-
Notifications
You must be signed in to change notification settings - Fork 0
/
bashrc
216 lines (171 loc) · 3.87 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
# env vars
export CLANGCXX=clang++
export CLANGC=clang
# Bash Functions
function c {
cd $1
}
mkcd(){
mkdir -p $1
cd $1
}
vims(){
vim $1
source $1
}
usrc(){
curr_dir=`pwd`
if [ "$1" != "" ]; then
curr_dir=$1
fi
source ~/.bashrc
}
gitcd(){
if [ $# -eq 2 ]
then
git clone $1 $2
cd $2
else
git clone $1
to_cd=`echo $1 | sed 's/\//\n/g' | awk END{print} | sed 's/\./\n/g' | head -1`
cd $to_cd
fi
}
title(){
temp=`python3 -c "print('$1'.title())"`
echo $temp | xclip -selection clipboard
}
small(){
temp=`python3 -c "print('$1'.lower())"`
echo $temp | xclip -selection clipboard
}
cpfile(){
cat $1 | xclip -selection clipboard
}
download-length(){
length_bytes=`curl -sI $1| grep -i Content-Length | awk '{print $2}'`
python3 -c "print('{} MB'.format(round($length_bytes/1024/1024,1)))"
}
ntimes(){
if [ $# -le 1 ]
then
echo "error: Not enough arguments"
echo "usage: ntimes command times"
fi
for ((c=0; c<$2; c++))
do
$1
done
}
up(){
ntimes "cd .." $1
}
netcheck(){
ping 1.1.1.1
}
copyout(){
$1 &> /tmp/pk_temp
cpfile /tmp/pk_temp
rm /tmp/pk_temp
}
cpcmd(){
echo $1 | xclip -selection clipboard
}
cpp_ast_dump(){
CLANGCXX -Xclang -ast-dump -fsyntax-only $1
}
getLatest(){
result=(`ls -t $1`)
echo $1/$result
}
git_size(){
user=`echo $1 | sed 's/\// /g' | awk '{print $(NF-1)}'`
repo=`echo $1 | sed 's/\//\n/g' | awk END{print} | sed 's/\./\n/g' | head -1`
result=`curl -s https://api.github.com/repos/$user/$repo | grep -Po "\"size\": \K([\d]*)"`
python3 -c "print($result / 1024, 'MB')"
}
bash_map(){
job=$1
files=$2
echo $files
}
# adds to the path to LD_LIBRARY_PATH env variable
add_libpath(){
export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:$1
}
mount_at(){
this=$1
at=$2
sudo mkdir -p $2
sudo mount $1 $2
}
unmount(){
sudo umount $1
}
hedwig() {
$BOS/howler.py $BOS/configs/regular_config.yaml "$@"
}
regress() {
echo -e "$1\n $2" | python3 -c "a = float(input()); b = float(input()); print(((a - b) / a) * 100);"
}
function pretty_csv {
column -t -s, -n "$@" | less -F -S -X -K
}
function ff {
find . -name $1
}
# tmux shortcuts
function ta {
tmux attach -t $1
}
function tn {
dir=`basename $(pwd)`
if [ "$1" != "" ]; then
dir=$1
fi
tmux rename-window $dir
}
function tl {
tmux ls
}
function tmr {
export $(tmux show-environment | grep "^PATH")
}
function trs {
tmux rename-session $1
}
function dwn {
cd ~/Downloads
}
# tmux shortcuts end
if [ -d "$HOME/.vscode-server/bin" ]; then
export PATH="${HOME}/.vscode-server/bin/$(ls -t1 ${HOME}/.vscode-server/bin | head -n 1)/bin:${PATH}"
fi
if [ -d "/run/user/$(id -u)/vscode-ipc-*" ]; then
export VSCODE_IPC_HOOK_CLI="$(ls -t1 /run/user/$(id -u)/vscode-ipc-* | head -n 1)"
fi
#export VSCODE_IPC_HOOK_CLI="$(ls -t1 /run/user/$(id -u)/vscode-ipc-* | head -n 1)"
# Tell tmux to set these variables for new windows/panes.
# Remove if you don't use tmux
tmux has-session &> /dev/null
if [ $? == 0 ]
then
tmux setenv PATH "$PATH"
tmux setenv VSCODE_IPC_HOOK_CLI "$VSCODE_IPC_HOOK_CLI"
fi
# Aliases
alias open=xdg-open
alias icode="code-insiders" # vscode insider version
alias mount_softwares="mount_at /dev/sda10 /media/pradeep/Softwares"
alias mount_movies="mount_at /dev/sda7 /media/pradeep/Movies"
alias mount_wormhole="mount_at /dev/sda6 /media/pradeep/Wormhole"
alias mount_my_stuff="mount_at /dev/sda9 /media/pradeep/My_Stuff"
alias unmount_softwares="unmount /media/pradeep/Softwares"
alias unmount_movies="unmount /media/pradeep/Movies"
alias unmount_wormhole="unmount /media/pradeep/Wormhole"
alias unmount_my_stuff="unmount /media/pradeep/My_Stuff"
alias tf="tail -f"
# Sourcing other files
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" > /dev/null 2>&1 && pwd)"
source $DIR/llvmrc
source $DIR/git_utils.sh