Created
February 18, 2014 23:32
-
-
Save Paczesiowa/9082833 to your computer and use it in GitHub Desktop.
automatically load aliases from .aliases file when entering a directory
This file contains 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
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