Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโ€™ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add config file support #251

Merged
merged 3 commits into from Jan 6, 2021
Merged

Add config file support #251

merged 3 commits into from Jan 6, 2021

Conversation

cjvaughter
Copy link
Contributor

What this does

This enables settings to be loaded from ~/.config/powerline-go/config.json in addition to the usual arguments.

How it works

This refactors everything configuration related into a Config struct. This struct is initialized with default values, loaded from config.json, then any args provided override their config counterparts. This should provide a seamless transition, as existing usage is preserved.

Each setting uses the equivalent arg name, with the exception of error and duration (which can only be set via args, as setting them in config would make no sense).

There are a few special settings:

  • modes, themes, and shells do not completely override the defaults, only add values to their respective maps.
  • modes and themes work exactly like loading them from an external file (i.e. they are preloaded with defaults so you don't have to specify the whole thing).
  • path-aliases specified via args are added to ones specified via config.

Example

Here is my config.json: (ignore the unicode shenanigans)

{
    "modules": [ "user", "cwd" ,"perms", "git", "jobs", "root" ],
    "path-aliases":
    {
       "~": "๐Ÿ ",
       "~/github/powerline-go": "๐Ÿ”Œ"
    },
    "theme": "wsl",
    "themes":
    {
        "wsl":
        {
            "RepoCleanFg": 15,
            "RepoCleanBg": 22,
            "RepoDirtyFg": 15,
            "RepoDirtyBg": 130
        }
    },
    "mode": "wsl",
    "modes":
    {
        "wsl":
        {
            "Lock":             "๐Ÿ”’",
            "Network":          "๐Ÿš€",
            "RepoDetached":     "โš“",
            "RepoAhead":        "๐Ÿ”บ",
            "RepoBehind":       "๐Ÿ”ป",
            "RepoStaged":       "โœ”\uFE0F",
            "RepoNotStaged":    "โœ\uFE0F",
            "RepoUntracked":    "โž•",
            "RepoConflicted":   "โ„\uFE0F",
            "RepoStashed":      "๐ŸŽ"
        }
    }
}

Prompt: PS1="$(powerline-go -error $?)"

Other thoughts

  • The performance impact is pretty negligible. On my machine I measured ~500-600ns to load the config. When no config file exists, there is practically no difference.
  • We could potentially allow specifying the config location.
  • I was torn on whether or not to merge arg specified ignore-repos with config ones (like path-aliases). This can easily be done if you'd like.
  • I don't like having two data structures that need to be manually kept in sync, but I wasn't sure how else to do it. Mostly due to the way the flag system works.

Let me know if you have any questions.

@justjanne
Copy link
Owner

Please rebase so I can merge :)

@cjvaughter
Copy link
Contributor Author

Okay, now this should be ready after merging #247.

@cjvaughter
Copy link
Contributor Author

Well, I was wrong. ๐Ÿ˜…
Now it's ready.

@cjvaughter
Copy link
Contributor Author

Now it's really ready (you've been quite active today!)

@justjanne
Copy link
Owner

You were just a tiny bit faster than me just now, I just got a complaint from GitHub "this page is out of date, please reload" while resolving the conflicts :)

@justjanne justjanne merged commit 83357d7 into justjanne:master Jan 6, 2021
@justjanne
Copy link
Owner

Now it's really ready (you've been quite active today!)

Yeah after I saw just how much this project has grown recently (and it's now even in official Windows documentation on microsoft.com ๐Ÿ˜ฎ), I decided I really need to clean this up and fix many of the outstanding issues :)

@cjvaughter
Copy link
Contributor Author

I knew I'd be ahead eventually, lol.

Well I'm glad, this is a great project!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants