-
Notifications
You must be signed in to change notification settings - Fork 0
/
.bashrc
241 lines (211 loc) · 6.55 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
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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
#!/bin/bash
# If not running interactively, don't do anything
[ -z "$PS1" ] && return
# enable programmable completion features (you don't need to enable
# this, if it's already enabled in /etc/bash.bashrc and /etc/profile
# sources /etc/bash.bashrc).
if [ -f /etc/bash_completion ]; then
. /etc/bash_completion
fi
read -p "Press any key to avoid lauching fish" -s -t 3 -n 1 -a no_fish
if [ -z "$no_fish" ]; then
echo -e "\nLaunching fish..."
exec fish
else
echo -e "\nStaying in bash..."
fi
export MYPS='$(echo -n "${PWD/#$HOME/~}" | awk -F "/" '"'"'{
if (length($0) > 14) { if (NF>4) print $1 "/" $2 "/.../" $(NF-1) "/" $NF;
else if (NF>3) print $1 "/" $2 "/.../" $NF;
else print $1 "/.../" $NF; }
else print $0;}'"'"')'
#PS1='\e[32m\!\e[m | \e[33m\u@\h\e[m | \e[31m$(eval "echo ${MYPS}")\e[m \n$ '
if [ -n "$SSH_CLIENT" ]; then
prompt_user_host_color='1;34'
else
prompt_user_host_color='1;31'
fi
if [ -n "$STY" ]; then
#Append (+) to username display when running in a screen session
PS1='\e[32m\!\e[m | \e['$prompt_user_host_color'm\u@\h (+)\e[m | \e[31m$(eval "echo ${MYPS}")\e[m \n$ '
else
PS1='\e[32m\!\e[m | \e['$prompt_user_host_color'm\u@\h\e[m | \e[31m$(eval "echo ${MYPS}")\e[m \n$ '
fi
# Auto-screen invocation. see: http://taint.org/wk/RemoteLoginAutoScreen
# if we're coming from a remote SSH connection, in an interactive session
# then automatically put us into a screen(1) session. Only try once
# -- if $STARTED_SCREEN is set, don't try it again, to avoid looping
# if screen fails for some reason.
if [ "$PS1" != "" -a "${STARTED_SCREEN:-x}" = x -a "${SSH_TTY:-x}" != x ]
then
STARTED_SCREEN=1 ; export STARTED_SCREEN
[ -z "$STY" ] && read && screen -Rd "work" || echo "Screen failed! continuing with normal bash startup"
fi
# [end of auto-screen snippet]
#------------------------------------------
#------WELCOME MESSAGE---------------------
# customize this first message with a message of your choice.
# this will display the username, date, time, a calendar, the amount of users, and the up time.
# Gotta love ASCII art with figlet
function figlet_welcome() {
figlet "Welcome, " $USER;
echo -e ""
echo -ne "Today is "; date
echo -e ""; cal ;
echo "";
}
clear
if [ -e "${HOME}/.local/.bashrc_local" ]; then
source "${HOME}/.local/.bashrc_local"
fi
# Gotta love ASCII art with figlet
type "figlet" > /dev/null 2>&1 && figlet_welcome
type "uptime" > /dev/null 2>&1 && uptime
### FUNCTIONS
# Easy extract
extract () {
if [ -f $1 ] ; then
case $1 in
*.tar.bz2) tar xvjf $1 ;;
*.tar.gz) tar xvzf $1 ;;
*.bz2) bunzip2 $1 ;;
*.rar) rar x $1 ;;
*.gz) gunzip $1 ;;
*.tar) tar xvf $1 ;;
*.tbz2) tar xvjf $1 ;;
*.tgz) tar xvzf $1 ;;
*.zip) unzip $1 ;;
*.Z) uncompress $1 ;;
*.7z) 7z x $1 ;;
*) echo "don't know how to extract '$1'..." ;;
esac
else
echo "'$1' is not a valid file!"
fi
}
# Makes directory then moves into it
function mkcdr {
mkdir -p -v $1
cd $1
}
# Get IP (call with myip)
function myip {
myip=`elinks -dump http://checkip.dyndns.org:8245/`
echo "${myip}"
}
# Custom Exit Routine to ensure sync and trap screen
function exiter {
if [ -n "$STY" ]; then
echo -e "\nDon't exit from screen. Detach with ctrl+a then d"
echo -e "Alternatively, you can force disconnection with: <return>~.\n"
else
if [ $OSTYPE == "cygwin" ]; then
syncuni
$"exit"
else
$"exit"
fi
fi
}
# Sync profiles and aliases
function syncuni {
unison -auto -batch
error_code=$?
if [ "$?" -ne "0" ]; then
echo "Sync failed, run Unison manually to correct."
read -p ""
fi
}
div () # Arguments: dividend and divisor
{
if [ $2 -eq 0 ]; then echo division by 0; exit; fi
local p=12 # precision
local c=${c:-0} # precision counter
local d=. # decimal separator
local r=$(($1/$2)); echo -n $r # result of division
local m=$(($r*$2))
[ $c -eq 0 ] && [ $m -ne $1 ] && echo -n $d
[ $1 -eq $m ] || [ $c -eq $p ] && return
local e=$(($1-$m))
let c=c+1
div $(($e*10)) $2
}
# Add aliases to file
function addalias() {
if [ -z "$3" ] ; then
echo "alias" $1="'"$2"'" >> ~/.bash_aliases
elif [ $1 == "local" ] ; then
echo "alias" $2="'"$3"'" >> ~/.local/.bash_aliases_local
else
echo "Malformed Command. Try Again."
fi
}
# default ping to count of 4
function pinger() {
if [ -z "$2" ] ; then
ping "$1" count 4
elif [ $2 != "x" ] ; then
ping "$1" count "$2"
else
ping "$1"
fi
}
# Create GitHub Repo
function create_github_repo() {
local token="$GITHUB_TOKEN"
local username='WisdomWolf'
if [ -z "$1" ] ; then
echo "Usage: create_github_repo reponame"
else
local repo_name=$1
curl -u "$username:$token" https://api.github.com/user/repos -d '{"name":"'$repo_name'"}'
fi
}
# Create Butbucket Repo
function create_bitbucket_repo() {
local token="$GITHUB_TOKEN"
local username='WisdomWolf'
if [ -z "$1" ] ; then
echo "Usage: create_bitbucket_repo reponame"
else
local repo_name=$1
curl -u "$username:$token" https://api.github.com/user/repos -d '{"name":"'$repo_name'"}'
fi
}
# startbitbucket - creates remote bitbucket repo and adds it as git remote to cwd
function startbitbucket {
if [ -z "$BitBucketUser" ] ; then
echo 'Username?'
read username
else
local username="$BitBucketUser"
fi
if [ -z "$BitBucketPass" ] ; then
echo 'Password?'
read -s password # -s flag hides password text
else
local password="$BitBucketPass"
fi
echo 'Repo name?'
read reponame
curl --user $username:$password https://api.bitbucket.org/1.0/repositories/ --data name=$reponame --data is_private='true'
git remote add origin [email protected]:$username/$reponame.git
git push -u origin --all
git push -u origin --tags
}
# Creates an archive from given directory
mktar() { tar cvf "${1%%/}.tar" "${1%%/}/"; }
mktgz() { tar cvzf "${1%%/}.tar.gz" "${1%%/}/"; }
mktbz() { tar cvjf "${1%%/}.tar.bz2" "${1%%/}/"; }
# don't put duplicate lines in the history. See bash(1) for more options
export HISTFILESIZE=300000 # save 300000 commands
export HISTCONTROL=ignoredups # no duplicate lines in the history.
export HISTSIZE=100000
### Added by the Heroku Toolbelt
export PATH="/usr/local/heroku/bin:$PATH"
### ALIASES
if [ -z "$SHELL_TYPE"]; then
alias exit="exiter"
fi
[ -r ~/.bash_aliases ] && source ~/.bash_aliases
source ~/.xsh