Last active
December 24, 2024 01:00
-
-
Save hidsh/9febae96fdceafba90c455f7f3bc73fa to your computer and use it in GitHub Desktop.
show command help w/ fzf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
h() { | |
local tmp_file=/tmp/h | |
local cmd='' | |
if [ "$#" -eq 0 ]; then | |
cmd=$(echo $PATH | tr ':' '\n' | xargs -I {} find {} -maxdepth 1 -type f -executable 2>/dev/nul | |
l | xargs -n 1 basename | fzf); | |
elif [ "$#" -eq 1 ]; then | |
cmd=$1 | |
else | |
echo 'Usage: h shows help for which command choosen via fzf' | |
echo ' h <command> shows help for <command>' | |
fi | |
$cmd --help 1>$tmp_file 2>/dev/null | |
if [ "$?" != 0 ]; then | |
echo "No help for $cmd" | |
else | |
less $tmp_file | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment