Comments (10)
@oranja @edouard-lopez what's the best way to achieve this?
from pure.
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.
For example:
# 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...
from pure.
@oranja that looks pretty decent and straightforward. Will give it a try! Thanks man.
from pure.
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 and
or or
. Long one-liners are difficult to maintain and modify in the future. But that's just my opinion.
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.
from pure.
Great, I will keep that in mind. Thanks.
Rafael Rinaldi
http://rinaldi.io
On Feb 13, 2016, at 15:27, Jorge Bucaran [email protected] wrote:
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 (hardly, but still) with other global variables of the same name.
—
Reply to this email directly or view it on GitHub.
from pure.
Thanks for your knowledge!
@oranja good proposal
@bucaran nice improvement! Love future-proof argument!
don't we need -g
to set globally?
from pure.
What @bucaran is suggesting is to have two variables for each customization options.
The first is local and is the one actually used in the theme code.
The second can have any scope that affects the prompt - universal, global, or local to an outer function (i.e. a test function).
To clarify, here's @bucaran's suggestion again, with annotations. (hoping I won't get sued for copyright infringement here).
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
from pure.
In the same file fish also has several of these set -q var; or set var
one liners, rendering your choice argument weaker.
Having said that, both are fine, but personally, I think that if you have
many of these in a row, it's better to use the shorter form. It's an
equally acceptable fish idiom.
On Tue, Feb 16, 2016, 00:22 Jorge Bucaran [email protected] wrote:
One more thing that I don't know whether it supports my argument or not,
is that fish does this too, so it's a way to stay consistent across the
universe.don't we need -g to set globally?
Depends. I was assuming this variable will only be used in the file where
it was declared.—
Reply to this email directly or view it on GitHub
#2 (comment).
from pure.
I think this issue should be closed by #30.
from pure.
@Shougo That's true. Thanks!
from pure.
Related Issues (20)
- Displaying conda/virtualenv env name has incorrect spacing HOT 2
- type: Unknown option '--quiet' HOT 1
- prompt character broken HOT 3
- Change git branch color HOT 3
- Add 🐍 to the virtualenv title so I know that's what I see HOT 9
- [request] Is there anyway to have the following prompt: $tail on $git_branch HOT 1
- Missing blank line between prompts? HOT 2
- Add CI for MacOS
- MacOS: warning: An error occurred while redirecting file '/proc/1/cgroup' HOT 26
- Prompt outputting _pure_is_inside_container 1 HOT 4
- head: cannot open '/proc/1/sched' for reading: No such file or directory HOT 6
- Prompt displays '2' character around user@host section HOT 1
- VI-mode visual mode prompt HOT 2
- Cannot uninstall 4.4.1 HOT 2
- WSL 1 shows user@hostname HOT 3
- Add kubernetes/k8s support HOT 1
- Is there any option in pure like truncation_length in starship? I want it to show last three parent folder. HOT 2
- 📖 Revamp README and docs
- Pure prompt contains newline in VSCode terminal HOT 3
- Improve `git` prompt during rebase conflicts HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pure.