Skip to content

Commit d9e62ff

Browse files
committed
update help colors
1 parent af47a1b commit d9e62ff

File tree

2 files changed

+88
-75
lines changed

2 files changed

+88
-75
lines changed

README.md

Lines changed: 61 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -101,61 +101,67 @@ sudo systemctl restart redis; await 'socat -u OPEN:/dev/null UNIX-CONNECT:/tmp/r
101101

102102
## --help
103103
```bash
104-
await [arguments] commands
105-
106-
# runs list of commands and waits for their termination
107-
108-
OPTIONS:
109-
--help #print this help
110-
--stdout -o #print stdout of commands
111-
--no-stderr -E #surpress stderr of commands by adding 2>/dev/null to commands
112-
--silent -V #do not print spinners and commands
113-
--fail -f #waiting commands to fail
114-
--status -s #expected status [default: 0]
115-
--any -a #terminate if any of command return expected status
116-
--change -c #waiting for stdout to change and ignore status codes
117-
--exec -e #run some shell command on success;
118-
--interval -i #milliseconds between one round of commands [default: 200]
119-
--forever -F #do not exit ever
120-
--service -S #create systemd user service with same parameters and activate it
121-
--version -v #print the version of await
122-
--autocomplete-fish #output fish shell autocomplete script
123-
--autocomplete-bash #output bash shell autocomplete script
124-
--autocomplete-zsh #output zsh shell autocomplete script
125-
126-
127-
NOTES:
128-
# \1, \2 ... \n - will be subtituted with n-th command stdout
129-
# you can use stdout substitution in --exec and in commands itself:
130-
await 'echo -n 10' 'echo -n $RANDOM' 'expr \1 + \2' --exec 'echo \3' --forever --silent
131-
132-
133-
EXAMPLES:
134-
# action on specific file type changes
135-
await 'stat **.c' --change --forever --exec 'gcc *.c -o await -lpthread'
136-
137-
# waiting google (or your internet connection) to fail
138-
await 'curl google.com' --fail
139-
140-
# waiting only google to fail (https://ec.haxx.se/usingcurl/usingcurl-returns)
141-
await 'curl google.com' --status 7
142-
143-
# waits for redis socket and then connects to
144-
await 'socat -u OPEN:/dev/null UNIX-CONNECT:/tmp/redis.sock' --exec 'redis-cli -s /tmp/redis.sock'
145-
146-
# lazy version
147-
await 'ls /tmp/redis.sock'; redis-cli -s /tmp/redis.sock
148-
149-
# daily checking if I am on french reviera. Just in case
150-
await 'curl https://ipapi.co/json 2>/dev/null | jq .city | grep Nice' --interval 86400
151-
152-
# Yet another server monitor
153-
await "curl 'https://whatnot.ai' &>/dev/null && echo 'UP' || echo 'DOWN'" --forever --change\
154-
--exec "ntfy send \'whatnot.ai \1\'"
155-
156-
# waiting for new iPhone in daemon mode
157-
await 'curl "https://www.apple.com/iphone/" -s | pup ".hero-eyebrow text{}" | grep -v 12'\
158-
--change --interval 86400 --daemon --exec "ntfy send \1"
104+
await [options] commands
105+

106+
# runs list of commands and waits for their termination
107+

108+

109+
EXAMPLES:
110+
# wait until your deployment is ready
111+
await 'curl 127.0.0.1:3000/healthz' \
112+
'kubectl wait --for=condition=Ready pod it-takes-forever-8545bd6b54-fk5dz' \
113+
"docker inspect --format='{{json .State.Running}}' elasticsearch 2>/dev/null | grep true" 
114+

115+
# action on specific file type changes
116+
await 'stat **.c' --change --forever --exec 'gcc *.c -o await -lpthread'
117+

118+
# waiting google (or your internet connection) to fail
119+
await 'curl google.com' --fail
120+

121+
# waiting only google to fail (https://ec.haxx.se/usingcurl/usingcurl-returns)
122+
await 'curl google.com' --status 7
123+

124+
# waits for redis socket and then connects to
125+
await 'socat -u OPEN:/dev/null UNIX-CONNECT:/tmp/redis.sock' --exec 'redis-cli -s /tmp/redis.sock'
126+

127+
# lazy version
128+
await 'ls /tmp/redis.sock'; redis-cli -s /tmp/redis.sock
129+

130+
# daily checking if I am on french reviera. Just in case
131+
await 'curl https://ipapi.co/json 2>/dev/null | jq .city | grep Nice' --interval 86400
132+

133+
# Yet another server monitor
134+
await "curl 'https://whatnot.ai' &>/dev/null && echo 'UP' || echo 'DOWN'" --forever --change\
135+
--exec "ntfy send \'whatnot.ai \1\'"
136+

137+
# waiting for new iPhone in daemon mode
138+
await 'curl "https://www.apple.com/iphone/" -s | pup ".hero-eyebrow text{}" | grep -v 12'\
139+
--change --interval 86400 --daemon --exec "ntfy send \1"
140+

141+

142+
OPTIONS:
143+
--help #print this help
144+
--stdout -o #print stdout of commands
145+
--no-stderr -E #surpress stderr of commands by adding 2>/dev/null to commands (doesn't work with pipes)
146+
--silent -V #do not print spinners and commands
147+
--fail -f #waiting commands to fail
148+
--status -s #expected status [default: 0]
149+
--any -a #terminate if any of command return expected status
150+
--change -c #waiting for stdout to change and ignore status codes
151+
--exec -e #run some shell command on success;
152+
--interval -i #milliseconds between one round of commands [default: 200]
153+
--forever -F #do not exit ever
154+
--service -S #create systemd user service with same parameters and activate it
155+
--version -v #print the version of await
156+
--autocomplete-fish #output fish shell autocomplete script
157+
--autocomplete-bash #output bash shell autocomplete script
158+
--autocomplete-zsh #output zsh shell autocomplete script
159+

160+

161+
NOTES:
162+
# \1, \2 ... \n - will be subtituted with n-th command stdout
163+
# you can use stdout substitution in --exec and in commands itself:
164+
await 'echo -n 10' 'echo -n $RANDOM' 'expr \1 + \2' --exec 'echo \3' --forever --silent
159165
160166
```
161167

await.c

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -241,14 +241,38 @@ char * replace_placeholders(char *string) {
241241
return string;
242242
}
243243

244+
char * colorize_comments(char *string) {
245+
string = replace("#", "\033[33m#", string);
246+
string = replace("\n", "\033[0m\n", string);
247+
return string;
248+
}
244249

245250
void help() {
246-
printf("await [arguments] commands\n\n"
251+
printf("%s", colorize_comments("await [options] commands\n\n"
247252
"# runs list of commands and waits for their termination\n"
253+
"\n\nEXAMPLES:\n"
254+
"# wait until your deployment is ready\n"
255+
" await 'curl 127.0.0.1:3000/healthz' \\\n\t'kubectl wait --for=condition=Ready pod it-takes-forever-8545bd6b54-fk5dz' \\\n\t\"docker inspect --format='{{json .State.Running}}' elasticsearch 2>/dev/null | grep true\" \n\n"
256+
"# action on specific file type changes\n"
257+
" await 'stat **.c' --change --forever --exec 'gcc *.c -o await -lpthread'\n\n"
258+
"# waiting google (or your internet connection) to fail\n"
259+
" await 'curl google.com' --fail\n\n"
260+
"# waiting only google to fail (https://ec.haxx.se/usingcurl/usingcurl-returns)\n"
261+
" await 'curl google.com' --status 7\n\n"
262+
"# waits for redis socket and then connects to\n"
263+
" await 'socat -u OPEN:/dev/null UNIX-CONNECT:/tmp/redis.sock' --exec 'redis-cli -s /tmp/redis.sock'\n\n"
264+
"# lazy version\n"
265+
" await 'ls /tmp/redis.sock'; redis-cli -s /tmp/redis.sock\n\n"
266+
"# daily checking if I am on french reviera. Just in case\n"
267+
" await 'curl https://ipapi.co/json 2>/dev/null | jq .city | grep Nice' --interval 86400\n\n"
268+
"# Yet another server monitor\n"
269+
" await \"curl 'https://whatnot.ai' &>/dev/null && echo 'UP' || echo 'DOWN'\" --forever --change\\\n --exec \"ntfy send \\'whatnot.ai \\1\\'\"\n\n"
270+
"# waiting for new iPhone in daemon mode\n"
271+
" await 'curl \"https://www.apple.com/iphone/\" -s | pup \".hero-eyebrow text{}\" | grep -v 12'\\\n --change --interval 86400 --daemon --exec \"ntfy send \\1\"\n\n"
248272
"\nOPTIONS:\n"
249273
" --help\t\t#print this help\n"
250274
" --stdout -o\t\t#print stdout of commands\n"
251-
" --no-stderr -E\t#surpress stderr of commands by adding 2>/dev/null to commands\n"
275+
" --no-stderr -E\t#surpress stderr of commands by adding 2>/dev/null to commands (doesn't work with pipes)\n"
252276
" --silent -V\t\t#do not print spinners and commands\n"
253277
" --fail -f\t\t#waiting commands to fail\n"
254278
" --status -s\t\t#expected status [default: 0]\n"
@@ -267,27 +291,10 @@ void help() {
267291
"# \\1, \\2 ... \\n - will be subtituted with n-th command stdout\n"
268292
"# you can use stdout substitution in --exec and in commands itself:\n"
269293
" await 'echo -n 10' 'echo -n $RANDOM' 'expr \\1 + \\2' --exec 'echo \\3' --forever --silent\n"
270-
"\n\nEXAMPLES:\n"
271-
"# action on specific file type changes\n"
272-
" await 'stat **.c' --change --forever --exec 'gcc *.c -o await -lpthread'\n\n"
273-
"# waiting google (or your internet connection) to fail\n"
274-
" await 'curl google.com' --fail\n\n"
275-
"# waiting only google to fail (https://ec.haxx.se/usingcurl/usingcurl-returns)\n"
276-
" await 'curl google.com' --status 7\n\n"
277-
"# waits for redis socket and then connects to\n"
278-
" await 'socat -u OPEN:/dev/null UNIX-CONNECT:/tmp/redis.sock' --exec 'redis-cli -s /tmp/redis.sock'\n\n"
279-
"# lazy version\n"
280-
" await 'ls /tmp/redis.sock'; redis-cli -s /tmp/redis.sock\n\n"
281-
"# daily checking if I am on french reviera. Just in case\n"
282-
" await 'curl https://ipapi.co/json 2>/dev/null | jq .city | grep Nice' --interval 86400\n\n"
283-
"# Yet another server monitor\n"
284-
" await \"curl 'https://whatnot.ai' &>/dev/null && echo 'UP' || echo 'DOWN'\" --forever --change\\\n --exec \"ntfy send \\'whatnot.ai \\1\\'\"\n\n"
285-
"# waiting for new iPhone in daemon mode\n"
286-
" await 'curl \"https://www.apple.com/iphone/\" -s | pup \".hero-eyebrow text{}\" | grep -v 12'\\\n --change --interval 86400 --daemon --exec \"ntfy send \\1\"\n\n"
287294

288295
// "# waiting for pup's author new blog post\n"
289296
// " await 'mv /tmp/eric.new /tmp/eric.old &>/dev/null; http \"https://ericchiang.github.io/\" | pup \"a attr{href}\" > /tmp/eric.new; diff /tmp/eric.new /tmp/eric.old' --fail --exec 'ntfy send \"new article $1\"'\n\n"
290-
);
297+
));
291298
exit(0);
292299
}
293300

0 commit comments

Comments
 (0)