-
Notifications
You must be signed in to change notification settings - Fork 85
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
Make it faster using builtins #9
Comments
Nice! I've been using git symbolic-ref in my own PS1 which is a lot dumber than git-radar so this should come in handy for me. Thanks @jart! Edit: bonus points for the ï in naïve :-) |
Anyway, this bit needs to be revised, because jartps1_gitbranch="${head##*/}" Example: $ head=release/1.0
$ echo "${head##*/}"
1.0 |
@zx8 Wow thanks for finding that bug. I updated the code in my original comment. PTAL? I'm not 100% sure what the best approach is, since I don't know everything that could be contained in that file. So I tried to pick the safest heuristic possible. |
Hmm, think you've overcomplicated it a bit, how about something simple like this: $ h=refs/heads/release/1/2/3
$ echo ${h##refs/heads/}
release/1/2/3 |
@zx8 The ## syntax wouldn't work since the |
Nice
PS1
hack. This is definitely the fanciest one I've seen for git. So I want to help you improve it.My question is this: do blank lines appear in the terminal if you hold down the enter key? That means the time to optimize is now. The name of the game is to drive down latency so that never happens.
Here's some code I wrote for mine own
.bashrc
file that you can use. It uses bash builtins to determine the git root and the current branch. This way you only need like 5 or so system calls, rather than the 182 you'd need to run the git command:strace -f git symbolic-ref --short HEAD |& wc -l
I've found that this is really helpful not only from the user experience standpoint (fast is better than slow) but also in situations where IO gets pwnd or you run out of processes. git might not run at all and you need builtins to save the system.
The only tradeoff with these functions is that it leaves garbage files behind in
/tmp
. It's assumed that a cron job exists to purge those occasionally./etc/cron.daily/tmpreaper
comes standard on Debian systems.The text was updated successfully, but these errors were encountered: