Skip to content

Instantly share code, notes, and snippets.

@shirobachi
Created May 7, 2023 12:58
Show Gist options
  • Save shirobachi/0f18759963101ece81aeab2e987c112d to your computer and use it in GitHub Desktop.
Save shirobachi/0f18759963101ece81aeab2e987c112d to your computer and use it in GitHub Desktop.

Sup, fellow command-line wizards!

You know what's wild? I installed some Git aliases in my zsh, and I'm like, "How the heck am I going to remember all these shortcuts?!"

But then, boom! I got my thinker thinking, and I whipped up this rad little script. It runs before every command you enter, checking for matching aliases and giving you a heads up if any are available to make your life easier and cooler.

Here's what it looks like:

Pretty groovy, right? I guarantee it's a total game-changer, and it's only going to get better as I tinker around with it.

Wanna give this baby a spin? Seriously, you won't regret it. Just toss this script into your .zshrc file (or .bashrc, if that's your jam), and let the magic unfold.

Any issues are welcome in gist comment :)

Stay funky, shell aficionados!

# This function should inform user if found that some alias expand to $*
# [ ] make dismiss command what will look on history and ask user which command to dismiss, when choose, it will save this and won't show again alises for this command
# [ ] Add checking param by param save how many match and how much does not, and make decision based on that and constants sets
# [ ] Check in history if same usage big amount of times and no alias suggest to create one
function info_aliases() {
# Check if an alias exists for the command, remove if has double '=' in whole command
ALIASES_MATCHES=$(alias | tr -d "\'\"" | grep -E "=$*" | grep -vE ".+=.+=")
messages_hey=( "Hey there, you!" "Hey you! Yes, you!" "Hey, listen up!" "Hey there buddy!" "Hey, what's up doc?" )
messages_content=( "You have alias for \`$1\`" "There is alias for \`$1\`" "Here is easier way to run \`$1\`" "You can run \`$1\` with aliases" )
[[ -z $ALIASES_MATCHES ]] && return 0
echo ${messages_hey[$(($RANDOM % ${#messages_hey[@]} + 1 ))]} | figlet -f slant -w 100
echo ${messages_content[$(($RANDOM % ${#messages_content[@]} + 1 ))]}
echo
echo $ALIASES_MATCHES | sed 's/^/- /g' | column -t -s '=' --table
echo -e "\n\n"
}
preexec() {
info_aliases "$1"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment