Skip to content

Commit 059e551

Browse files
committed
--watch
1 parent 81d2586 commit 059e551

3 files changed

Lines changed: 40 additions & 4 deletions

File tree

README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,18 @@ await 'curl -s https://unreliable-api.com || echo failed' --no-stderr
119119
await 'some-verbose-command' 'another-command' --no-stderr --stdout --silent
120120
```
121121

122+
### Watch mode for clean monitoring
123+
```bash
124+
# Equivalent to: await 'uptime' -fVodE
125+
await 'uptime' --watch
126+
127+
# Monitor system resources with clean diff output
128+
await 'ps aux | head -10' --watch --interval 2000
129+
130+
# Watch log file changes with highlighted differences
131+
await 'tail -5 /var/log/system.log' --watch
132+
```
133+
122134
## --help
123135
```bash
124136
await [options] commands
@@ -166,6 +178,7 @@ OPTIONS:
166178
--help #print this help
167179
--stdout -o #print stdout of commands
168180
--no-stderr -E #suppress stderr output from commands
181+
--watch -w #equivalent to -fVodE (fail, silent, stdout, diff, no-stderr)
169182
--silent -V #do not print spinners and commands
170183
--fail -f #waiting commands to fail
171184
--status -s #expected status [default: 0]

await.c

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ void print_autocomplete_fish() {
9797
" set -l cmd (commandline -opc)\n"
9898
" for i in $cmd\n"
9999
" switch $i\n"
100-
" case --help --stdout --silent --fail --status --any --change --diff --exec --interval --forever --service\n"
100+
" case --help --stdout --silent --fail --status --any --change --diff --exec --interval --forever --service --watch\n"
101101
" return 1\n"
102102
" end\n"
103103
" end\n"
@@ -117,6 +117,7 @@ void print_autocomplete_fish() {
117117
"complete -c await -n '__fish_await_no_subcommand' -l forever -s F -d 'Do not exit ever'\n"
118118
"complete -c await -n '__fish_await_no_subcommand' -l service -s S -d 'Create systemd user service with same parameters and activate it'\n"
119119
"complete -c await -n '__fish_await_no_subcommand' -l no-stderr -s E -d 'Surpress stderr of commands by adding 2>/dev/null to commands'\n"
120+
"complete -c await -n '__fish_await_no_subcommand' -l watch -s w -d 'Equivalent to -fVodE (fail, silent, stdout, diff, no-stderr)'\n"
120121
"\n"
121122
"# For command completion\n"
122123
"complete -c await -f -a '(__fish_complete_command)'\n");
@@ -129,7 +130,7 @@ void print_autocomplete_bash() {
129130
" cur=\"${COMP_WORDS[COMP_CWORD]}\"\n"
130131
" prev=\"${COMP_WORDS[COMP_CWORD-1]}\"\n"
131132
"\n"
132-
" opts=\"--help --stdout --silent --fail --status --any --change --diff --exec --interval --forever --service --version --no-stderr\"\n"
133+
" opts=\"--help --stdout --silent --fail --status --any --change --diff --exec --interval --forever --service --version --no-stderr --watch\"\n"
133134
"\n"
134135
" case \"${prev}\" in\n"
135136
" --status|--exec|--interval)\n"
@@ -171,6 +172,7 @@ void print_autocomplete_zsh() {
171172
" '--exec[Run some shell command on success]::command:_command_names' \\\n"
172173
" '--interval[Milliseconds between rounds of commands (default: 200)]::interval' \\\n"
173174
" '--forever[Do not exit ever]' \\\n"
175+
" '--watch[Equivalent to -fVodE (fail, silent, stdout, diff, no-stderr)]' \\\n"
174176
" '--service[Create systemd user service with same parameters and activate it]'\n"
175177
"}\n"
176178
"\n"
@@ -350,6 +352,7 @@ void help() {
350352
" --help\t\t#print this help\n"
351353
" --stdout -o\t\t#print stdout of commands\n"
352354
" --no-stderr -E\t#suppress stderr output from commands\n"
355+
" --watch -w\t\t#equivalent to -fVodE (fail, silent, stdout, diff, no-stderr)\n"
353356
" --silent -V\t\t#do not print spinners and commands\n"
354357
" --fail -f\t\t#waiting commands to fail\n"
355358
" --status -s\t\t#expected status [default: 0]\n"
@@ -403,14 +406,15 @@ void parse_args(int argc, char *argv[]) {
403406
{"exec", required_argument, 0, 'e'},
404407
{"interval",required_argument, 0, 'i'},
405408
{"no-stderr", no_argument, 0, 'E'},
409+
{"watch", no_argument, 0, 'w'},
406410
{"autocomplete-fish", no_argument, 0, 0},
407411
{"autocomplete-bash", no_argument, 0, 0},
408412
{"autocomplete-zsh", no_argument, 0, 0},
409413
{0, 0, 0, 0}
410414
};
411415

412416
int option_index = 0;
413-
getopt = getopt_long(argc, argv, "oVafFchdvS:s:e:i:E", long_options, &option_index);
417+
getopt = getopt_long(argc, argv, "oVafFchdvS:s:e:i:Ew", long_options, &option_index);
414418

415419
if (getopt == -1)
416420
break;
@@ -454,7 +458,7 @@ void parse_args(int argc, char *argv[]) {
454458
case 'S': args.service = optarg; break;
455459
case 'i': args.interval = atoi(optarg); break;
456460
case 'd': args.diff = 1; break;
457-
case 'v': printf("2.0.0\n"); exit(0); break;
461+
case 'v': printf("2.1.0\n"); exit(0); break;
458462
case 'h': case '?': help(); break;
459463
case 1:
460464
if (strcmp(long_options[option_index].name, "autocomplete-fish") == 0) {
@@ -475,6 +479,13 @@ void parse_args(int argc, char *argv[]) {
475479
}
476480
break;
477481
case 'E': args.no_stderr = 1; break;
482+
case 'w':
483+
args.fail = 1;
484+
args.silent = 1;
485+
args.stdout = 1;
486+
args.diff = 1;
487+
args.no_stderr = 1;
488+
break;
478489
}
479490
}
480491

hooks/pre-commit

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,18 @@ await 'curl -s https://unreliable-api.com || echo "failed"' --no-stderr
121121
await 'some-verbose-command' 'another-command' --no-stderr --stdout --silent
122122
\`\`\`
123123
124+
### Watch mode for clean monitoring
125+
\`\`\`bash
126+
# Equivalent to: await 'uptime' -fVodE
127+
await 'uptime' --watch
128+
129+
# Monitor system resources with clean diff output
130+
await 'ps aux | head -10' --watch --interval 2000
131+
132+
# Watch log file changes with highlighted differences
133+
await 'tail -5 /var/log/system.log' --watch
134+
\`\`\`
135+
124136
## --help
125137
\`\`\`bash
126138
$(./await --help | sed 's/\x1b\[[0-9;]*m//g')

0 commit comments

Comments
 (0)