Skip to content

Instantly share code, notes, and snippets.

@chriskirkland
Created May 11, 2017 19:48
Show Gist options
  • Save chriskirkland/940725485b6774751d714272bce42a52 to your computer and use it in GitHub Desktop.
Save chriskirkland/940725485b6774751d714272bce42a52 to your computer and use it in GitHub Desktop.
Decorating bash aliases to print the underlying command
# prints the underlying command for an alias
function print_alias() {
BLUE="\033[1;34m" # Light Blue
NC='\033[0m' # No Color
printf ">>> Running ${BLUE}$(alias $@ | cut -d"'" -f2 | cut -d";" -f2- | cut -d'&' -f3-| xargs)${NC}\n"
}
### source aliases to decorate
source ~/.bash_aliases_decorated
### Decorate all aliases to print the underlying command (educational purposes)
while IFS='' read -r ALIAS
do
ALIAS_NAME=$(echo $ALIAS | cut -d'=' -f1)
ALIAS_VAL=$(echo $ALIAS | cut -d'=' -f2- | cut -d"'" -f2)
cmd="alias ${ALIAS_NAME}='print_alias ${ALIAS_NAME} && ${ALIAS_VAL}'"
eval "$cmd"
done < <(alias | cut -d' ' -f2-)
# source core aliases (not to be decorated); e.g. ggrep-->grep
source ~/.bash_aliases_core
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment