Skip to content

Instantly share code, notes, and snippets.

@BriellaBugs
Created July 17, 2026 19:02
Show Gist options
  • Select an option

  • Save BriellaBugs/36e53a0e188fdea1c5de7e2732e22437 to your computer and use it in GitHub Desktop.

Select an option

Save BriellaBugs/36e53a0e188fdea1c5de7e2732e22437 to your computer and use it in GitHub Desktop.
nwatch <time> <command>
1 #!/bin/bash
2
3 #
4 # nwatch <time <command>
5 #
6
7 catch_exit() {
8 printf "\e[2J\e[?47l\e[?25h\e8"
9 stty sane
10 exit 130
11 }
12 trap catch_exit INT
13
14 if [ -z "$1" ]; then
15 printf "No time given\n"
16 printf 'Usage: %s <time> <command>\n' "$(basename "$0")"
17 exit
18 else
19 if [ -z "$2" ]; then
20 printf "No command given\n"
21 printf 'Usage: %s <time> <command>\n' "$(basename "$0")"
22 exit
23 else
24 command="${*:2}"
25
26 printf "\e7\e[?47h\e[1J\e[?25l" # Init
27 while true; do
28 printf "\e[H"
29 printf "\e[1mEvery $1 sec:\e[0m $command\e[0K\n\e[0K\n"
30 eval "$command"
31 [ "$?" -eq 130 ] && catch_exit
32 printf "\e[0J"
33 sleep "$1"
34 [ "$?" -eq 130 ] && catch_exit
35 done
36 fi
37 fi
38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment