Skip to content

Instantly share code, notes, and snippets.

@jcrsilva
Last active October 11, 2017 13:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jcrsilva/1884111eb78db6fbd1e7bb584c78b9bb to your computer and use it in GitHub Desktop.
Save jcrsilva/1884111eb78db6fbd1e7bb584c78b9bb to your computer and use it in GitHub Desktop.
.bashrc for server use
### File managed with puppet ###
# If not running interactively, don't do anything
[ -z "$PS1" ] && return
# don't put duplicate lines in the history. See bash(1) for more options
# ... or force ignoredups and ignorespace
HISTCONTROL=ignoredups:ignorespace
# append to the history file, don't overwrite it
shopt -s histappend
# for setting history length see HISTSIZE and HISTFILESIZE in bash(1)
HISTSIZE=10000
HISTFILESIZE=20000
# check the window size after each command and, if necessary,
# update the values of LINES and COLUMNS.
shopt -s checkwinsize
# make less more friendly for non-text input files, see lesspipe(1)
[ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)"
# set variable identifying the chroot you work in (used in the prompt below)
if [ -z "$debian_chroot" ] && [ -r /etc/debian_chroot ]; then
debian_chroot=$(cat /etc/debian_chroot)
fi
if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then
# Set color variables. These will be empty if no color prompt.
# Colors
BASE03='\[\033[38;5;234m\]'
BASE02='\[\033[38;5;235m\]'
BASE01='\[\033[38;5;240m\]'
BASE00='\[\033[38;5;241m\]'
BASE0='\[\033[38;5;244m\]'
BASE1='\[\033[38;5;245m\]'
BASE2='\[\033[38;5;254m\]'
BASE3='\[\033[38;5;230m\]'
YELLOW='\[\033[38;5;136m\]'
ORANGE='\[\033[38;5;166m\]'
RED='\[\033[38;5;160m\]'
MAGENTA='\[\033[38;5;125m\]'
VIOLET='\[\033[38;5;61m\]'
BLUE='\[\033[38;5;34m\]'
CYAN='\[\033[38;5;37m\]'
GREEN='\[\033[38;5;64m\]'
BOLD='\e[1m'
ITALIC='\e[3m'
UNDERLINE='\e[4m'
RESET='\[\033[0m\]'
fi
__prompt_command() {
local EXIT_CODE="$?" # This needs to be first
PS1=${RESET}
if [[ ${HOSTNAME} != *'.stg.'* ]]; then
PS1+="${ORANGE}[PROD]${RESET} "
fi
PS1+='${debian_chroot:+($debian_chroot)}'
# Some color logic
if [ ${EUID} -eq 0 ]; then
local USER_COLOR=${ORANGE}
else
local USER_COLOR=${GREEN}
fi
PS1+="${USER_COLOR}\u${RESET}"
PS1+="${BASE2}@${RESET}"
PS1+="${BASE1}\H${RESET}"
PS1+="${BASE2}:${RESET}"
PS1+="${ITALIC}${BASE1}\w${RESET} "
# Some color logic
if [ ${EXIT_CODE} -eq 0 ]; then
local STATUS_COLOR=${GREEN}
else
local STATUS_COLOR=${RED}
fi
PS1+="${STATUS_COLOR}\\\$${RESET}"
PS1+=' '
}
PROMPT_COMMAND=__prompt_command # Func to gen PS1 after CMDs
unset color_prompt force_color_prompt
# If this is an xterm set the title to user@host:dir
case "$TERM" in
xterm*|rxvt*)
PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1"
;;
*)
;;
esac
# enable color support of ls and also add handy aliases
if [ -x /usr/bin/dircolors ]; then
test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" \
|| test -r /usr/local/share/dircolors && eval "$(dircolors -b /usr/local/share/dircolors)" \
|| eval "$(dircolors -b)"
alias ls='ls --color=auto'
alias grep='grep --color=auto'
alias fgrep='fgrep --color=auto'
alias egrep='egrep --color=auto'
fi
# some more ls aliases
alias ll='ls -alF'
alias la='ls -A'
alias l='ls -CF'
# Alias definitions.
# You may want to put all your additions into a separate file like
# ~/.bash_aliases, instead of adding them here directly.
# See /usr/share/doc/bash-doc/examples in the bash-doc package.
# shellcheck source=/dev/null
if [ -f ~/.bash_aliases ]; then
. ~/.bash_aliases
fi
# enable programmable completion features (you don't need to enable
# this, if it's already enabled in /etc/bash.bashrc and /etc/profile
# sources /etc/bash.bashrc).
if [ -f /etc/bash_completion ] && ! shopt -oq posix; then
. /etc/bash_completion
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment