Skip to content

Instantly share code, notes, and snippets.

@Paczesiowa
Created February 18, 2014 23:32
Show Gist options
  • Save Paczesiowa/9082833 to your computer and use it in GitHub Desktop.
Save Paczesiowa/9082833 to your computer and use it in GitHub Desktop.
automatically load aliases from .aliases file when entering a directory
MY_OLD_PWD=""
MY_ALIASES=""
function load_aliases() {
if [ "${PWD}" != "${MY_OLD_PWD}" ]; then
MY_OLD_PWD="${PWD}"
for NAME in ${MY_ALIASES}; do
unalias "${NAME}"
done
MY_ALIASES=""
ALIAS_FILE="${PWD}/.aliases"
if [ -f "${ALIAS_FILE}" ]; then
while read LINE; do
NAME=$(echo ${LINE} | perl -pe 's|=.*||')
VALUE=$(echo ${LINE} | perl -pe 's|.*?=||')
MY_ALIASES="${MY_ALIASES} ${NAME}"
alias "${NAME}=${VALUE}"
done < "${ALIAS_FILE}"
fi
fi
}
export PROMPT_COMMAND=load_aliases
# remember about new line at the end of the .aliases file
# cat /tmp/.aliases
# dupa=ls -l
# dupa2=ls -lh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment