Live data from Hacker News

Bash Prompts Collection

gilesorr.com

31–33 of 33 posts

Re: Bash Prompts Collection

#31
post #13

Earlier quoted context omitted.

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!

Understood. I learned this way too, stick with a near universal standard/expectation, especially if you want to script for it and customize and if you are accessing remote machines often so you can be comfortable and productive in any situation.

P.S. just fully noticed your handle, very shell discussion appropriate! :)

Re: Bash Prompts Collection

#32
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'…

This would have helped when I `rm -rf`ed my home directory, but I was on Ultrix, whose `rm` didn't have the `-I` flag. In fact, I don't think even GNU `rm` had `-I` yet. I was in /tmp/something where I'd unpacked some software package I'd downloaded and decided was of no use, and I wanted to read netnews, so I typed

    rm -rf * & cd; trn
Several hours later, around 3 AM, I was done reading netnews, so I exited trn. Then I remembered that there was one newsgroup I had forgotten to read, so I typed ↑↵ to run trn again, which had the effect of again running

    rm -rf * & cd; trn
but this time in my home directory. And of course my frantic ^C^C^C had no effect on the `rm`, which was safely in the background.

Fortunately the computer center kept nightly backups.

Re: Bash Prompts Collection

#33
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…

Right, I shouldn't assume that everyone knows what the `:` command does. I'm not especially worried about destructive file operations in this context because I don't think any of my directories has a `>` in its filename.
Post reply on HN