Skip to content

Instantly share code, notes, and snippets.

@minhajuddin
Created September 19, 2011 12:07
Show Gist options
  • Select an option

  • Save minhajuddin/1226371 to your computer and use it in GitHub Desktop.

Select an option

Save minhajuddin/1226371 to your computer and use it in GitHub Desktop.
mind-stack
#!/bin/bash
# ======================================================= #
# __ __ _ _ ____ _ _ #
# | \/ (_)_ __ __| | _ / ___|| |_ __ _ ___| | __ #
# | |\/| | | '_ \ / _` | (_) \___ \| __/ _` |/ __| |/ / #
# | | | | | | | | (_| | _ ___) | || (_| | (__| < #
# |_| |_|_|_| |_|\__,_| (_) |____/ \__\__,_|\___|_|\_\ #
# #
# ======================================================= #
title=("$@")
unset title[0]
title_string=${title[*]}
space=" "
data_dir=~/.mind_stack
data_file=~/.mind_stack/data
mkdir -p $data_dir && touch $data_file
append(){
echo "$(date "+%Y-%m-%d %H:%M:")" "$title_string" > $data_file.tmp && cat $data_file >> $data_file.tmp && mv $data_file.tmp $data_file
}
push(){
echo "$(date "+%Y-%m-%d %H:%M:")" "$title_string" >> $data_file
}
list(){
tac ~/.mind_stack/data
}
peek(){
echo $( tail -1 $data_file | tr ":" "\n" | tail -1 | sed "s/^ *//g" )
}
pop(){
peek
head -n-1 $data_file > $data_file.tmp && mv $data_file.tmp $data_file
}
reset(){
mv $data_file $data_file.$(date +%Y%m%d%H%M%S)
}
if [ $# -eq 0 ]
then
list
exit
fi
case $1 in
push)
push
exit
;;
pop)
pop
exit
;;
peek)
peek
exit
;;
ls)
list
exit
;;
ap)
append
exit
;;
reset)
reset
exit
;;
help)
echo 'Mind :: Stack usage:'
echo '=========================================================='
echo 's [push] some stuff #to add something to the top of stack'
echo 's pop #to pop something from the top of the stack'
echo 's peek #to peek at something on the top of the stack'
echo 's ls #to list the whole stack'
echo 's help #to print this usage/help'
echo 's reset #to reset the stack'
echo '=========================================================='
exit
;;
*)
title_string=$1$space$title_string
push
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment