0 0:00:00 ~/Code/company/app$
- I actually don't care about the exit code unless it was non-zero
- It calculates the delta three times
but I've been to busy to optimise it.
prompt_command() { _PS1_now=$(printf '%(%s)T') PS1=$( printf "\n\$? \[\e%02d:%02d:%02d \n\[\033[01;34m\]\w\[\033[00m\]\$ " \ $(( ( _PS1_now - _PS1_lastcmd ) / 3600)) \ $(( (( _PS1_now - _PS1_lastcmd ) % 3600) / 60 )) \ $(( ( _PS1_now - _PS1_lastcmd ) % 60)) \ ) _PS1_lastcmd=$_PS1_now } PROMPT_COMMAND='prompt_command' _PS1_lastcmd=$(printf '%(%s)T')
$
- username@hostname:pwd $
### PROMPT ### ### 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='# '
- I actually don't care about the exit code unless it was non-zero
- It calculates the delta three times
but I've been to busy to optimise it.