Skip to content

Instantly share code, notes, and snippets.

@zellyn
Created March 9, 2017 14:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zellyn/fe02ec40258bcb09a85c853f6c90ad26 to your computer and use it in GitHub Desktop.
Save zellyn/fe02ec40258bcb09a85c853f6c90ad26 to your computer and use it in GitHub Desktop.
My watchloop script, and helper functions
alias csb="clear && printf '\e[3J'"
# Print a horizontal rule, the width of the terminal
# http://wiki.bash-hackers.org/snipplets/print_horizontal_line
function hr {
# Optional arg $1: number of blank lines before
# Optional arg $2: number of blank lines after
if [[ $1 > 0 ]]
then
printf '%*s\n' $(($1+0)) '' | tr ' ' '\n'
fi
printf '%*s\n' "${COLUMNS:-$(tput cols)}" '' | tr ' ' -
if [[ $2 > 0 ]]
then
printf '%*s\n' $(($2+0)) '' | tr ' ' '\n'
fi
}
# perform an action in a loop
function watchloop {
local clear=0
if [[ "$1" = "-c" ]]
then
clear=1
shift
fi
local dir=$1
shift
while true
do
hr
[[ $clear == 1 ]] && clear && printf '\e[3J'
$* && echo ok
fswatch -1 -r $dir > /dev/null
sleep 0.2
done
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment