2016-08-25 19:45:59 +03:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								# If not running interactively, don't do anything
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								[[ $- != *i* ]] && return
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2016-08-26 19:43:59 +03:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								# {{{ settings
							 | 
						
					
						
							
								
									
										
										
										
											2016-08-25 19:45:59 +03:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								HISTSIZE=1000
							 | 
						
					
						
							
								
									
										
										
										
											2018-07-10 03:25:36 +03:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								HISTFILE="$HOME/.bash_history.$UID"
							 | 
						
					
						
							
								
									
										
										
										
											2016-10-20 15:44:56 +03:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								HISTCONTROL=ignoredups
							 | 
						
					
						
							
								
									
										
										
										
											2018-07-11 13:26:42 +03:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								shopt -s histappend checkwinsize autocd
							 | 
						
					
						
							
								
									
										
										
										
											2016-08-25 19:45:59 +03:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2021-04-08 21:06:34 +03:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								export LESS='-R'
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								export PAGER='less'
							 | 
						
					
						
							
								
									
										
										
										
											2017-06-05 19:50:20 +03:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								export EDITOR='vim'
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								export TIME_STYLE='long-iso'
							 | 
						
					
						
							
								
									
										
										
										
											2018-07-10 03:25:36 +03:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								export SSH_AUTH_SOCK="$HOME/.ssh/ssh_auth_sock"
							 | 
						
					
						
							
								
									
										
										
										
											2016-08-27 02:32:55 +03:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								# }}}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								# {{{ prompt
							 | 
						
					
						
							
								
									
										
										
										
											2019-02-07 15:21:37 +03:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								prompt_command() {
							 | 
						
					
						
							
								
									
										
										
										
											2018-07-10 03:25:36 +03:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    case "$TERM" in
							 | 
						
					
						
							
								
									
										
										
										
											2021-03-03 00:10:38 +03:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        (screen*) printf '\ek%s\e\\' "${HOSTNAME%%.*}";;
							 | 
						
					
						
							
								
									
										
										
										
											2019-02-07 16:21:49 +03:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        (*)       printf '\e]0;%s\a' "${HOSTNAME%%.*}";;
							 | 
						
					
						
							
								
									
										
										
										
											2016-09-09 14:21:23 +03:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    esac
							 | 
						
					
						
							
								
									
										
										
										
											2016-08-30 19:08:56 +03:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							
								
									
										
										
										
											2019-10-30 18:52:11 +03:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								((UID)) && ps_clr=4 || ps_clr=1
							 | 
						
					
						
							
								
									
										
										
										
											2021-02-10 21:52:02 +03:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								# just a colored version of [ $USER $HOSTNAME:$CWD ]
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								printf -v PS1 '\\[\\e[0m\\][ \\[\\e[3%sm\\]\\u\\[\\e[0m\\] \\h:\\[\\e[32m\\w\\[\\e[0m\\] ]\n\\$ ' $ps_clr
							 | 
						
					
						
							
								
									
										
										
										
											2019-02-07 15:21:37 +03:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								unset ps_clr
							 | 
						
					
						
							
								
									
										
										
										
											2016-08-30 19:08:56 +03:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								PROMPT_COMMAND=prompt_command
							 | 
						
					
						
							
								
									
										
										
										
											2016-08-27 02:32:55 +03:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								# }}}
							 | 
						
					
						
							
								
									
										
										
										
											2018-07-10 03:25:36 +03:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								# {{{ aliases
							 | 
						
					
						
							
								
									
										
										
										
											2020-01-28 16:39:04 +03:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								beep()    { printf "\007"; }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								fixterm() { printf "c"; }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								diff()   { command diff --color "$@"; }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								less()   { command less -R "$@"; }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								tailf()  { command less -R +F "$@"; }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								rgrep()  { command grep --exclude-dir=\.git -R "$@"; }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								whence() { command -v "$@"; }
							 | 
						
					
						
							
								
									
										
										
										
											2018-07-10 03:25:36 +03:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								# ls
							 | 
						
					
						
							
								
									
										
										
										
											2020-01-28 16:39:04 +03:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								ls() { command ls --color=auto --group-directories-first "$@"; }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								ll() { command ls -lha --color=auto --group-directories-first "$@"; }
							 | 
						
					
						
							
								
									
										
										
										
											2018-07-10 03:25:36 +03:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								# git
							 | 
						
					
						
							
								
									
										
										
										
											2020-01-28 16:39:04 +03:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								gci()   { command git commit "$@"; }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								gsl()   { command git stash list "$@"; }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								gss()   { command git status -sbu "$@"; }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								gup()   { command git pull "$@"; }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								groot() { cd "$(command git rev-parse --show-cdup)" || return 1; }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								ggrep() { command git grep "$@"; }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								gsi()   { command tig status; }
							 | 
						
					
						
							
								
									
										
										
										
											2018-07-10 03:25:36 +03:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								# tmux
							 | 
						
					
						
							
								
									
										
										
										
											2020-01-28 16:39:04 +03:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								tmux()  { command tmux -2 "$@"; }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								atmux() { tmux attach; }
							 | 
						
					
						
							
								
									
										
										
										
											2018-07-10 03:25:36 +03:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2021-04-08 21:06:34 +03:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								# sudo
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								sush()  { command sudo -Es; }
							 | 
						
					
						
							
								
									
										
										
										
											2020-01-28 16:39:04 +03:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-10 19:37:26 +03:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								# vim
							 | 
						
					
						
							
								
									
										
										
										
											2021-05-06 15:03:25 +03:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								vi()  { command vim "$@"; }
							 | 
						
					
						
							
								
									
										
										
										
											2020-02-10 19:37:26 +03:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2018-07-10 03:25:36 +03:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								# }}}
							 | 
						
					
						
							
								
									
										
										
										
											2016-12-13 02:08:47 +03:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								# {{{ plugins and traps
							 | 
						
					
						
							
								
									
										
										
										
											2018-07-10 03:25:36 +03:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								# bash-completion
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								completion_path='/usr/share/bash-completion/bash_completion'
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								[[ -r "$completion_path" ]] && source "$completion_path"
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								# grc
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								if [[ -x $(command -v grc) ]]; then
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    cmds=(\
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        cc configure cvs df diff dig gcc gmake id ip last lsof make mount \
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        mtr netstat ping ping6 ps tcpdump traceroute traceroute6 \
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    )
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    for cmd in "${cmds[@]}"; do
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        alias $cmd="command grc -es --colour=auto $cmd"
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    done
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    unset cmds cmd
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								fi
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								# some cool git stuff
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								gdiff() { /usr/bin/git diff --color "$@"; }
							 | 
						
					
						
							
								
									
										
										
										
											2019-02-07 15:21:37 +03:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								gdf() {
							 | 
						
					
						
							
								
									
										
										
										
											2018-07-10 03:25:36 +03:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    local difftool
							 | 
						
					
						
							
								
									
										
										
										
											2018-07-18 16:12:41 +03:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    if difftool=$(command -v sdiff-so-fancy); then
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        gdiff "$@" | "$difftool" | less --tabs=4 -RSFX
							 | 
						
					
						
							
								
									
										
										
										
											2018-07-10 03:25:36 +03:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    else
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        gdiff "$@"
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    fi
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							
								
									
										
										
										
											2016-08-25 19:45:59 +03:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								# we want to see exit code on error (it also has to be the last entry here)
							 | 
						
					
						
							
								
									
										
										
										
											2019-11-22 19:32:06 +03:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								trap_msg='\e[31m>>\e[0m exit \e[31m%s\e[0m\n'
							 | 
						
					
						
							
								
									
										
										
										
											2019-02-07 15:21:37 +03:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								trap 'printf "$trap_msg" "$?" >&2' ERR
							 | 
						
					
						
							
								
									
										
										
										
											2016-08-25 19:45:59 +03:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								# }}}
							 |