Greg 'groggy' Lehey wrote in
<20211225231941.GB83649(a)eureka.lemis.com>:
|On Friday, 24 December 2021 at 23:40:56 -0500, Theodore Ts'o wrote:
|> Here are examples of some of my prompts. It does use two lines, but
|> the extra context is worth it to me:
|>
|> <tytso@cwcc> {/home/tytso}
|> 267% cd /usr/projects/e2fsprogs/base
|
|That's actually surprisingly like mine, though I squeeze it into one
|line. Like you, I find user, system and cwd important, but also the
|tty. In addition I put a marker to help find prompts in long output,
|so a typical prompt might be:
|
| === grog@bilbo (/dev/pts/27) ~/src 6 ->
|
|That's generated with
|
| PS1="\[ESC[34m\]=== \u@\h (`tty`) \[ESC[31m\]\w\[ESC[34m\] \# ->\[ESC[30\
| m\]\[ESC[47m\] "
|
|> 272% su
|> Password:
|> <tytso.root@cwcc> {/home/tytso}, level 2
|
|That's interesting. How do you do that?
Looks like bash(1)'s $SHLVL to me.
I always stumble over the
OpenCSW.org ssh(1) logins, they set
ignoreeof by default. That is how strange things go, in the shell
i hate that, in my mailer i have that and furthermore even
commandalias q 'echo You do not want to quit, do you?'
and that happens several times a week.
I mean i have
[ "${UID}" -eq 0 ] && PS1='#' || PS1='$'
if ( [ "${HISTSIZE##84}" = 42 ] ) > /dev/null 2>&1; then
# bash(1)/*ksh(1)?
if [ -n "${___SHTYPE}" ] || [ -n "${PWD}" ]; then
PS1="${ps1s}#?\$?${j}|${HOSTNAME%%.*}:\${PWD##*/}${PS1}${ps1e} "
else
PS1="${ps1s}#${j}${HOSTNAME%%.*}:${ps1W}${PS1}${ps1e} "
fi
else
PS1="${ps1s}#${j}${HOSTNAME}${PS1}${ps1e} "
fi
PS2='> '
export PS1 PS2
Where all the ps1* series was detected earlier, for colour, like
ps1s="\[\e[31m\]" ps1S="\[\e[38;5;203m\]"
ps1e="\[\e[0m\]"
for bash or
eval "ps1s=\$'\e[31m' ps1S=\$'\e[38;5;203m'
ps1e=\$'\e[0m'"
for mksh (to get around bugs it had sometime, and were fixed, some
get fixed by Thorsten), as well as
ps1s="^[[31m" ps1S="^[[38;5;203m" ps1e="^[[0m" # XXX \e
<> OpenBSD?$
and here ^[ is indeed the fully expanded \e for those ksh's which
cannot. The $j is for shells not running in tmux, where i have
a status line with lots of infos, to get load average
[ -f /proc/loadavg ] && j="(\$(cut -f1,4 -d' '
/proc/loadavg))"
I forgot busybox sh(1) in the listing. ps1W is \W for FreeBSD and
DragonFly ash(1) things. Hm.
Maybe i have to un-bitrot that by retesting against all shells
again, it has been years, and lots of programming happens.
I usually do "scp .* HOST:" whenever i get a HOST account, and
forget about it thereafter.
A nice rest-Christmas for all Christians, shall there be some left
which Jesus would not throw out of the temple, actually, that is.
:)
--steffen
|
|Der Kragenbaer, The moon bear,
|der holt sich munter he cheerfully and one by one
|einen nach dem anderen runter wa.ks himself off
|(By Robert Gernhardt)