Created
June 29, 2010 11:29
-
-
Save anekos/457095 to your computer and use it in GitHub Desktop.
シェルで長い処理が終わったときに声で通知する
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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