-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path.commonrc
279 lines (257 loc) · 9.25 KB
/
.commonrc
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
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
if [ ! -f ~/.bash_git ]; then
wget --quiet https://raw.githubusercontent.com/inferont/shell-scripts/master/.bash_git -O ~/.bash_git
fi
if [ ! -f ~/.commonrc ]; then
wget --quiet https://raw.githubusercontent.com/inferont/shell-scripts/master/.commonrc -O ~/.commonrc
fi
if [ ! -f ~/.dircolors ]; then
wget --quiet https://raw.githubusercontent.com/inferont/shell-scripts/master/.dircolors -O ~/.dircolors
fi
eval $(dircolors -b ~/.dircolors)
source ~/.bash_git
mkdir -p ~/bin
mkdir -p ~/logs
if [ ! -f ~/bin/branches ]; then
wget --quiet https://raw.githubusercontent.com/inferont/shell-scripts/master/branches -O ~/bin/branches
chmod a+x ~/bin/branches
fi
if [ ! -f ~/.nanorc ]; then
find /usr/share/nano -name '*.nanorc' -printf "include %p\n" > ~/.nanorc
fi
mkdir -p ~/.config/nanorc
if [ ! -f ~/.config/nanorc/apacheconf.nanorc ]; then
cd ~/.config/nanorc
wget --quiet https://raw.githubusercontent.com/scopatz/nanorc/master/apacheconf.nanorc
wget --quiet https://raw.githubusercontent.com/scopatz/nanorc/master/Dockerfile.nanorc
wget --quiet https://raw.githubusercontent.com/scopatz/nanorc/master/csv.nanorc
wget --quiet https://raw.githubusercontent.com/scopatz/nanorc/master/git.nanorc
wget --quiet https://raw.githubusercontent.com/scopatz/nanorc/master/ini.nanorc
wget --quiet https://raw.githubusercontent.com/scopatz/nanorc/master/javascript.nanorc
wget --quiet https://raw.githubusercontent.com/scopatz/nanorc/master/json.nanorc
wget --quiet https://raw.githubusercontent.com/scopatz/nanorc/master/markdown.nanorc
wget --quiet https://raw.githubusercontent.com/scopatz/nanorc/master/nginx.nanorc
wget --quiet https://raw.githubusercontent.com/scopatz/nanorc/master/puppet.nanorc
wget --quiet https://raw.githubusercontent.com/scopatz/nanorc/master/readme.nanorc
wget --quiet https://raw.githubusercontent.com/scopatz/nanorc/master/sql.nanorc
wget --quiet https://raw.githubusercontent.com/scopatz/nanorc/master/yaml.nanorc
find /usr/share/nano ~/.config/nanorc -name '*.nanorc' -printf "include %p\n" > ~/.nanorc
cd ~
fi
export PATH=~/bin:$PATH
LAST_PWD=$(pwd)
LAST_PWD=$(printf %q "$LAST_PWD")
LAST_PWD_TIMES=0
if [ -f ~/logs/long_pwd_log ]; then
mv ~/logs/long_pwd_log ~/logs/long_pwd.log
fi
touch ~/logs/long_pwd.log
## Welcome Message
# Basic info
HOSTNAME=`uname -n`
# System load
MEMORY1=`free -t -g | grep Total | awk '{print $3" GB";}'`
MEMORY2=`free -t -g | grep "Mem" | awk '{print $2" GB";}'`
echo "Hostname: $HOSTNAME"
echo "Memory used: $MEMORY1 / $MEMORY2"
uptime
## Use: "regenerate"
## Allows you to change the random color assigned to the host in the prompt on initial login
## The generate function will be called when you first log in
function generate() {
echo "export PHP_IDE_CONFIG='serverName="$HOSTNAME"'" > ~/.bashrc_this_server
echo "export HOST_COLOR=\"\\[\\033[1;"$(( ( RANDOM % 15 ) + 31 ))"m\\]\"" >> ~/.bashrc_this_server
}
function regenerate() {
generate
source ~/.commonrc
}
if [ ! -f ~/.bashrc_this_server ]; then
generate
fi
source ~/.bashrc_this_server
## Use: "key {ssh filename suffix}"
## Allows you to switch between ssh keys easily
function key() {
if [ ! -f ~/.ssh/id_rsa_old ]; then
cp ~/.ssh/id_rsa ~/.ssh/id_rsa_old
cp ~/.ssh/id_rsa.pub ~/.ssh/id_rsa_old.pub
fi
cp ~/.ssh/id_rsa.$1 ~/.ssh/id_rsa
cp ~/.ssh/id_rsa.pub.$1 ~/.ssh/id_rsa.pub
}
## Use: "authorize {user}@{servername}"
## Allows easy installation of authorization keys on remote server
function authorize() {
if [ ! -f ~/.ssh/id_rsa.pub ]; then
ssh-keygen
fi
cat ~/.ssh/id_rsa.pub | /usr/bin/ssh $@ 'cat >> ~/.ssh/authorized_keys'
}
alias passwordless="authorize"
alias keyless="authorize"
## Use: Up/Down arrows for searching history with current input
unset HISTFILESIZE
HISTSIZE=9999999
HISTFILESIZE=99999999
shopt -s histappend
set -o emacs
bind '"\e[A": history-search-backward'
bind '"\e[B": history-search-forward'
bind '"\eOA": history-search-backward'
bind '"\eOB": history-search-forward'
APPLICATION_ENV="testing"
export GIT_PS1_SHOWDIRTYSTATE=true
export GIT_PS1_SHOWUNTRACKEDFILES=true
## General aliases
alias ls="ls --color=auto --group-directories-first -p"
alias ll="ls -lh --time-style=long-iso"
alias la="ll -a"
alias calculator="bc --quiet"
alias bc="bc --quiet"
function calc() {
echo $@ | bc --quiet
}
alias cd..="cd .."
alias ..="cd .."
alias ...="cd ../.."
alias ....="cd ../../.."
alias .....="cd ../../../.."
alias ......="cd ../../../../.."
alias .......="cd ../../../../../.."
alias ........="cd ../../../../../../.."
alias .........="cd ../../../../../../../.."
unset PROMPT_COMMAND
PROMPT_COMMAND="${PROMPT_COMMAND:-:} ; history -a"
function prompt_right() {
EPOCHTIME=`date +%s`
HEXTIME=`printf "%X" $EPOCHTIME`
#SPH=`echo "${HEXTIME:0:4}" "${HEXTIME:4:8}"`
echo -e "\033[0;0m$HEXTIME\033[0m"
}
function prompt_left() {
if [ $(id -u) -eq 0 ]; then
echo -e "\e[1;31m##\033[0m \u@$HOST_COLOR\h\[\033[0m\]:\w$(__git_ps1)"
else
echo -e "\u@$HOST_COLOR\h\[\033[0m\]:\w$(__git_ps1)"
fi
}
function print_pre_prompt() {
compensate=9
export WINDOW_TITLE="\033]0;${USER}@${HOSTNAME} ($(cat /proc/loadavg | cut -d' ' -f1-3))\a"
CURRENT_PWD=$(pwd)
CURRENT_PWD=$(printf %q "$CURRENT_PWD")
## Keep track of last working directory. Write path to long_pwd.log if in directory for longer than 15 commands
if [[ "$CURRENT_PWD" == "$LAST_PWD" ]]; then
LAST_PWD_TIMES=$((LAST_PWD_TIMES+1))
else
LAST_PWD_TIMES=0
fi
if [ $LAST_PWD_TIMES -gt 15 ]; then
LAST_PWD_TIMES=0
TO_WRITE="${LAST_PWD/~/~}"
if ! grep -q $TO_WRITE ~/logs/long_pwd.log; then
echo $TO_WRITE >> ~/logs/long_pwd.log
fi
fi
LAST_PWD=$(pwd)
LAST_PWD=$(printf %q "$LAST_PWD")
if [ $(id -u) -eq 0 ]; then
PS1=$WINDOW_TITLE$(printf "\n%*s\r%s\n\! # " "$(($(tput cols)+${compensate}))" "$(prompt_right)" "$(prompt_left)")
else
PS1=$WINDOW_TITLE$(printf "\n%*s\r%s\n\! \$ " "$(($(tput cols)+${compensate}))" "$(prompt_right)" "$(prompt_left)")
fi
}
PROMPT_COMMAND="${PROMPT_COMMAND:-:} ; print_pre_prompt"
## Use "compress {folder name}"
## Creates a gz/bz2 file with the contents of the folder
function compress() {
if hash bzip2 2>/dev/null; then
tar -cvjf $1.tar.bz2 $1
else
tar -cvzf $1.tar.gz $1
fi
}
## Use "gitc {Git branch name}"
## Checks out master, pulls, checks out a branch, and pulls again
function gitc() {
git checkout master
git pull
git checkout $1
git pull
}
## Use "gitcc {Git branch name}"
## Checks out master, pulls, checks out a branch, pulls, and runs composer install
function gitcc() {
gitc $1
composer install
}
## Use "gitbc"
## Lists all current branches, prompts for selection, checks out selection
function gitbc() {
git checkout master
git pull
echo "---------------------------------------------------------------------"
~/bin/branches | head -n 20 | nl
echo "---------------------------------------------------------------------"
echo "Make selection:"
read selection
git checkout $(~/bin/branches | tail -n +$selection | head -n 1 | awk '{print $1}')
git pull
}
## Use "gitbcc"
## Lists all current branches, prompts for selection, checks out selection, run composer
function gitbcc() {
gitbc $1
composer install
}
alias bcc=gitbcc
## Use: "c" or "cd"
## Lists common PWDs that have been used in long_pwd.log with an option to choose one
function c() {
if [ -z $1 ]; then
cat ~/logs/long_pwd.log | sort -u | nl
echo "---------------------------------------------------------------------"
echo "Make selection:"
read selection
eval cd $(cat ~/logs/long_pwd.log | sort -u | tail -n +$selection | head -n 1)
else
cd "$@"
fi
}
alias cd=c
## Use: "unixdate {1565894972 - seconds since epoch}"
## Allows easy conversion of unix time to human readable date/time
function unixdate() {
if [ $# -eq 0 ]; then
date --date="@$(history | tail -n 1 | cut -d" " -f6)";
else
date --date="@$@";
fi
}
alias unixtime=unixdate
## Use: "hextime {5DF26DDA - seconds since epoch in hex}"
## Allows easy conversion of hexadecimal unix time to human readable date/time
function hextime() {
DECTIME=`printf "%d" 0x$@`
CONVERTED=`unixtime $DECTIME`
echo $DECTIME $CONVERTED
}
## Use: "- {history item}"
## Shows a human readable date/time for any history item
function -() {
unixtime $(history | grep " $1 " | cut -d" " -f6)
}
## Use: "_ {search history}"
## Example: "_ ssh" returns all servers logged into
## Allows to search history for any command and prompt to repeat it
function _() {
export HISTSEARCH="$@"
cat ~/.bash_history ~/logs/bash_history/* | grep -av "^\#" | grep -a "^$HISTSEARCH" | sort -u | nl
echo "---------------------------------------------------------------------"
echo "Make selection: "
read selection
eval $(cat ~/.bash_history ~/logs/bash_history/* | grep -av "^\#" | grep -a "^$HISTSEARCH" | sort -u | tail -n +$selection | head -n 1)
}
## Export information needed for xdebug in shell on PHPStorm
CURRENT_IP=`echo $SSH_CLIENT | awk '{ print $1}'`
export XDEBUG_CONFIG="idekey=PHPSTORM_CLI remote_enable=1 remote_host=$CURRENT_IP remote_port=9000 remote_handler=dbgp remote_mode=req"