aboutsummaryrefslogtreecommitdiffstats
path: root/bash/.bashrc
blob: e8a61fcda8e35def76b265e3bff0e83e338d742c (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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
#
# ~/.bashrc
#

# If not running interactively, don't do anything
[[ $- != *i* ]] && return

export PS1='[\d][\t]\u on \h\n\w $ '

export PATH="$PATH:$HOME/.local/bin"
export PATH="$PATH:$HOME/.local/usr/bin"
export PATH="$PATH:$HOME/.local/usr/local/bin"

alias :q="exit"

case "$(uname)" in
	Linux)
		alias ls="ls --color=auto"
		usr="/usr"
		;;
	FreeBSD)
		alias ls="ls -G"
		usr="/usr/local"
		;;
	*)
		alias ls="ls --color=auto"
		usr="/usr"
		;;
esac

man() {
	env LESS_TERMCAP_mb=$'\E[01;31m' \
	LESS_TERMCAP_md=$'\E[01;38;5;74m' \
	LESS_TERMCAP_me=$'\E[0m' \
	LESS_TERMCAP_se=$'\E[0m' \
	LESS_TERMCAP_so=$'\E[38;5;246m' \
	LESS_TERMCAP_ue=$'\E[0m' \
	LESS_TERMCAP_us=$'\E[04;38;5;146m' \
	man "$@"
}

exists() {
	hash $@ 2> /dev/null
}

is_function() {
	function=$(type $@ 2> /dev/null | awk '/is a function/ { print "1" }')
	if [ -n "$function" ]; then
		return 0
	else
		return 1
	fi
}

is_alias() {
	alias=$(type $1 2> /dev/null | awk '/is aliased to/ { print "1" }')
	if [ -n "$alias" ]; then
		return 0
	else
		return 1
	fi
}

if exists sudo; then
	sudo() {
		# Allow functions and aliasses to be executed with sudo
		if is_function $1 2> /dev/null; then
			tmpfile="/tmp/$(date +%s).sh"

			echo "#!$usr/bin/bash" > "$tmpfile"
			echo "usr=$usr" >> "$tmpfile"
			type $1 | grep -v "is a function" >> "$tmpfile"
			echo "$@" >> "$tmpfile"

			chmod +x "$tmpfile"

			$usr/bin/sudo "$tmpfile"

			rm "$tmpfile"
		elif is_alias $1 2> /dev/null; then
			alias=$(type $1 2> /dev/null |
				sed -n "s/^$1\ is\ aliased\ to\ \`\(.*\)'$/\1/p")

			$usr/bin/sudo "$alias"
		else
			$usr/bin/sudo "$@"
		fi
	}
fi

if exists complete && exists sudo; then
	complete -cf sudo
fi

if exists mpv; then
	alias jblive='mpv rtmp://videocdn-us.geocdn.scaleengine.net/jblive/live/jblive.stream'
elif exists vlc; then
	alias jblive='vlc rtmp://videocdn-us.geocdn.scaleengine.net/jblive/live/jblive.stream'
fi

if exists vim; then
	export EDITOR="vim"
	vim() {
		if [[ -z $@ ]]; then
			$usr/bin/vim
		elif [[ -d $@ ]]; then
			dir=$(pwd)
			cd $@ && $usr/bin/vim && cd $dir
		else
			$usr/bin/vim $@
		fi
	}
fi

if exists go; then
	export GOPATH="$HOME/programming/go"
	export PATH="$PATH:$GOPATH/bin"
fi

if exists gem; then
	export GEM_HOME="$(ruby -e 'print Gem.user_dir')/bin"
	export PATH="$PATH:$GEM_HOME"
fi

if exists ezjail-admin && exists sudo; then
	jl() {
		sudo ezjail-admin $1 $2\.tomvanderlee.com
	}
fi

if exists pfctl && exists sudo; then
	showbanned ()
	{
		for table in "fail2ban" "permaban"; do
			banned=$(sudo pfctl -t $table -T show 2> /dev/null)

			if [ -z "$banned" ]; then
				nrBanned="0"
			else
				nrBanned=$(echo "$banned" | wc -l | awk '{ print $1 }')
			fi

			echo -e "$table ($nrBanned)\n$banned"
		done
	}
fi

if (exists pacman && ! exists pacaur) && exists sudo; then
	alias pacaur="sudo pacman"
fi

if exists less; then
	export PAGER="less"
fi

if exists pip; then
	pip() {
		if [[ "$1" == "upgrade" ]] || [[ "$1" == "update" ]]; then
			outdated=$($usr/bin/pip list --outdated | awk '{ print $1 }')
			for pkg in $outdated; do
				$usr/bin/pip install $pkg --upgrade
			done

			if [[ -z "$outdated" ]]; then
				echo "No updates found"
			fi
		else
			$usr/bin/pip $@
		fi
	}
fi

if exists liquidprompt; then
	source liquidprompt
fi

if exists archey3; then
	archey3
elif exists screenfetch; then
	screenfetch
fi

# vim: set ts=8 sw=8 tw=0 noet :