Skip to content

Instantly share code, notes, and snippets.

@NicholasRoge
Last active March 4, 2017 22:23
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 NicholasRoge/0eaad2bd8532ec599a6f07c7bb5c101f to your computer and use it in GitHub Desktop.
Save NicholasRoge/0eaad2bd8532ec599a6f07c7bb5c101f to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
source "overload"
output=
output_updated()
{
clear
echo "$1" | head -n $(tput lines)
# Move the (currently hidden) cursor to position 0,0
printf "\e[0;0H"
}
update_output()
{
parent "$@"
_output="`${command[@]}`"
if [[ "$_output" != "$output" ]]
then
output="$_output"
output_updated "$output"
fi
}
view_in_less()
{
parent "$@"
tput cnorm
stty echo
echo "$output" | less
stty -echo
tput civis
}
watch()
{
command=( "$@" )
if ! $running
then
overload update "update_output"
overload key_pressed l "view_in_less"
run
fi
}
if [[ "${BASH_SOURCE[0]}" == "$0" ]]
then
watch "$@"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment