Add a "w" alias for watch.

This commit is contained in:
Tom Alexander 2023-07-03 12:54:10 -04:00
parent 1d97921e7b
commit 55fec03445
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
4 changed files with 52 additions and 1 deletions

View File

@ -0,0 +1,40 @@
#!/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 "$@"

View File

@ -0,0 +1,8 @@
#!/usr/bin/env bash
#
# Invoke watch
set -euo pipefail
IFS=$'\n\t'
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
exec watch "$@"

View File

@ -94,6 +94,8 @@
loop:
- src: bemount.bash
dest: /usr/local/bin/bemount
- src: watch_freebsd
dest: /usr/local/bin/ww
- name: Install rc script
copy:
@ -121,4 +123,3 @@
group: wheel
loop:
- disk_labels

View File

@ -37,3 +37,5 @@
loop:
- src: mount_disk_image
dest: /usr/local/bin/mount_disk_image
- src: watch_linux
dest: /usr/local/bin/ww