Skip to content

Instantly share code, notes, and snippets.

@MichaelDimmitt
Last active September 16, 2024 14:44
Show Gist options
  • Save MichaelDimmitt/2bb02d435a0ddbe2509a4cfef0fdfbe1 to your computer and use it in GitHub Desktop.
Save MichaelDimmitt/2bb02d435a0ddbe2509a4cfef0fdfbe1 to your computer and use it in GitHub Desktop.
Find the correct help function on command line.
function hhelp() {
help $1 > /dev/null 2>&1 && echo "yes, help $1" || echo "no, help $1" ;
man $1 > /dev/null 2>&1 && echo "yes, man $1" || echo "no, man $1";
$1 --help > /dev/null 2>&1 && echo "yes, $1 --help" || echo "no, $1 --help";
$1 -h > /dev/null 2>&1 && echo "yes, $1 -h" || echo "no, $1 -h";
apropos $1 > /dev/null 2>&1 && echo "yes, apropos $1" || echo "no, apropos $1";
whatis $1 > /dev/null 2>&1 && echo "yes, whatis $1" || echo "no, whatis $1";
which $1 > /dev/null 2>&1 && echo "yes, which $1" || echo "no, which $1";
}
# because sometimes it is hard to find the correct help function on command line.
@MichaelDimmitt
Copy link
Author

MichaelDimmitt commented Sep 10, 2024

some notes, and things to solve.

  1. You might end up executing the tool twice (--help and -h) by accident.

I think this is a non issue though. Who cares if you run a help function twice?
This command line currently swallows stdout and stderr. So you wont see anything on the tui.

And sometimes command lines ship with -h but don't ship with --help ... or vice versa so this solves a real problem.

  1. Most basic shell script based tools dont include argument parsing will simply run and ignore arguments/flags.

"The best solution would be to spin up a small docker image and run it in isolation" - Trenton
it looks like you can setup a chroot jail - https://www.baeldung.com/linux/sandboxing-process

@MichaelDimmitt
Copy link
Author

add tldr + a check to see if tldr exists before showing it now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment