Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
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
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
You can’t perform that action at this time.