Skip to content

Instantly share code, notes, and snippets.

@eusonlito
Last active April 22, 2021 10:31
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eusonlito/cd015b050d1caf3b1ff0 to your computer and use it in GitHub Desktop.
Save eusonlito/cd015b050d1caf3b1ff0 to your computer and use it in GitHub Desktop.
Simple bash promp configuration
## User installation:
#
# 1) Append to user file ~/.bashrc
#
# Wide System installation:
#
# 1) Create /etc/bash.bashrc.d folder
# 2) Paste this file into /etc/bash.bashrc.d/custom.sh file
# 3) Append ". /etc/bash.bashrc.d/custom.sh" at end of /etc/bash.bashrc file
#
# 1) Remove history limit and add time to .bash_history / history command
export HISTCONTROL="ignoredups:ignorespace"
export HISTFILESIZE=-1
export HISTSIZE=-1
export HISTTIMEFORMAT="%F %T "
# 2) Backup bash history into hidden user ".log" folder
export CLIENT_IP=$(echo "$SSH_CLIENT" | cut -d' ' -f 1)
export HISTORY_LOG_PATH=~/.logs/bash-history
if [ ! -d "$HISTORY_LOG_PATH" ]; then
install -d "$HISTORY_LOG_PATH"
fi
log_bash_history () {
echo "$CLIENT_IP $(pwd) $(history 1)" >> "$HISTORY_LOG_PATH/$(date "+%Y-%m-%d").log";
}
if [ "$(echo "$PROMPT_COMMAND" | grep 'log_bash_history')" == "" ]; then
export PROMPT_COMMAND='log_bash_history; '$PROMPT_COMMAND
fi
# 3) Useful bash prompt
pwdtail () {
pwd | awk -F/ '{nlast = NF -1; print $nlast "/" $NF}'
}
export PS1='${debian_chroot:+($debian_chroot)}\[\e[0;33m\]\A\[\e[m\] \[\033[01;31m\]\u\[\033[01;33m\]@\[\033[01;32m\]\h\[\033[00m\]:\[\033[01;94m\]$(pwdtail)\[\033[00m\]$ '
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment