Last active
December 15, 2024 18:41
-
-
Save sebastiancarlos/fed16de732ba36d684e8cd829525c0cc to your computer and use it in GitHub Desktop.
commands - list all commands in your PATH, and their directories
This file contains hidden or 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
# All my gist code is licensed under the terms of the MIT license. | |
# Video demo: https://www.youtube.com/shorts/9sKEQ-DFL8I | |
# commands | |
# - list all commands in your PATH, and their directories | |
function commands () { | |
local green='\x1b[32m' | |
local reset='\x1b[0m' | |
compgen -c | \ | |
while read -r command; do | |
printf "%s\t" "$command" | |
type -P $command || printf "\n" | |
done | \ | |
# remove lines with only one word | |
# make first word green | |
# remove everything after last "/" | |
command sed -E -n '/^([^\t]+)\t([^\t]*)\/[^\t]+$/ {s//'"${green}"'\1'"${reset}"'\t\2/g; p}' | \ | |
column -t -s $'\t' | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment