summaryrefslogtreecommitdiffstats
path: root/bashrc
blob: 38860148ceb88980df3f0af9bbd0e718cd1e4d8b (plain)
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#!/bin/bash
#
# .bashrc for non-login shells
#
# Set environment variables
export EDITOR='vim'
export LESS='R'
export CVS_RSH='ssh'
export GPG_TTY=$(tty)
# Set a browser
if [ -x /usr/bin/firefox -a "x$DISPLAY" != "x" ]; then
	export BROWSER='/usr/bin/firefox'
elif [ -x /usr/bin/links ]; then
	export BROWSER='/usr/bin/links'
fi

# Various shell options
#case-insensitive filename globbing
shopt -s nocaseglob
#ignore small errors in cd
shopt -s cdspell
#no duplicates in history
export HISTCONTROL=erasedups:ignorespace
export HISTSIZE=5000

# Enable bash completion in interactive shells
if [ -z "$BASH_COMPLETION" -a -f /etc/bash_completion ]; then
	. /etc/bash_completion
fi

# Custom Prompt Setup
bash_prompt() {
	local RED="\[\e[1;31m\]"
	local GREEN="\[\e[0;32m\]"
	local YELLOW="\[\e[0;33m\]"
	local BLUE="\[\e[1;34m\]"
	local PURPLE="\[\e[0;35m\]"
	local CYAN="\[\e[1;36m\]"
	local NONE="\[\e[0;0m\]"

	if [ "$TERM" != "linux" ]; then
		local TITLEBAR="\[\e]0;\w\a\]"
	else
		local TITLEBAR=""
	fi

	# use a different color for the host if we are SSH'ed
	if [ "x$SSH_TTY" != "x" ]; then
		local ATHOST="$NONE@$CYAN"
	else
		local ATHOST="$NONE@$BLUE"
	fi

	# if git is installed and git bash completion exists, show current branch
	if [ -n "$(type -p git)" -a "$(type -t __git_ps1)" = "function" ]; then
		local GITPS1="$PURPLE"'$(__git_ps1)'
	else
		local GITPS1=''
	fi

	export PS1="$TITLEBAR\n$RED\u$ATHOST\h $GREEN\w$GITPS1$NONE\n\$ "
}
bash_prompt; unset -f bash_prompt

# pacman aliases- don't bother defining if pacman doesn't exist
if [ -x /usr/bin/pacman ]; then
	alias pac='pacman'
	alias pacQ='pacman -Q'
	alias pacQs='pacman -Qs'
	alias pacQi='pacman -Qi'
	alias pacQm='pacman -Qm'
	alias pacS='sudo pacman -S'
	alias pacSy='sudo pacman -Sy'
	alias pacSu='sudo pacman -Su'
	alias pacSyu='sudo pacman -Syu'
	alias pacSs='/usr/bin/pacsearch'
	alias pacSi='pacman -Si'
	alias pacU='sudo pacman -U'
	alias pacR='sudo pacman -R'
	alias pacRc='sudo pacman -Rc'
	alias pacRs='sudo pacman -Rs'
	alias pacO='sudo pacman-optimize'

	# helpful makepkg shortcuts
	alias makepkgclean='rm -rf src/ pkg/ *~'
fi

# sanitize - set file/directory owner and permissions to normal values (644/755)
# Usage: sanitize <file>
sanitize() {
	chmod -R u=rwX,go=rX "$@"
	chown -R ${USER}.users "$@"
}

# psfind - shortcut for grepping a process name
# Usage: psfind <process name>
psfind() {
	ps -ef | egrep "PID|$@"
}

# rmbackups - remove all *~ files recursively in directory
rmbackups() {
	find -iname '*~' -exec rm -v {} \;
}

# Useful aliases
alias ls='ls --color=auto'
alias ll='ls -lh'
alias la='ls -A'
alias lla='ls -lAh'
alias lr='ls -R'
alias c='clear'
alias r='reset'

# Common misspellings
alias pdw='pwd'
alias mroe='more'
alias csv='cvs'
alias snv='svn'
alias gti='git'

# source the local config
[ -f ~/.bashrclocal ] && source ~/.bashrclocal