diff --git a/.bashrc b/.bashrc index 51ba326a96825fdfde3190cb4d5eacf278479c46..ff2cebc36cfddb11ed497c68d96e0755636f9f5e 100644 --- a/.bashrc +++ b/.bashrc @@ -46,10 +46,6 @@ export LESS_TERMCAP_se=$'\E[0m' # Underline (dark grey). export LESS_TERMCAP_us=$'\E[01;32m' export LESS_TERMCAP_ue=$'\E[0m' -export PS0="\$(__prerun)" -# shellcheck disable=SC1117 -export PS1="\[\$(__prompt)\]\u@\h:\w\$ " -export CDPATH="$HOME:$HOME/Documents:$HOME/Documents/Shore:$HOME/Documents/Endless" alias make='monitor make ' alias packer='monitor packer ' @@ -265,11 +261,56 @@ __prompt () { echo "$prompt" } +__prompt_command () { + trap __command_notifier debug +} + +__command_notifier () { + local exitstatus="$?" + local now runduration + now="$(date +%s)" + if [ -n "${last_finish:-}" ] && [ "$last_command" != "__prompt_command" ] + then + runduration="$(( now - last_finish ))" + if [ "$runduration" -gt "10" ] + then + if [ "$exitstatus" -eq "0" ] + then + notify-send "$last_command has finished." + else + notify-send "$last_command has failed." + fi + fi + fi + last_command="$BASH_COMMAND" + last_finish="$(date +%s)" + trap - debug +} + # shellcheck disable=SC1090 . "$HOME/Documents/Shore/bundle_certs/bundle_certs" + +# make less more friendly for non-text input files, see lesspipe(1) +[ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)" + +# enable color support of ls and also add handy aliases +if [ -x /usr/bin/dircolors ]; then + eval "$(dircolors -b)" + alias ls='ls --color=auto' + alias grep='grep --color=auto' + alias diff='diff --color=auto' + alias ip='ip -color' + alias less='less --raw-control-chars' +fi + if [ -n "${BASH:-}" ] then + export CDPATH="$HOME:$HOME/Documents:$HOME/Documents/Shore:$HOME/Documents/Endless" + # shellcheck disable=SC2016 + export PS0='$(__prerun)' + export PS1='\[$(__prompt)\]\u@\h:\w\$ ' + export PROMPT_COMMAND='__prompt_command' shopt -s checkwinsize shopt -s cmdhist # shellcheck disable=SC1091 @@ -281,22 +322,8 @@ then [ ! -f "$sourcefile" ] || . "$sourcefile" done ! command -v direnv > /dev/null || eval "$(direnv hook bash)" + prune_prerun trap prune_prerun EXIT fi - -# make less more friendly for non-text input files, see lesspipe(1) -[ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)" - -# enable color support of ls and also add handy aliases -if [ -x /usr/bin/dircolors ]; then - eval "$(dircolors -b)" - alias ls='ls --color=auto' - alias grep='grep --color=auto' - alias diff='diff --color=auto' - alias ip='ip -color' - alias less='less --raw-control-chars' -fi - prune_docker_remote -prune_prerun