config/bash/bashrc-server
2025-12-11 16:32:41 +01:00

76 lines
2.3 KiB
Plaintext

## Enable color support of ls and also add handy aliases
# Some colors
alias ls='ls --color=auto'
alias grep='grep --color=auto'
# Some utils aliases
alias ll='ls -l'
alias la='ls -A'
alias rmrf='rm -rf'
alias gcl='git clone'
# Aliases for executing ~/.script scripts
alias gitan='sh ~/.script/gitan.sh'
alias clean='sh ~/.script/clean.sh'
## Some export
# colored GCC warnings and errors
export GCC_COLORS='error=01;31:warning=01;35:note=01;36:caret=01;32:locus=01:quote=01'
# Set history size to unlimited
export HISTSIZE=-1
export HISTFILESIZE=-1
# For header vim
#export VIUSER=xuser
#export VIMAIL=xuser@xdomain.tld
## Activate and custom bash completion
#bind 'TAB:menu-complete'
#bind 'set show-all-if-ambiguous on'
## Setting prompt style
# Get current branch in git repo
function parse_git_branch() {
BRANCH=`git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/'`
if [ ! "${BRANCH}" == "" ]
then
STAT=`parse_git_dirty`
echo " [${BRANCH}${STAT}]"
else
echo ""
fi
}
# get current status of git repo
function parse_git_dirty {
status=`git status 2>&1 | tee`
dirty=`echo -n "${status}" 2> /dev/null | grep "modified:" &> /dev/null; echo "$?"`
untracked=`echo -n "${status}" 2> /dev/null | grep "Untracked files" &> /dev/null; echo "$?"`
ahead=`echo -n "${status}" 2> /dev/null | grep "Your branch is ahead of" &> /dev/null; echo "$?"`
newfile=`echo -n "${status}" 2> /dev/null | grep "new file:" &> /dev/null; echo "$?"`
renamed=`echo -n "${status}" 2> /dev/null | grep "renamed:" &> /dev/null; echo "$?"`
deleted=`echo -n "${status}" 2> /dev/null | grep "deleted:" &> /dev/null; echo "$?"`
bits=''
if [ "${renamed}" == "0" ] || [ "${newfile}" == "0" ] || [ "${untracked}" == "0" ] || [ "${dirty}" == "0" ]; then
bits="+${bits}"
fi
if [ "${ahead}" == "0" ]; then
bits="*${bits}"
fi
if [ "${deleted}" == "0" ]; then
bits="-${bits}"
fi
if [ ! "${bits}" == "" ]
then
echo " ${bits}"
else
echo ""
fi
}
IP_LOC=`ip -4 -o addr show | grep "eth0" | cut -f7 -d' ' | cut -f1 -d'/'`
IP_PUB=`wget -q -O - checkip.dyndns.org|sed -e 's/.*Current IP Address: //' -e 's/<.*$//'`
export PS1='` if [ $? = 0 ]; then echo "\[\033[01;32m\]✔"; else echo "\[\033[01;31m\]✘"; fi` \[\033[36m\]\u\[\033[00m\]@\[\033[01;36m\]$IP_LOC\[\033[32m\] \w\[\033[34m\]$(parse_git_branch " %s") \[\033[0m\]>\[\033[00m\] '