Skip to content

Instantly share code, notes, and snippets.

@live2ravi
Last active August 14, 2023 15:35
Show Gist options
  • Save live2ravi/d7b87f427224ac0ade10635e38294419 to your computer and use it in GitHub Desktop.
Save live2ravi/d7b87f427224ac0ade10635e38294419 to your computer and use it in GitHub Desktop.
Bash profile
#!/usr/bin/env bash
# Customizations for PM2 logs and Git
# Colors for better visualization
blk="\[\e[1;30m\]"
red="\[\e[1;31m\]"
grn="\[\e[1;32m\]"
ylw="\[\e[1;33m\]"
blu="\[\e[1;34m\]"
mgnt="\[\e[1;35m\]"
cyn="\[\e[1;36m\]"
rst="\[\e[m\]"
# Download and setup git-prompt if not present
if [ ! -e ~/.git-prompt.sh ]; then
curl -s -o ~/.git-prompt.sh https://raw.githubusercontent.com/git/git/master/contrib/completion/git-prompt.sh
fi
source ~/.git-prompt.sh
GIT_PS1_SHOWDIRTYSTATE=true
GIT_PS1_SHOWSTASHSTATE=true
GIT_PS1_SHOWUNTRACKEDFILES=true
# Custom prompt with git branch visualization
if [[ $(id -u) -eq 0 ]]; then
# Root user - display red prompt
PS1="$red[\u@\h] $blu\w$rst$ylw\$(__git_ps1 ' (%s)') $rst$ylwϟ $rst"
elif [[ -n "$SSH_CLIENT" ]]; then
# Connected via SSH
PS1="\n$rst[$grn\u$rst@$red\h$rst]$blu \w$rst$ylw\$(__git_ps1 ' (%s)') $rst$ylw❯$rst "
else
# Local user
PS1="$blu\w$rst$ylw\$(__git_ps1 ' (%s)') $rst$ylw❯ $rst"
fi
# Git Aliases
alias gs="git status"
alias gl="git log --oneline --graph --decorate"
alias ga="git add"
alias gc="git commit"
alias gp="git push"
alias gff="git pull --ff-only"
# Aliases for better PM2 logs visualization
alias pm2logs="pm2 logs | lolcat" # Colorize pm2 logs output
# If lolcat isn't installed, just display the usual logs
if ! command -v lolcat &> /dev/null; then
unalias pm2logs
alias pm2logs="pm2 logs"
fi
# Load nvm, if available
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"
# History customizations
# Use standard ISO 8601 timestamp
# %F equivalent to %Y-%m-%d
# %T equivalent to %H:%M:%S (24-hours format)
export HISTTIMEFORMAT='%F %T '
export HISTCONTROL="erasedups:ignoreboth"
export HISTSIZE=10000
export HISTFILESIZE=$HISTSIZE
shopt -s histappend # Append history
shopt -s cmdhist # Save multi-line commands as one command
export HISTIGNORE="&:[ ]*:exit:cd:ls:bg:fg:hist:history:clear"
# Save and reload history after each command
export PROMPT_COMMAND="history -a; history -c; history -r; $PROMPT_COMMAND"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment