-
-
Save hacolab/a48d9a795f800abc039ab22780404e15 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
#!/bin/sh | |
CMD_NAME=`basename $0` | |
usage_exit() { | |
cat <<- HELPEND | |
$CMD_NAME wait_time[hms] [-c command | message] | |
wait_time wait time[unit] | |
[unit] | |
h: hours = wait_seconds * 3600 [sec] | |
m: minutes = wait_seconds * 60 [sec] | |
s: seconds = wait_seconds [sec] (default) | |
-c command execute command after wait_time | |
default) tmux new window & popup message | |
message any message | |
HELPEND | |
exit 1 | |
} | |
# set wait seconds | |
if [ ${#1} -ge 2 ]; then | |
target_time=`echo "$1" | cut -c 1-\`expr ${#1} - 1\`` | |
fi | |
case "$1" in | |
*h ) wait_sec=`expr $target_time \* 3600` | |
;; | |
*m ) wait_sec=`expr $target_time \* 60` | |
;; | |
*s ) wait_sec="$target_time" | |
;; | |
* ) wait_sec="$1" | |
;; | |
esac | |
# wait_sec is digit? | |
if [ -z "`echo "$wait_sec" | grep '^[0-9]\{1,\}$'`" ]; then | |
echo "Invalid wait time!: `$1`" | |
usage_exit | |
fi | |
# set execute command | |
case $2 in | |
-c ) exec_command=$3 | |
;; | |
"" ) exec_command="popup_window" | |
;; | |
* ) exec_command="popup_window '$2'" | |
;; | |
esac | |
popup_window() { | |
[ -n "$*" ] && msg="$*" || msg="take a break!" | |
[ -n "`which bunnysay`" ] && print_cmd=bunnysay || print_cmd=echo | |
# make popup window | |
tmux new-window 2> /dev/null && ( | |
WIN_ID=`tmux display -p '#I'` | |
# print message | |
tmux pipe-pane -I -t:$WIN_ID 'echo " "' | |
tmux pipe-pane -I -t:$WIN_ID "echo '$print_cmd \"$msg\"'" | |
# tmux clock-mode -t:$WIN_ID 2> /dev/null | |
# auto close | |
sleep 3 | |
tmux kill-window -t:$WIN_ID | |
) 2> /dev/null \ | |
|| ( echo " "; $print_cmd "$msg" ) 1>&2 | |
} | |
# wait & excuete command | |
sleep $wait_sec && $exec_command & | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment