github.com/hrntknr/ntf@v1.0.2-0.20220725163249-d52a7861d93d/ntf-shell-hook.sh (about) 1 AUTO_NTF_DONE_IGNORE=${AUTO_NTF_DONE_IGNORE:-ntf emacs htop info less mail man meld most mutt nano screen ssh tail tmux top vi vim watch} 2 3 function _ntf_precmd() { 4 local code="$?" 5 [[ -n "$ntf_start_time" ]] || return 6 local duration=$(($(date +%s) - $ntf_start_time)) 7 ntf_start_time='' 8 [[ "$duration" -le "$AUTO_NTF_DONE_LONGER_THAN" ]] && return 9 10 local appname=$(basename "${ntf_command%% *}") 11 [[ " $AUTO_NTF_DONE_IGNORE " == *" $appname "* ]] && return 12 13 (ntf shell-done "$code" "$duration" "$ntf_command" &) 14 } 15 16 function _ntf_preexec() { 17 ntf_start_time=$(date +%s) 18 ntf_command="$1" 19 } 20 21 function _contains_element() { 22 local e 23 for e in "${@:2}"; do [[ "$e" == "$1" ]] && return 0; done 24 return 1 25 } 26 27 if ! _contains_element _ntf_preexec "${preexec_functions[@]}"; then 28 preexec_functions+=(_ntf_preexec) 29 fi 30 31 if ! _contains_element _ntf_precmd "${precmd_functions[@]}"; then 32 precmd_functions+=(_ntf_precmd) 33 fi