Skip to content

Instantly share code, notes, and snippets.

@znz
Created June 27, 2012 15:03
Show Gist options
  • Save znz/3004651 to your computer and use it in GitHub Desktop.
Save znz/3004651 to your computer and use it in GitHub Desktop.
AAを走らせるシェルスクリプト
run-smily.sh
#!/bin/bash
# LICENSE: MIT License. Copyright (C) 2012 Kazuhiro NISHIYAMA
if [ -z "$COLUMNS" ]; then
get_window_size () {
COLUMNS=$(tput cols)
: ${COLUMNS:=80}
}
trap 'get_window_size' WINCH
get_window_size
fi
get_column () {
# http://qa.atmarkit.co.jp/q/2277
stty -echo
printf $'\e[6n'
read -dR column
stty echo
column="${column#*;}"
}
run_smily_bytesize () {
local aa=("$@")
local offset=0
local index
while [[ $COLUMNS -ge $[$offset + ${#aa[index]}] ]]; do
printf "%*s%s\r" $offset " " "${aa[index]}"
offset=$[offset+1]
index=$[offset % ${#aa[@]}]
sleep ${RUN_SMILY_DELAY}
done
printf "%*s%s\r" $COLUMNS " "
}
run_smily_vt100 () {
local aa=("$@")
local offset=0
local index
offset=0
while [[ $COLUMNS -ge $column ]]; do
printf "%*s%s" $offset " " "${aa[index]}"
get_column
printf "\r"
offset=$[offset+1]
index=$[offset % ${#aa[@]}]
sleep ${RUN_SMILY_DELAY}
done
printf "%*s%s\r" $COLUMNS " "
}
run_smily () {
local aa
if [ -n "$1" ]; then
aa=("$@")
else
case $[$RANDOM % 3] in
0) aa=("(: )" "('')" "( :)" "(..)") ;;
1) aa=("(^_^)" "( ^_)" "( ^)" "( )" "(^ )" "(_^ )") ;;
2) aa=("C=(;^^)" " (;^^)") ;;
esac
fi
: ${RUN_SMILY_DELAY:=0.1}
case "$RUN_SMILY_METHOD" in
bytesize)
run_smily_bytesize "${aa[@]}"
;;
vt100 | *)
run_smily_vt100 "${aa[@]}"
;;
esac
}
case "$0" in
*run-smily*)
run_smily "$@"
;;
*bl)
# https://twitter.com/WizardOfPSG/status/217230089971175424
run_smily "ホモォ…┌(┌ ^o^)┐"
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment