3 ms·
This is a color thing I've done with a bash script / bash prompt. If there is a better way to do this that would be the coolest. ### long prompt (in color) o
by mmphosis 4y ago
This is a color thing I've done with a bash script / bash prompt. If there is a better way to do this that would be the coolest.
### long prompt (in color) only when 'user or hostname or path' changes, or after certain commands
prompt_command ()
{
local -a a;
local last_cmd;
IFS=' ' read -r -d '' -a a < <( history 1 );
last_cmd="$(printf "%s" "${a[1]}"|xargs -0)";
if [ "$USER_HOSTNAME_PWD" != "$USER@$HOSTNAME:$PWD" ] || [[ " cd src doc ssh sudo su login $(sed -e '/^#.*$/d' -e '/^$/d' -e 's@^.*/@@' /etc/shells|uniq|xargs) " == *" ${last_cmd} "* ]]; then
USER_HOSTNAME_PWD="$USER@$HOSTNAME:$PWD";
echo -e "\\e7\\e(B\\e[m- \\e[3$((($(id -u) != 0) + 1))m${USER}\\e(B\\e[m@\\e[35m${HOSTNAME%%.*}\\e(B\\e[m:\\e[36m${PWD/#$HOME/\~}\\e8";
fi
}
-() { unset USER_HOSTNAME_PWD
}
PROMPT_COMMAND=prompt_command
PS1='$ ';[ "$(id -u)" -eq 0 ] && PS1='# '