110 lines
3.6 KiB
Plaintext
110 lines
3.6 KiB
Plaintext
# ~/.bashrc
|
|
|
|
function git_branch() {
|
|
git_branch=$(git branch --no-color 2>/dev/null | grep \* | sed 's/* //')
|
|
|
|
if [ $git_branch ]
|
|
then
|
|
white="\001\033[0;37m\002"
|
|
yellow="\001\033[0;33m\002"
|
|
blue="\001\033[0;34m\002"
|
|
red="\001\033[0;31m\002"
|
|
|
|
git_status=$(git status --porcelain 2>/dev/null)
|
|
git_count_t=$(for i in "$git_status"; do echo "$i"; done | grep -v '^?? ' | sed '/^$/d' | wc -l | sed "s/ //g")
|
|
git_count_color_t=$(if [ $git_count_t = "0" ]; then echo -e "$blue"; else echo -e "$red"; fi)
|
|
git_count_ut=$(for i in "$git_status"; do echo "$i"; done | grep '^?? ' | sed '/^$/d' | wc -l | sed "s/ //g")
|
|
git_count_color_ut=$(if [ $git_count_ut = "0" ]; then echo -e "$blue"; else echo -e "$red"; fi)
|
|
|
|
echo -e "$white:$yellow${git_branch}$white:$git_count_color_t${git_count_t}$white:$git_count_color_ut${git_count_ut}"
|
|
fi
|
|
}
|
|
|
|
function pushall() {
|
|
sudo git add .
|
|
sudo git commit --all
|
|
sudo git push --all
|
|
}
|
|
|
|
short_pwd() {
|
|
cwd=$(pwd | sed "s#${HOME}#~#g" | perl -F/ -ane 'print join( "/", map { $i++ < @F - 1 ? substr $_,0,1 : $_ } @F)')
|
|
echo -n $cwd
|
|
}
|
|
|
|
set_bash_prompt() {
|
|
if [ "$UID" = 0 ]; then
|
|
#root
|
|
PS1="\[\033[0;31m\]\u\[\033[0;37m\]@\h\[\033[1;37m\] \[\033[0;31m\]\$(short_pwd)\$(git_branch)\[\033[0;36m\]# \[\033[0m\]"
|
|
else
|
|
#non-root
|
|
PS1="\[\033[0;32m\]\u\[\033[0;37m\]@\h\[\033[1;37m\] \[\033[0;32m\]\$(short_pwd)\$(git_branch)\[\033[0;36m\]$ \[\033[0m\]"
|
|
fi
|
|
}
|
|
|
|
# Extracts pretty much anything you throw at it granted you have the program for it.
|
|
extract() {
|
|
if [ -z ${1} ] || [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
|
|
echo "Usage: extract <archive> [directory]"
|
|
echo "Example: extract presentation.zip."
|
|
echo "Valid archive types are:"
|
|
echo "tar.bz2, tar.gz, tar.xz, tar, bz2, gz, tbz2,"
|
|
echo "tbz, tgz, lzo, rar, zip, 7z, xz, txz, lzma and tlz"
|
|
else
|
|
case "$1" in
|
|
*.tar.bz2|*.tbz2|*.tbz) tar xvjf "$1" ;;
|
|
*.tgz) tar zxvf "$1" ;;
|
|
*.tar.gz) tar xvzf "$1" ;;
|
|
*.tar.xz) tar xvJf "$1" ;;
|
|
*.tar) tar xvf "$1" ;;
|
|
*.rar) 7z x "$1" ;;
|
|
*.zip) unzip "$1" ;;
|
|
*.7z) 7z x "$1" ;;
|
|
*.lzo) lzop -d "$1" ;;
|
|
*.gz) gunzip "$1" ;;
|
|
*.bz2) bunzip2 "$1" ;;
|
|
*.Z) uncompress "$1" ;;
|
|
*.xz|*.txz|*.lzma|*.tlz) xz -d "$1" ;;
|
|
*) echo "Sorry, '$1' could not be decompressed." ;;
|
|
esac
|
|
fi
|
|
}
|
|
|
|
# Goes up many dirs as the number passed as argument, if none goes up by 1 by default
|
|
up(){
|
|
local d=""
|
|
limit=$1
|
|
for ((i=1 ; i <= limit ; i++))
|
|
do
|
|
d=$d/..
|
|
done
|
|
d=$(echo $d | sed 's/^\///')
|
|
if [ -z "$d" ]; then
|
|
d=..
|
|
fi
|
|
cd $d
|
|
}
|
|
|
|
# Creates a directory and immediately changes into it.
|
|
mkcd() {
|
|
mkdir -p "$1" && cd "$1"
|
|
}
|
|
|
|
# Displays your external IP address
|
|
myip() {
|
|
curl -s ifconfig.me
|
|
}
|
|
|
|
# Get colors in manual pages
|
|
man() {
|
|
env \
|
|
LESS_TERMCAP_mb="$(printf '\e[1;31m')" \
|
|
LESS_TERMCAP_md="$(printf '\e[1;31m')" \
|
|
LESS_TERMCAP_me="$(printf '\e[0m')" \
|
|
LESS_TERMCAP_se="$(printf '\e[0m')" \
|
|
LESS_TERMCAP_so="$(printf '\e[1;44;33m')" \
|
|
LESS_TERMCAP_ue="$(printf '\e[0m')" \
|
|
LESS_TERMCAP_us="$(printf '\e[1;32m')" \
|
|
man "$@"
|
|
}
|
|
|