kragen
4 days ago
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 file named "ls". Or, in some cases, overwrite an existing file.My own current setting is
PS1=': ${env:+($env) }\W; '
Which looks like this: : ~; cd wak
: wak; ls
LICENSE monosrc scripts toybox toybox_awk_test
Makefile README.md src toybox_awk_parts
: wak;
The :; has the advantage that, if you unintentionally include the prompt in your copy and paste, it usually has no effect. (Maybe I should change ($env) to [$env].) \W (the last segment of the directory name) is usually about the right amount of context for me, but if I were working on a project with a lot of directories named things like "views" I would probably reconsider that.BTW, since this prompt collection was written, Linux terminal emulators have mostly gained 24-bit color support, which potentially opens up more alternative colors. See http://canonical.org/~kragen/sw/dev3/gradient.c with sample results in http://canonical.org/~kragen/sw/dev3/gradient.png. The escape sequence is \033[38;2;rrr;ggg;bbbm, where \033 is ESC and rrr, ggg, and bbb are decimal numbers from 0 to 255.
(Probably I should switch from bash to zsh...)
oneshtein
4 days ago
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.
kragen
4 days ago
I bet you've never accidentally rm -rf'ed your home directory or your email archives either.
AdieuToLogic
4 days ago
> 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.
kragen
2 days ago
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.
porridgeraisin
3 days ago
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.
nailer
4 days ago
I do
rm /dir
Then go back and add the -rf.
Works on GNU and BSD. On GNU only you can
‘rm /dir -rf’
AdieuToLogic
4 days ago
> 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...
kragen
2 days ago
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.
chickensong
4 days ago
You can avoid this by using Unicode character U+276F "Heavy Right-Pointing Angle Quotation Mark Ornament", which also looks better IMHO.