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…
Bash PS1 Generator
111–120 of 146 posts
Re: Bash PS1 Generator
#112 function fish_right_prompt --description 'Write out the right prompt'
set_color 666666
date +'%Y-%m-%d %H:%M:%S'
set_color normal
end
I was sold. I'm never, ever going back to futzing around with a bunch of complex $PSx variables when I can just write a function that does the right thing.Re: Bash PS1 Generator
#113Seeing '>' 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…
Terminal app feature idea: a hotkey that puts the last command run in the copy buffer
function copy_last_command {
history 1 | sed 's/ [0-9]* //' | xclip -i
}
bind -x '"\C-h":copy_last_command'Re: Bash PS1 Generator
#114current git branch is missing (helps me to avoid working on the wrong branch). (tried to do it with colors, but things got too messy). I never managed to work with colors in bash propmts; they look different on each environment. parse_git_branch() { git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/' } PS1="[\u@\h \W\$(parse_git_branch)]\$ "
Re: Bash PS1 Generator
#115Why would you export PS1? Seems like unnecessarily cluttering the environment of child processes.
Isn't it correct? I mean, sure, we are talking shell here, so who cares about efficiency, but I don't see the benefit of using export either.
Re: Bash PS1 Generator
#116Earlier quoted context omitted.
I mean, the other alternative is just keep your prompt simple. ;-)
This. The one time a month when I can't remember which git branch I'm on I'll just run 'git branch'. If you're feeling frisky, you could even alias that to 'gb'.
I also have a newline in my prompt which makes it easier to copy commands and output into Jira.
Re: Bash PS1 Generator
#117Re: Bash PS1 Generator
#118 PS1="\$(curl -fsL https://news.ycombinator.com/user?id=USERNAME | awk 'x==1 {print \$1; x=0}; /karma/{x=1};') $PS1"
Replace USERNAME with your HN nick and always have your karma at your fingertips ;-)PS: This is a really bad idea...
Re: Bash PS1 Generator
#119Why would you export PS1? Seems like unnecessarily cluttering the environment of child processes.
What is wrong with the above comment (it got downvotes)? Isn't it correct? I mean, sure, we are talking shell here, so who cares about efficiency, but I don't see the benefit of using export either.
To elaborate, when I say "cluttering," it's not really performance I'm after. Of course I realize that yet another small key value pair in a hashmap matters very little. Rather, I'm thinking in terms of debugging and - worst case - weird side effects.
When I debug something I'm not helped by the environment being filled with unnecessary crap, in much the same way I don't particularly declare a bunch of irrelevant global variables in my programs.
In the worst case, a leaking environment may cause problems. What if another interactive shell process is spawned by a sub shell, and suddenly your prompt that queries your mail server, double checks if there's new stuff in GitHub, fetches the next ten days' weather and renders hamsterdance in your prompt using a hacked font or whatever is inherited (except that now maybe it runs as root). Unlikely? Yeah, sure. Still unnecessary.
In the end though, I suspect many people just aren't aware of the difference between exporting a variable and not, and somehow think that "to declare a variable in a shell you must type export".
Re: Bash PS1 Generator
#120Seeing '>' 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…
Maybe >(Unicode 0xFF1/>) would be a good substitute? Side by side: >>