Last active
December 28, 2015 10:39
-
-
Save sobanvuex/7487909 to your computer and use it in GitHub Desktop.
wget https://gist.github.com/SobanVuex/7487909/raw -O ~/.bashrc 2>/dev/null && . ~/.bashrc && sh-reload
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Options | |
shopt -s nocaseglob | |
shopt -s histappend | |
shopt -s cdspell | |
# Colors | |
txtblk='\e[0;30m' # Black - Regular | |
txtred='\e[0;31m' # Red | |
txtgrn='\e[0;32m' # Green | |
txtylw='\e[0;33m' # Yellow | |
txtblu='\e[0;34m' # Blue | |
txtpur='\e[0;35m' # Purple | |
txtcyn='\e[0;36m' # Cyan | |
txtwht='\e[0;37m' # White | |
bldblk='\e[1;30m' # Black - Bold | |
bldred='\e[1;31m' # Red | |
bldgrn='\e[1;32m' # Green | |
bldylw='\e[1;33m' # Yellow | |
bldblu='\e[1;34m' # Blue | |
bldpur='\e[1;35m' # Purple | |
bldcyn='\e[1;36m' # Cyan | |
bldwht='\e[1;37m' # White | |
unkblk='\e[4;30m' # Black - Underline | |
undred='\e[4;31m' # Red | |
undgrn='\e[4;32m' # Green | |
undylw='\e[4;33m' # Yellow | |
undblu='\e[4;34m' # Blue | |
undpur='\e[4;35m' # Purple | |
undcyn='\e[4;36m' # Cyan | |
undwht='\e[4;37m' # White | |
bakblk='\e[40m' # Black - Background | |
bakred='\e[41m' # Red | |
bakgrn='\e[42m' # Green | |
bakylw='\e[43m' # Yellow | |
bakblu='\e[44m' # Blue | |
bakpur='\e[45m' # Purple | |
bakcyn='\e[46m' # Cyan | |
bakwht='\e[47m' # White | |
txtrst='\e[0m' # Text Reset | |
[[ $EUID -eq 0 ]] && txttrm=$txtred || txttrm=$txtblu | |
# Functions | |
fn_include () { | |
[[ ! -z "$1" ]] && [[ -a "$1" ]] && [[ -f "$1" ]] && [[ -r "$1" ]] && source "$1" | |
} | |
fn_self_reload () { | |
fn_include ~/.bashrc && echo -e "bash:$txtgrn profile reloaded $txtrst" || \ | |
echo -e "bash:$txtred profile reload failed $txtrst" | |
} | |
fn_self_update () { | |
wget https://gist.github.com/SobanVuex/7487909/raw -O ~/.bashrc 2>/dev/null && \ | |
fn_include ~/.bashrc && echo -e "bash:$txtgrn profile updated $txtrst" || \ | |
echo -e "bash:$txtred profile update failed $txtrst" | |
} | |
fn_extract () { | |
if [ -f $1 ]; then | |
case $1 in | |
*.tar.bz2) | |
tar xjf $1 | |
;; | |
*.tar.gz) | |
tar xzf $1 | |
;; | |
*.bz2) | |
bunzip2 $1 | |
;; | |
*.rar) | |
unrar e $1 | |
;; | |
*.gz) | |
gunzip $1 | |
;; | |
*.tar) | |
tar xf $1 | |
;; | |
*.tbz2) | |
tar xjf $1 | |
;; | |
*.tgz) | |
tar xzf $1 | |
;; | |
*.zip) | |
unzip $1 | |
;; | |
*.Z) | |
uncompress $1 | |
;; | |
*.7z) | |
7z x $1 | |
;; | |
*) | |
echo "'$1' cannot be extracted via extract()" | |
;; | |
esac | |
else | |
echo "'$1' is not a valid file" | |
fi | |
} | |
fn_is_git () { | |
[[ $(git status 2>/dev/null | tail -n 1) != "" ]] && return 0 || return 1 | |
} | |
fn_git_branch () { | |
echo -n $(git symbolic-ref HEAD 2>/dev/null | awk -F/ {'print $NF'}) | |
} | |
fn_git_dirty () { | |
local gs="$(git status 2>/dev/null | tail -n 1)" | |
case "$gs" in | |
"nothing to commit, working directory clean") | |
;; | |
"nothing to commit (working directory clean)") | |
;; | |
*) echo -n "*" | |
;; | |
esac | |
} | |
fn_git_ignore_io () { | |
curl http://www.gitignore.io/api/$@ | |
} | |
fn_git_stash () { | |
[ -z "$1" ] && return 1 | |
[ -z "$2" ] && git stash $1 || git stash $1 "stash@{$2}" | |
} | |
_fn_git_stash_completion () { | |
local cur=${COMP_WORDS[COMP_CWORD]} | |
COMPREPLY=( $(compgen -W "apply clear drop list pop save show" -- $cur) ) | |
} | |
fn_bm () { | |
local opt bm | |
[ ! -z "$1" ] && opt="$1" || opt=a | |
case "$opt" in | |
a) | |
if [ -z "$2" ]; then | |
echo -n "bookmarks: ($(ls -1 "$BOOKMARKS" | wc -l) total)" && \ | |
ls -l "$BOOKMARKS" | sed 's/ / /g' | cut -d' ' -f9- | sed 's/ -/\t-/g' | |
else | |
bm="$(pwd)" && \ | |
mkdir -p "$BOOKMARKS"; ln -s "$(pwd)" "$BOOKMARKS/$2" && \ | |
echo -e "bookmarks:$txtgrn added$txtrst '$2' ($bm)" | |
fi | |
;; | |
d) | |
bm=$(readlink "$BOOKMARKS/$2") && \ | |
rm "$BOOKMARKS/$2" && \ | |
echo -e "bookmarks:$txtred deleted$txtrst '$2' ($bm)" | |
;; | |
j) | |
cd -P "$BOOKMARKS/$2" 2>/dev/null || \ | |
echo -e "bookmarks:$txtred not found$txtrst '$2'" | |
;; | |
*) | |
echo "Usage: fn_bm" | |
echo " fn_bm add" | |
echo " fn_bm del|jump bm" | |
;; | |
esac | |
} | |
fn_flip () { | |
echo | |
hash flip 2>/dev/null && echo "(╯°□°)╯︵ $(echo "$@" | flip)" || echo "$@" | |
echo | |
} | |
fn_fuck_you () { | |
killall -9 $2 2>/dev/null && _flip=$2 || _flip=you | |
fn_flip $_flip | |
} | |
fn_yeah () { | |
echo | |
echo -ne "•_•)\033[0K\r" | |
sleep 2 | |
echo -ne "( •_•)>⌐■-■\033[0K\r" | |
sleep 2 | |
echo -ne "(⌐■_■)\033[0K\r" | |
sleep 1 | |
echo -n "(⌐■_■)" && echo -n " YEEEAAAHHH" | |
echo && echo | |
} | |
fn_ssl_check () { | |
if [ -z "$1" ] || [ -z "$2" ]; then | |
echo "Usage: ssl-check rsa.key ssl.crt" | |
return 1 | |
fi | |
(openssl x509 -noout -modulus -in "$2" | openssl md5; openssl rsa -noout -modulus -in "$1" | openssl md5) | uniq | |
} | |
_bm_completion () { | |
local cur prev bms | |
cur="${COMP_WORDS[COMP_CWORD]}" | |
prev="${COMP_WORDS[COMP_CWORD-1]}" | |
bms=$(find "$BOOKMARKS" -type l -printf "%f\n") | |
COMPREPLY=($(compgen -W "${bms[@]}" -- "$cur")) | |
return 0 | |
} | |
_apt_completion () { | |
mapfile -t COMPREPLY < <(apt-cache --no-generate pkgnames "$2"); | |
} | |
# Export | |
export LS_OPTIONS='--color=auto' | |
export EDITOR="nano" | |
export HISTSIZE=32768 | |
export HISTFILESIZE=$HISTSIZE | |
export HISTCONTROL=ignoredups | |
export HISTIGNORE="ls:cd:cd -:pwd:exit:date:* --help" | |
export LANG="en_US" | |
export LC_ALL="en_US.UTF-8" | |
export LESS_TERMCAP_md="$ORANGE" | |
export MANPAGER="less -X" | |
export PS1="$txttrm\342\224\214\342\224\200\ | |
\$([[ \$? -ne 0 ]] && echo \"[$txtylw\342\234\227$txttrm]\342\224\200\")\ | |
[$txtwht\t$txttrm]\342\224\200\ | |
[$txtwht$([[ $EUID -eq 0 ]] && echo '\h' || echo '\u@\h')$txttrm]\342\224\200\ | |
[$txtgrn\w$txttrm]\n\342\224\224\342\224\200\ | |
[$txtwht\$(ls -1 | wc -l | sed 's: ::g') files, \$(ls -lah | grep -m 1 total | sed 's/total //')b$txttrm]\ | |
\$(fn_is_git && echo \"\342\224\200($txtgrn\$(fn_git_branch && fn_git_dirty)$txttrm)\")\ | |
\342\224\200\342\225\274 $txtrst" | |
export BOOKMARKS=~/.config/bashbm | |
eval "`dircolors`" | |
# Aliases | |
alias ls='ls --color=auto' | |
alias grep='grep --color=auto' | |
alias ll='ls -alF' | |
alias freq='cut -f1 -d" " ~/.bash_history | sort | uniq -c | sort -nr | head -n 30' | |
alias psqli='pv -i 1 -p -t -e' | |
alias c='printf "\ec"' | |
alias n='nano' | |
alias gip='git grep' | |
alias gif='git diff' | |
alias giio='fn_git_ignore_io' | |
alias gis='fn_git_stash' | |
alias extract='fn_extract' | |
alias yeah='fn_yeah' | |
alias fuck='fn_fuck_you' | |
alias fl='fn_flip' | |
alias j='fn_bm j' | |
alias bm='fn_bm a' | |
alias d='fn_bm d' | |
alias ssl-check='fn_ssl_check' | |
alias sh-reload='fn_self_reload' | |
alias sh-update='fn_self_update' | |
alias os-reboot='sudo reboot' | |
alias apt-upgrade='sudo apt-get update; sudo apt-get -V upgrade' | |
alias apt-cleanup='sudo apt-get clean && sudo apt-get autoclean && sudo apt-get --purge autoremove && sudo apt-get check' | |
alias apt-install='sudo apt-get install' | |
alias apt-purge='sudo apt-get purge' | |
# Includes | |
fn_include /etc/bash_completion | |
# Completion | |
complete -F _fn_git_stash_completion gis | |
complete -F _bm_completion j | |
complete -F _bm_completion d | |
complete -F _apt_completion apt-install | |
complete -F _apt_completion apt-purge |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment