-
-
Save LeetCodes/009971dcfa22db0486a782931da763ab to your computer and use it in GitHub Desktop.
An auto-reloading .bashrc file
This file contains hidden or 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
if _BASHRC_WAS_RUN 2>/dev/null; then | |
:; | |
else # Stuff that only needs to run the first time we source .bashrc. | |
# Useful to allow re-sourcing new changes, without breaking/changing things in this section | |
alias _BASHRC_WAS_RUN=true | |
# ... continued ... | |
fi | |
# Last mod time of a file or files | |
get_file_timestamp () { | |
ls -1 --time-style=+%s -l "$@" | cut -f6 -d" " | |
} | |
# Make sure our version of the .bashrc file is up-to-date, or reload it. | |
chk_bashrc_timestamp () { | |
if [[ "$_BASHRC_TIMESTAMP" -lt "$(get_file_timestamp "$HOME/.bashrc")" ]]; then | |
echo >&2 "Reloading .bashrc..." | |
. ~/.bashrc | |
fi | |
} | |
_BASHRC_TIMESTAMP=$(date +%s) | |
prompt_cmd () { | |
chk_bashrc_timestamp | |
} | |
PROMPT_COMMAND=prompt_cmd | |
# some ls aliases | |
alias ll='ls -alF' | |
alias la='ls -A' | |
alias l='ls -CF' | |
# ... continued ... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment