machine_setup/ansible/roles/base/files/watch_freebsd

41 lines
692 B
Plaintext
Raw Normal View History

2023-07-03 16:54:10 +00:00
#!/usr/bin/env bash
#
# Imitate watch from linux
set -euo pipefail
IFS=$'\n\t'
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
############## Setup #########################
function cleanup {
switch_to_main_screen
}
for sig in EXIT INT QUIT HUP TERM; do
trap "set +e; cleanup; exit" "$sig"
done
############## Program #########################
function main {
switch_to_alt_screen
while true; do
local output=$("$@")
clear
cat <<<"$output"
sleep 2
done
}
function switch_to_alt_screen {
# tput smcup
echo -e "\e[?1049h"
clear
}
function switch_to_main_screen {
# tput rmcup
echo -e "\e[?1049l"
}
main "$@"