Live data from Hacker News

Bash PS1 Generator

bashrcgenerator.com

111–120 of 146 posts

Re: Bash PS1 Generator

#111

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…

Terminal app feature idea: a hotkey that puts the last command run in the copy buffer

Re: Bash PS1 Generator

#112
I was moved to experiment with Fish shell one day, and wanted to see how to set my prompt. Answer: you create a function named `fish_prompt` that uses regular shell commands like `echo` (and fish's own `set_color`) to imperatively build the prompt. Want to make a right-hand prompt for something like the current time? Write a function named `fish_right_prompt`. For example, here's mine:

  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

#113

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…

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

#114

current 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)]\$ "

I recently added a count of stashes (in red) following the branch name, and I've been liking it.

Re: Bash PS1 Generator

#115
post #90

Why 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.

Re: Bash PS1 Generator

#116
post #98

Earlier 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'.

One time a month? Currently I have 85 work related repositories checked out, putting the current git branch and current Kubernetes context in the prompt is helping to avoid mistakes.

I also have a newline in my prompt which makes it easier to copy commands and output into Jira.

Re: Bash PS1 Generator

#118
You think your prompt is too fast? Just add some HN style to it:

  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

#119
post #90

Why 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.

Thank you :-)

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

#120
post #110

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…

Maybe >(Unicode 0xFF1/>) would be a good substitute? Side by side: >>

that seems like asking for trouble
Post reply on HN