-
Notifications
You must be signed in to change notification settings - Fork 132
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 option to customize theme #2
Comments
@oranja @edouard-lopez what's the best way to achieve this? |
For bare fish (not using any framework), I believe the most standard way is to rearrange the variable assignments to serve as defaults in case the variable is not yet set. # Symbols
set -q symbol_prompt; or set -g symbol_prompt "❯"
set -q symbol_git_down_arrow; or set -g symbol_git_down_arrow "⇣"
set -q symbol_git_up_arrow; or set -g symbol_git_up_arrow "⇡"
set -q symbol_git_dirty; or set -g symbol_git_dirty "*"
set -q symbol_horizontal_bar; or set -g symbol_horizontal_bar "—" This way, any of these variables can be defined in config.fish without being overwritten by pure's fish_prompt.fish. If it gets too tedious, you can define a helper function: function set_default -S -a var value
set -q $var; or set -g $var $value
end Then the previous block becomes: # Symbols
set_default symbol_prompt "❯"
set_default symbol_git_down_arrow "⇣"
set_default symbol_git_up_arrow "⇡"
set_default symbol_git_dirty "*"
set_default symbol_horizontal_bar "—" In the price of indirection you get a more compact block, and it also helps to avoid bugs from typos... |
@oranja that looks pretty decent and straightforward. Will give it a try! Thanks man. |
My two cents. Mostly agree with @oranja, but please always prefix any global variables with the name of your plugin/theme/prompt/snippet/etc so as to not conflict with other global variables of the same name. I personally recommend against using My alternative is this: set -l symbol_prompt ❯
if set -q pure_symbol_prompt
set symbol_prompt $pure_symbol_prompt
end Some may look at that and think "why do I need to create an extra variable and do in 4 LOC what I can do in 1?". The answer, again, has to do with readability and maintainability. Refactoring the code I have proposed is very easy and it's harder to botch causing a bug. It's like a fortress you are building to protect yourself from your future self. |
Great, I will keep that in mind. Thanks. Rafael Rinaldi
|
What @bucaran is suggesting is to have two variables for each customization options. set -l symbol_prompt ❯ # This is the local variable that will be used in the prompt's code.
if set -q pure_symbol_prompt # Here we check for any previous definition of `pure_symbol_prompt`. Not necessarily global.
set symbol_prompt $pure_symbol_prompt # We override the local variable with the external value, if it's present.
end |
In the same file fish also has several of these On Tue, Feb 16, 2016, 00:22 Jorge Bucaran notifications@github.com wrote:
|
I think this issue should be closed by #30. |
@Shougo That's true. Thanks! |
# This is the 1st commit message: rename `$pure_symbol_git_arrow_down` as `$pure_color_git_unpulled_commits` # This is the commit message #2: fix pure_color_git_unpulled_commits to pure_symbol_git_unpulled_commits
# This is the 1st commit message: rename `$pure_symbol_git_arrow_down` as `$pure_color_git_unpulled_commits` # This is the commit message #2: fix pure_color_git_unpulled_commits to pure_symbol_git_unpulled_commits
# This is the 1st commit message: rename `$pure_symbol_git_arrow_down` as `$pure_color_git_unpulled_commits` # This is the commit message #2: fix pure_color_git_unpulled_commits to pure_symbol_git_unpulled_commits
# This is the 1st commit message: rename `$pure_symbol_git_arrow_down` as `$pure_color_git_unpulled_commits` # This is the commit message #2: fix pure_color_git_unpulled_commits to pure_symbol_git_unpulled_commits
Since we already use variables everywhere, it should be as simple as changing them from local to the global scope.
The text was updated successfully, but these errors were encountered: