4 ms·
HEREDOC for help is nicer than echo IMHO
by bradwood 4y ago
HEREDOC for help is nicer than echo IMHO
- Beltalowda 4y agoYeah, you can actually indent it with <<- so it doesn't look so ugly. That said, I like doing the usage like so for short scripts: #!/bin/sh # # Sleep until a specific time. This takes a time in 24-hour clock format and # sleeps until the next instance of this time is reached. # # % sleep-until 15:30:45 # % sleep-until 15:30 # Until 15:30:00 # % sleep-until 15 # Until 15:00:00 # # Or to sleep until a specific date: # # % sleep-until 2023-01-01T15:00:00 # # Or space instead of T; can abbreviate time like above. echo " $@" | grep -q -- ' -h' && { sed '1,2d; /^[^#]/q; s/^# \?//;' "$0" | sed '$d'; exit 0; } # Show docs That will re-use the comment as the help: % sleep-until -h Sleep until a specific time. This takes a time in 24-hour clock format and sleeps until the next instance of this time is reached. … It's a bit of a byzantine incarnation, but I just copy it from one script to the next, it saves a bit of plumbing, and generally looks pretty nice IMO. I'm not 100% sure if I thought of this myself or if it's something I once saw somewhere.