Created
March 9, 2017 14:10
-
-
Save zellyn/fe02ec40258bcb09a85c853f6c90ad26 to your computer and use it in GitHub Desktop.
My watchloop script, and helper functions
This file contains hidden or 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
alias csb="clear && printf '\e[3J'" |
This file contains hidden or 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
# 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 | |
} | |
This file contains hidden or 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
# 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