Am Fri, Dec 03, 2021 at 02:43:54PM +0000 schrieb Peter Humphrey:
Hello list,
Is there a way to set the colour of a bash prompt according to
whether the user has SSH'd in?
[…]
When you are connected via SSH, the environment variable
SSH_CONNECTION is set. I store the color in a variable and set it to yellow if `[[ -n "${SSH_CONNECTION}" ]]`. I can't give you the exact snippet since I use Zsh, but it should be possible to use a variable
as color in bash's prompt?
Kind regards, tastytea
This link expands upon tastytea's idea:
https://unix.stackexchange.com/questions/217270/change-ps1-color-when-> connected-to-other-host-via-ssh
Thank you both. Now I just have to shoehorn it into /etc/bash/bashrc on the SSH server...
I expanded on that idea somewhat further. When I am in midnight commander
and press Ctrl+O to open a fullscreen shell, I sometimes forget after a
while that it was an mc shell, and so blindly quit it with ctrl+D, which
also kills the mc process. So a long time ago I expanded my PS1 in ~/.bashrc for those shells to show the number of backgrounded processes and “subshell type” like so:
__jobsprompt() {
PS1_JOBS_COUNT=`jobs -p | wc -l`
if [ $PS1_JOBS_COUNT -eq 0 ]; then
PS1_JOBS_COUNT=
else
PS1_JOBS_COUNT="$PS1_JOBS_COUNT "
fi
[ "$MC_SID" ] && PS1_JOBS_COUNT="${PS1_JOBS_COUNT}MC "
[ "$RANGER_LEVEL" ] && PS1_JOBS_COUNT="${PS1_JOBS_COUNT}R "
}
if [[ -z "$PROMPT_COMMAND" ]]; then
PROMPT_COMMAND=__jobsprompt
else
PROMPT_COMMAND="$PROMPT_COMMAND ; __jobsprompt"
fi
PS1="$CBPURPLE\u$CDGRAY@$CBGREEN\h$CRESET $CBBLUE\w $CRED"'$PS1_JOBS_COUNT'$CRESET"
Those $C… strings of course being shell codes for colours (CB…=bold). Note the single quotes within the string. PS1 shall contain the actual string '$PS1_JOBS_COUNT', so that the variable is expanded anew in every prompt.
--
Grüße | Greetings | Qapla’
Please do not share anything from, with or about me on any social network.
I just took an IQ test. The results were negative.
-----BEGIN PGP SIGNATURE-----
iQIzBAABCgAdFiEEVbE9o2D2lE5fhoVsizG+tUDUMMoFAmGulr0ACgkQizG+tUDU MMqB/w//XfLHgF8gXFG0I9Qi2iyifv1hYqvABJhFZZXlIWU0mmbRCXIvo03SYeLq lEhMYmDDDDRPOQiUnxkQopG16DPXECuxjALOTLAz8DfjFsoFUa6KUR85UYvdVOyI BMcKj7Igzdc0bEZqLHRiu22OA3Yp3PjeE/dZtxtG+40c/hqyFL9ItT91ak6O7o7b XORu0PD3t5gHtQG8qHVrMaojfy1ETNXL5fltaHB+YHZFlr/vZ1QQTos6mFOk0d0q cMkUlBGjOSOPODhM2sfRAlSE5LwDLOosYUUC2u5v5aTTm7q1fsjLlIp67LiPmHpe XQjcBlrp4LM8oDLIlwxE7UZAsLuzq/9qwe358NYWbblef4zIDb+MbM2ngKI7l/n3 SOsYVKvXEdWOP/9O1qdC3KVwVII4o+RjSO/bYZcCctKDu1sKsjBcWe2kf69WF3JY e3kKQBXJTnHmF43TG22RdmZ8bu11wE7QQVFFPOHNN7Gw82Ua1dyOdit2FidkpZOt vuvZKjwrRTrNVgmbrwSDe+Nclic6tRiUYqO57ljw5YV7K7GhEBebrqs7+m0CjhlX i6Dx9xydR3V8M0iNEb0e1QBiQvIw9IiY2fF9Idrn/dbVrg/6nvR/JXP6LWwwLdZc a3zp21LfQdhi//BEc7deJaMCtmZ0Zy0hYBEEMAcdWfcS+bLmrmU=
=yRzA
-----END PGP SIGNATURE-----
---