-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.bashrc
140 lines (116 loc) · 3.05 KB
/
.bashrc
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
# bash rc
# If not running interactively, don't do anything
[ -z "$PS1" ] && return
# Function to run upon exit of shell.
function _exit()
{
printf "${BRed}Au revoir, monsieur${NC}\n"
}
trap _exit EXIT
#-----------------
# Command prompt look and feel
#-----------------
if [ $TERM == "xterm-256color" ]; then
colour=true
fi
# Normal Colors
Black='\e[0;30m' # Black
Red='\e[0;31m' # Red
Green='\e[0;32m' # Green
Yellow='\e[0;33m' # Yellow
Blue='\e[0;34m' # Blue
Purple='\e[0;35m' # Purple
Cyan='\e[0;36m' # Cyan
White='\e[0;37m' # White
# Bold
BBlack='\e[1;30m' # Black
BRed='\e[1;31m' # Red
BGreen='\e[1;32m' # Green
BYellow='\e[1;33m' # Yellow
BBlue='\e[1;34m' # Blue
BPurple='\e[1;35m' # Purple
BCyan='\e[1;36m' # Cyan
BWhite='\e[1;37m' # White
# Background
On_Black='\e[40m' # Black
On_Red='\e[41m' # Red
On_Green='\e[42m' # Green
On_Yellow='\e[43m' # Yellow
On_Blue='\e[44m' # Blue
On_Purple='\e[45m' # Purple
On_Cyan='\e[46m' # Cyan
On_White='\e[47m' # White
NC="\e[m" # Color Reset
ALERT=${BWhite}${On_Red} # Bold White on red background
function git_branch() {
git branch 2>/dev/null | grep '^*' | colrm 1 2
}
#function error_smiley() {
# if [ $? == 0 ]; then
# printf ":D \xe2\x9c\x93\x0a";
# else
# printf ":O \xe2\x9c\x97\x0a";
# fi
#}
function error_smiley() {
if [ $? == 0 ]; then
printf "\xe2\x9c\x93\x0a";
else
printf "\xe2\x9c\x97\x0a";
fi
}
function error_smiley_colour() {
local ret_code=$?
if [ $ret_code == 0 ]; then
printf "${BGreen}";
else
printf "${ALERT}";
fi
return $ret_code
}
trap _exit EXIT
if [ "$colour" == true ]; then
export PS1="\[\$(error_smiley_colour)\]\$(error_smiley)\[${NC}\] \u@\h: \[${Green}\]\W\[${NC}\] \[${Purple}\]\$(git_branch)\[${NC}\]\$ "
else
export PS1="\$(error_smiley) \u@\h: \W \$(git_branch)\$ "
fi
#------------------
# Aliases
#------------------
# System aliases
alias ls='ls -G'
alias ll='ls -la'
alias grep='grep --color=auto'
# Functions for burning disks to storage cards
alias lsbd="diskutil list"
umbd() { diskutil umountDisk "/dev/$1"; }
burn() { pv $1 | sudo dd of="/dev/r$2" bs="1m" ;}
function is_installed()
{
command -v $1 > /dev/null 2>&1
local ret_val=$?
local err_str="Command $1 is not in PATH"
if [ $ret_val -ne 0 ]; then
if [ "$colour" == true ]; then
err_str=${ALERT}$err_str${NC}
fi
printf "$err_str\n" 1>&2
fi
return $ret_val
}
function ct() {
local ctags_dir="${HOME}/ctags"
is_installed "ctags"
local ctags_exists=$?
if [ $ctags_exists -eq 0 ]; then
ctags_cmd="ctags -R -f \"$ctags_dir\" --exclude=.git --exclude=*.js \"$1\""
printf "${BWhite}Executing: ${On_Green}$ctags_cmd${NC}\n"
eval "$ctags_cmd"
fi
}
# History related settings
shopt -s histappend
HISTCONTROL=ignoreboth
# Bash window
shopt -qs checkwinsize
shopt -qs hostcomplete