Skip to content

Instantly share code, notes, and snippets.

@jpaugh
Created September 6, 2017 13:53
Show Gist options
  • Save jpaugh/11d06ee4b02acff784bfc61964a0263a to your computer and use it in GitHub Desktop.
Save jpaugh/11d06ee4b02acff784bfc61964a0263a to your computer and use it in GitHub Desktop.
An auto-reloading .bashrc file
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