Last active
March 4, 2017 22:23
-
-
Save NicholasRoge/0eaad2bd8532ec599a6f07c7bb5c101f to your computer and use it in GitHub Desktop.
This file contains 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
#!/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