From 55fec0344537458606ce7b478f2541da59713020 Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Mon, 3 Jul 2023 12:54:10 -0400 Subject: [PATCH] Add a "w" alias for watch. --- ansible/roles/base/files/watch_freebsd | 40 ++++++++++++++++++++++++++ ansible/roles/base/files/watch_linux | 8 ++++++ ansible/roles/base/tasks/freebsd.yaml | 3 +- ansible/roles/base/tasks/linux.yaml | 2 ++ 4 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 ansible/roles/base/files/watch_freebsd create mode 100644 ansible/roles/base/files/watch_linux diff --git a/ansible/roles/base/files/watch_freebsd b/ansible/roles/base/files/watch_freebsd new file mode 100644 index 0000000..6b56000 --- /dev/null +++ b/ansible/roles/base/files/watch_freebsd @@ -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 "$@" diff --git a/ansible/roles/base/files/watch_linux b/ansible/roles/base/files/watch_linux new file mode 100644 index 0000000..e9a6b68 --- /dev/null +++ b/ansible/roles/base/files/watch_linux @@ -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 "$@" diff --git a/ansible/roles/base/tasks/freebsd.yaml b/ansible/roles/base/tasks/freebsd.yaml index c0a464e..05ba700 100644 --- a/ansible/roles/base/tasks/freebsd.yaml +++ b/ansible/roles/base/tasks/freebsd.yaml @@ -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 - diff --git a/ansible/roles/base/tasks/linux.yaml b/ansible/roles/base/tasks/linux.yaml index 67b3554..a6017c3 100644 --- a/ansible/roles/base/tasks/linux.yaml +++ b/ansible/roles/base/tasks/linux.yaml @@ -37,3 +37,5 @@ loop: - src: mount_disk_image dest: /usr/local/bin/mount_disk_image + - src: watch_linux + dest: /usr/local/bin/ww