Optimise Your Prompt

If you use a prompt which begins with a colon and ends with a semi-colon, you can cut and paste entire lines which requires much less eye-hand co-ordination.

Consider, if you will, setting a prompt like this:

$ export PS1=": $(hostname -s); "
: chekalahk; ls
file1
file2

As : is a builtin /bin/sh command which returns true ignoring its arguments, if you cut and paste the line:

: chekalahk; ls

Will evaluate into a NOOP and then the command that you typed in.

For root, you want to have a different prompt, generally one that contains a hash for some reason. The trick here is to make sure that you position the hash s.t.:

1. the hash is part of the preceding word, i.e. no spaces, and
2. the semi-colon comes after the hash.

Like this:

: chekalahk#; ls
file
file
file
Written on February 23, 2021