Skip to content

Instantly share code, notes, and snippets.

@anekos
Created June 29, 2010 11:29
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anekos/457095 to your computer and use it in GitHub Desktop.
Save anekos/457095 to your computer and use it in GitHub Desktop.
シェルで長い処理が終わったときに声で通知する
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