1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | #
# ~/.bashrc
#
# If not running interactively, don't do anything
[[ $- != *i* ]] && return
# Source the Git promt script
source /usr/share/git/completion/git-prompt.sh
# Load files from ~/.bashrc.d
if [ -d ${HOME}/.bashrc.d ]; then
for file in ${HOME}/.bashrc.d/*; do
source "$file";
done
fi
|
x
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | #
# ~/.bashrc.d/aliases
#
if [ -x /usr/bin/dircolors ]; then
# Color support
test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)"
alias ls='ls --color=auto --group-directories-first'
alias la='ls -a --color=auto --group-directories-first'
alias ll='ls -l --color=auto --group-directories-first'
alias dir='dir --color=auto'
alias vdir='vdir --color=auto'
alias grep='grep --color=auto -in'
alias egrep='egrep --color=auto'
alias fgrep='fgrep --color=auto'
else
alias ls='ls --group-directories-first'
alias la='ls -a --group-directories-first'
alias ll='ls -l --group-directories-first'
alias grep='grep -in'
fi
alias install='sudo pacman -S'
alias update='sudo pacman -Syu'
alias install-aur='yaourt -S'
alias update-aur='yaourt -Syua'
alias start='sudo systemctl start '
alias restart='sudo systemctl restart '
alias stop='sudo systemctl stop '
alias status='systemctl status '
alias ff='exec firefox && exit 0'
alias excuse='fortune bofh-excuses'
|
x
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | #
# ~/.bashrc.d/colors
#
# Font attributes
export reset="$(tput sgr0)" bold="$(tput bold)" dim="$(tput dim)" blink="$(tput blink)" \
underline="$(tput smul)" end_underline="$(tput rmul)" reverse="$(tput rev)" \
hidden="$(tput invis)"
# Font colors
export black="$(tput setaf 0)" red="$(tput setaf 1)" green="$(tput setaf 2)" \
yellow="$(tput setaf 3)" blue="$(tput setaf 4)" magenta="$(tput setaf 5)" \
cyan="$(tput setaf 6)" white="$(tput setaf 7)" default="$(tput setaf 9)"
# Font background colors
export bg_black="$(tput setab 0)" bg_red="$(tput setab 1)" bg_green="$(tput setab 2)" \
bg_yellow="$(tput setab 3)" bg_blue="$(tput setab 4)" bg_magenta="$(tput setab 5)" \
bg_cyan="$(tput setab 6)" bg_white="$(tput setab 7)" bg_default="$(tput setab 9)"
|
x
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 | #
# ~/.bashrc.d/functions
#
# Create a new alias
mkalias() {
echo "alias $@" >> ${HOME}/.bashrc.d/aliases
alias $@
}
# Remove an alias
rmalias() {
unalias $1 && sed -i "/alias $1\=/d" ~./bashrc.d/aliases
}
# Color man pages
man() {
env \
LESS_TERMCAP_mb=$(printf "${bold}${red}") \
LESS_TERMCAP_md=$(printf "${bold}${red}") \
LESS_TERMCAP_me=$(printf "${reset}") \
LESS_TERMCAP_se=$(printf "${reset}") \
LESS_TERMCAP_so=$(printf "${bold}${bg_blue}${yellow}") \
LESS_TERMCAP_ue=$(printf "${reset}") \
LESS_TERMCAP_us=$(printf "${bold}${green}") \
man "$@"
}
## COMPRESSION FUNCTION ##
compress() {
FILE=$1
shift
case $FILE in
*.tar.bz2) tar cjf $FILE $* ;;
*.tar.gz) tar czf $FILE $* ;;
*.tgz) tar czf $FILE $* ;;
*.zip) zip $FILE $* ;;
*.rar) rar $FILE $* ;;
*) echo "Filetype not recognized" ;;
esac
}
## EXTRACT FUNCTION ##
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
}
## DICTIONARY FUNCTIONS ##
dwordnet () { curl dict://dict.org/d:${1}:wn; }
dacron () { curl dict://dict.org/d:${1}:vera; }
djargon () { curl dict://dict.org/d:${1}:jargon; }
dfoldoc () { curl dict://dict.org/d:${1}:foldoc; }
dthesaurus () { curl dict://dict.org/d:${1}:moby-thes; }
dtranslate () {
PS3="${blue}Select the dictionary: ${reset}"
local _options="deu-eng eng-deu deu-fra fra-deu deu-ita ita-deu deu-nld nld-deu deu-por por-deu tur-deu lat-deu jpn-deu afr-deu gla-deu exit"
select i in $_options; do
if [ $i == "exit" ]; then
return
else
printf "${blue}Enter the word to translate: ${reset}"
read w
curl dict://dict.org/d:${w}:fd-${i}
fi
done
}
|
x
1 2 3 4 5 6 7 | #
# ~/.bashrc.d/lscolors
#
LS_COLORS='no=00:fi=00:di=01;34:ln=01;36:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:su=37;41:sg=30;43:tw=30;42:ow=34;42:st=37;44:ex=01;32:*.tar=01;31:*.tgz=01;31:*.svgz=01;31:*.arj=01;31:*.taz=01;31:*.lzh=01;31:*.lzma=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.dz=01;31:*.gz=01;31:*.bz2=01;31:*.bz=01;31:*.tbz2=01;31:*.tz=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.rar=01;31:*.ace=01;31:*.zoo=01;31:*.cpio=01;31:*.7z=01;31:*.rz=01;31:*.jpg=01;35:*.jpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.svg=01; 35:*.mng=01;35:*.pcx=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.m2v=01;35:*.mkv=01;35:*.ogm=01;35:*.mp4=01;35:*.m4v=01;35:*.mp4v=01;35:*.vob=01;35:*.qt=01;35:*.nuv=01;35:*.wmv=01;35:*.asf=01;35:*.rm=01;35:*.rmvb=01;35:*.flc=01;35:*.avi=01;35:*.fli=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.yuv=01;35:*.aac=00;36:*.au=00;36:*.flac=00;36:*.mid=00;36:*.midi=00;36:*.mka=00;36:*.mp3=00;36:*.mpc=00;36:*.ogg=00;36:*.ra=00;36:*.wav=00;36:'
export LS_COLORS
|
x
1 2 3 4 5 6 7 8 9 | #
# ~/.bashrc.d/misc
#
# Add to history instead of overriding it
shopt -s histappend
# Window size sanity check
shopt -s checkwinsize
|
x
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 | #
# ~/.bashrc.d/prompt
#
_PROMPT() {
local EXIT_STATUS="$?"
# Other variables
local _time12h="\T" _time12a="\@" _time24h="\t" _time24s="\A" _cwd_short="\W" \
_cwd_full="\w" _new_line="\n" _jobcount="\j"
# Set variables for PS1 string
local _br1="\[${bold}${black}\][\[${reset}\]" _br2="\[${bold}${black}\]]\[${reset}\]" \
_div1="\[${bold}${black}\] » \[${reset}\]" _div2="\[${bold}${black}\]╺─╸\[${reset}\]" \
_line1="\[${red}\]┌─╼\[${reset}\]" _line2="\[${red}\]└────╼\[${reset}\]" \
_sep="\[${reset}\]@" _title_sep="@"
local _cwd="${_br1}${_cwd_short}${_br2}" _title_cwd="[${_cwd_short}]" \
_time="${_br1}${_time24h}${_br2}"
# Exit status string
[ $EXIT_STATUS != 0 ] && local _errmsg="${_br1}\[${bold}${red}\]${EXIT_STATUS}${_br2}"
# User
if (( UID == 0 )); then
local _user="\[${red}\]root\[${reset}\]" _title_user="root"
else
local _user="\[${green}\]\u\[${reset}\]" _title_user="\u"
fi
# Hostname
if [[ $SSH_TTY ]]; then
local _host="\[${blue}\]\h" _title_ssh="ssh://" _title_host="\h"
else
local _host="\[${yellow}\]\h" _title_ssh="" _title_host="\h"
fi
# Jobs
if [[ $(echo -n `jobs | egrep -c \[[:digit:]+\]`) != 0 ]]; then
local _jobs="${_br1}\[${bold}${green}\]${_jobcount}${_br2}"
else
local _jobs=""
fi
# Get the Git shell
local _git_branch="$(__git_ps1 "%s")"
if [[ ${_git_branch} != "" ]] && [[ ${PWD} =~ "/.git" ]]; then
# CWD is inside a .git directory
local _git="${_br1}\[${red}\]${_git_branch}${_br2}" _title_git="[${_git_branch}]"
elif [[ ${_git_branch} != "" ]]; then
local _title_git="[${_git_branch}]"
if [[ -z $(git status -s) ]] && ( [[ ${_git_branch} == "master" ]] || [[ ${_git_branch} == "master=" ]] ); then
# CWD is inside an unmodified master branch
local _git="${_br1}\[${green}\]${_git_branch}${_br2}"
elif [[ -z $(git status -s) ]]; then
# CWD is inside an unmodified branch
local _git="${_br1}\[${yellow}\]${_git_branch}${_br2}"
else
# CWD is inside a modified branch
local _git="${_br1}\[${red}\]${_git_branch}${_br2}"
fi
else
# Not inside a Git branch
local _git="" _title_git=""
fi
# Set title in xterm/rxvt
case $TERM in
xterm*|rxvt*)
local _title="\[\e]2;${_title_ssh}${_title_user}${_title_sep}${_title_host} ${_title_cwd} ${_title_git}\007\]" ;;
*)
local _title="" ;;
esac
# Set PS1
PS1="${_title}${_new_line}${_line1} ${_time}${_div1}${_user}${_sep}${_host} ${_div2} ${_errmsg}${_jobs}${_cwd}${_git}${_new_line}${_line2} "
export PS2='continue >'
export PS4='+$BASH_SOURCE[$LINENO]: '
}
# Prompt
PROMPT_COMMAND=_PROMPT
|
x
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | #
# ~/.bashrc.d/variables
#
# Set environment variables
export VISUAL=/usr/bin/vim
export EDITOR=/usr/bin/vim
export PAGER=/usr/bin/most
if [ -n "$DISPLAY" ]; then
export BROWSER=/usr/bin/firefox
else
export BROWSER=/usr/bin/w3m
fi
# Don't put duplicate lines or lines starting with space in the history.
export HISTCONTROL=ignoreboth
# History lenght
export HISTSIZE=1000
export HISTFILESIZE=2000
# Set options for Git prompt
export GIT_PS1_SHOWDIRTYSTATE=yes
export GIT_PS1_SHOWSTASHSTATE=yes
export GIT_PS1_SHOWUNTRACKEDFILES=true
export GIT_PS1_SHOWUPSTREAM=yes
|
x
Notes
Got my inspiration from “Classy Touch” (http://dotshare.it/dots/579/), “Compact Prompt” (http://dotshare.it/dots/468/), “Classy” (http://dotshare.it/dots/32/) and some others.