Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
シェルで長い処理が終わったときに声で通知する
function _anekos_longtimeago_preexec {
# マッチするコマンドの時は無視する
[[ $2 == (sc|screen|ssh|vim|git ci)\ * ]] && return
_anekos_longtimeago_time=`date +%s`
}
function _anekos_longtimeago_precmd {
[ ${+_anekos_longtimeago_time} = 1 ] || return
local time=$((`date +%s` - $_anekos_longtimeago_time))
unset _anekos_longtimeago_time
# 5 秒以上かかったら、"にゃああああん" と鳴くよ
if [ $time -gt 5 ]
then
say にゃああああん
# おまけで処理にかかった時間も表示
local unit=sec
if [ $time -gt 120 ]
then
time=$(( $time / 60 ))
unit=min
fi
echo processing time: $time $unit
fi
}
preexec_functions=($preexec_functions _anekos_longtimeago_preexec)
precmd_functions=($precmd_functions _anekos_longtimeago_precmd)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment