Skip to content

Instantly share code, notes, and snippets.

@syui
Created September 25, 2014 10:38
Show Gist options
  • Save syui/53b98cc6e2cf35954707 to your computer and use it in GitHub Desktop.
Save syui/53b98cc6e2cf35954707 to your computer and use it in GitHub Desktop.
#!/bin/zsh
dir=$HOME/.command_stream
fil=$dir/tmp.txt
com=$1
mkdir -p $dir
case $1 in
-h)
echo -e "
\$1...command
\$2...count
-n...clear
";;
-n)
rm $fil && echo 1 > $fil
;;
*)
case $# in
1) arg=5;;
2) arg=$2;;
0) com="df -h | grep disk | sed 's/ /,/g'";;
*) exit;;
esac
max=`zsh -c $com | wc -c | tr -d ' '`
if [ -e $fil ]; then
i=`cat $fil | tail -n 1`
if [ $i -le $max ]; then
a=$i"-"`expr $i + $arg` > /dev/null 2&>1
b=`zsh -c $com | cut -c $a` > /dev/null 2&>1
echo "$b"
echo `expr $i + 1` >> $fil
else
rm $fil
echo 1 > $fil
fi
else
echo 1 > $fil
fi
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment