Live data from Hacker News

Bash Prompts Collection

gilesorr.com

21–30 of 33 posts

Re: Bash Prompts Collection

#21
post #15

I strongly recommend against putting a ">" in your prompt on Unix if you're using any kind of system that supports copy and paste. (So, like, on a physical VT100 on a serial port it would be okay.) Sooner or later you're going to take a prompt-included command like > ls GN* and accidentally paste it into a terminal window (or a web page that someone else pastes into a terminal window) and accidentally create an empty…

You can avoid this by using Unicode character U+276F "Heavy Right-Pointing Angle Quotation Mark Ornament", which also looks better IMHO.

Re: Bash Prompts Collection

#22

Adopted: https://atuin.sh/ https://github.com/akinomyoga/ble.sh https://starship.rs/ These three have made my shell game so much more enjoyable.

Can’t agree more.

atuin in particular records the history of each command but also how long they took and is they were successful or not.

You never have to rerun a command with long output to know how long it took: just ctrl-r and see.

Re: Bash Prompts Collection

#23
post #13

My buddy spike723 on EFnet built what I can only describe as a sentinent bash prompt. I recall it being massive and could show you everything about your system in a prompt. 25 years later I have no clue where this guy went but I remember him because he was instrumental in moving me off zsh to bash

Right on, I've always enjoyed tinkering with my own `$PS1`. Why did you move from zsh to bash -- what bash features pulled you over?

This was 20 years ago, but what I found was that bash is on every system. Too many shells would only have bash (or ksh) where my zsh profiles were useless. Fast forward to today and I’m hard pressed to find any containers with anything but Bourne. So bash it is!

Re: Bash Prompts Collection

#24
Another idea: an indication of how many background jobs are currently running. With many terminal tabs open, I can forget if I already have $EDITOR (or something else) running, so the number of jobs can be a nice cue.

    _jobscount() {
        local jobs=($(jobs -p))
        local count=${#jobs[@]}
        (($count)) && echo -n " (${count}j)"
    }
And then put that in your prompt.

Re: Bash Prompts Collection

#26
post #15

I strongly recommend against putting a ">" in your prompt on Unix if you're using any kind of system that supports copy and paste. (So, like, on a physical VT100 on a serial port it would be okay.) Sooner or later you're going to take a prompt-included command like > ls GN* and accidentally paste it into a terminal window (or a web page that someone else pastes into a terminal window) and accidentally create an empty…

> I strongly recommend against putting a ">" in your prompt on Unix ...

Another reason against using ">" in the definition of PS1 is that this is a typical character used in the definition of PS2[0].

> The :; has the advantage that, if you unintentionally include the prompt in your copy and paste, it usually has no effect.

This is because colon (':') has a specific definition in POSIX shells[1], which is:

  Do nothing beyond expanding arguments and performing 
  redirections. The return status is zero.
Note that "performing redirections" can result in destructive file operations.

0 - https://unix.stackexchange.com/questions/193659/in-which-sit...

1 - https://www.gnu.org/software/bash/manual/html_node/Bourne-Sh...

Re: Bash Prompts Collection

#27
post #18

Earlier quoted context omitted.

I use Linux for 30 years. Never had this problem. However, I saw newbies, which copy paste commands from tutorials to shell and then frustrated, because # is a comment.

I bet you've never accidentally rm -rf'ed your home directory or your email archives either.

> I bet you've never accidentally rm -rf'ed your home directory or your email archives either.

If this is a concern to mitigate, consider adding the following alias to your preferred shell profile:

  alias rm='/bin/rm -I'
This will not conflict with scripts using PATH-relative 'rm' invocations, yet will provide the desired protection from erroneous interactive use of "rm -rf".

See here[0] for details regarding the '-I' flag.

0 - https://linux.die.net/man/1/rm

Re: Bash Prompts Collection

#28
post #18

Earlier quoted context omitted.

I use Linux for 30 years. Never had this problem. However, I saw newbies, which copy paste commands from tutorials to shell and then frustrated, because # is a comment.

I bet you've never accidentally rm -rf'ed your home directory or your email archives either.

I do

rm /dir

Then go back and add the -rf.

Works on GNU and BSD. On GNU only you can

‘rm /dir -rf’

Re: Bash Prompts Collection

#30
post #18

Earlier quoted context omitted.

I bet you've never accidentally rm -rf'ed your home directory or your email archives either.

> I bet you've never accidentally rm -rf'ed your home directory or your email archives either. If this is a concern to mitigate, consider adding the following alias to your preferred shell profile: alias rm='/bin/rm -I' This will not conflict with scripts using PATH-relative 'rm' invocations, yet will provide the desired protection from erroneous interactive use of "rm -rf". See here[0] for details regarding the '-I'…

I alias rm='rm -i', and then check that I'm deleting the right thing. And then redo the command with `yes | rm -r whatever`. This ends up giving me an "audit log" of what was deleted.
Post reply on HN