-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathalias
More file actions
275 lines (256 loc) · 7.41 KB
/
alias
File metadata and controls
275 lines (256 loc) · 7.41 KB
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
if [ "$(uname -s)" = "Darwin" ]; then
is_mac=true
fi
if command -v nvim >/dev/null 2>&1 ; then
has_nvim=true
fi
# colorize stuff
if test -t 1 && which tput >/dev/null 2>&1; then
ncolors=$(tput colors)
if test -n "$ncolors" && test $ncolors -ge 8; then
bold_color=$(tput bold)
normal_color=$(tput setaf 2)
warn_color=$(tput setaf 3)
error_color=$(tput setaf 1)
reset_color=$(tput sgr0)
fi
fi
echo_bad() {
echo "$error_color$bold_color$@$reset_color"
}
echo_good() {
echo "$normal_color$bold_color$@$reset_color"
}
# Some aliases. Most are from the arch wiki
## Modified commands ## {{{ alias diff='colordiff' # requires colordiff package
alias grep='grep --color=auto'
alias more='less'
alias df='df -h'
alias du='du -c -h'
alias mkdir='mkdir -p -v'
alias nano='nano -w'
alias ping='ping -c 5'
alias dmesg='dmesg -HL'
if [ "$has_nvim" = "true" ]; then
alias vi='nvim'
alias vim='nvim'
else
alias vi='vim'
fi
alias qpdfview='qpdfview --unique'
alias mutt='cd ~/Downloads && mutt'
alias reboot='systemctl reboot'
alias shutdown='systemctl poweroff'
alias suspend='i3lock && systemctl suspend'
alias chromium='chromium -incognito'
alias pdflatex='pdflatex --shell-escape'
# }}}
## New commands ## {{{
alias da='date "+%A, %B %d, %Y [%T]"'
alias hist='history | grep' # requires an argument
alias openports='ss --all --numeric --processes --ipv4 --ipv6'
alias pgg='ps -Af | grep' # requires an argument
alias ..='cd ..'
alias stop='kill -TSTP'
alias setclip='xclip -selection c'
alias getclip='xclip -selection clipboard -o'
# }}}
## Custom commands ## {{{
alias screendim='xbacklight -set 5'
alias screenbright='xbacklight -set 100'
alias torrent='transmission-cli'
alias pacmirr='sudo reflector --verbose --latest 25 --sort rate --save /etc/pacman.d/mirrorlist'
alias g++20='g++ -march=native -O3 -W -Wall -Wextra -pedantic -std=c++20'
alias gcc11='gcc -march=native -O3 -W -Wall -Wextra -Wshadow -pedantic -std=c11'
alias androidmount='jmtpfs ~/mtp'
alias androidumount='fusermount -u ~/mtp'
alias usbmount='mount /mnt/usb'
alias usbumount='umount /mnt/usb'
if [ "$is_mac" = "true" ]; then
alias i3lock='/System/Library/CoreServices/"Menu Extras"/User.menu/Contents/Resources/CGSession -suspend'
else
alias i3lock='i3lock -c 000000'
fi
alias gp='/usr/bin/gp'
# This is needed for incompatibilites regarding string splitting.
args() {
echo $*
}
# Backup stuff.
user_name=gajjanag
imp_dirs=".ssh \
.dotfiles \
.textfiles \
.keys \
temp \
books \
courses \
dev \
ganesh \
research \
doc \
temp_priv"
extra_dirs="videos \
music \
photos \
projects \
Dropbox \
wallpapers"
src_loc="/home/$user_name"
backup_loc=$user_name@athena.dialup.mit.edu:Private
storage_loc1="/home/$user_name/storage_wd1"
storage_loc2="/home/$user_name/storage_wd2"
local_dirs=""
full_local_dirs=""
remote_dirs=""
storage_dirs=""
for dir in $(args $imp_dirs); do
local_dirs="${local_dirs} $src_loc/$dir"
remote_dirs="${remote_dirs} $backup_loc/$dir"
storage1_dirs="${storage1_dirs} $storage_loc1/$dir"
storage2_dirs="${storage2_dirs} $storage_loc2/$dir"
full_local_dirs="${full_local_dirs} $src_loc/$dir"
done
for dir in $(args $extra_dirs); do
full_local_dirs="${full_local_dirs} $src_loc/$dir"
storage1_dirs="${storage1_dirs} $storage_loc1/$dir"
storage2_dirs="${storage2_dirs} $storage_loc2/$dir"
done
is_mounted() {
findmnt -rno SOURCE,TARGET "$1" >/dev/null #path or device
}
storagesync() {
if is_mounted ${storage_loc1}; then
d1=0
else
mount $storage_loc1
d1=$?
fi
if is_mounted ${storage_loc2}; then
d2=0
else
mount $storage_loc2
d2=$?
fi
if [ $d1 -ne 0 ] && [ $d2 -ne 0 ]; then
echo_bad "External drives not mounted, exiting!"
return 1
else
if [ $d1 -eq 0 ]; then
echo_good "External drive 1 mounted, syncing to it"
prev_alias=$(alias rsync)
unalias rsync
eval "rsync -av --delete $full_local_dirs $storage_loc1"
alias "$prev_alias"
echo_good "Unmounting drive 1"
umount $storage_loc1
fi
if [ $d2 -eq 0 ]; then
echo_good "External drive 2 mounted, syncing to it"
prev_alias=$(alias rsync)
unalias rsync
eval "rsync -av --delete $full_local_dirs $storage_loc2"
alias "$prev_alias"
echo_good "Unmounting drive 2"
umount $storage_loc2
fi
echo_good "Trying to mount external drive 1"
mount $storage_loc1
d1=$?
echo_good "Trying to mount external drive 2"
mount $storage_loc2
d2=$?
if [ $d1 -eq 0 ] && [ $d2 -eq 0 ]; then
echo_good "External drive 1,2 both mounted, syncing from 2 to 1"
prev_alias=$(alias rsync)
unalias rsync
eval "rsync -av --delete --exclude='lost+found' $storage_loc2/ $storage_loc1"
alias "$prev_alias"
fi
if [ $d1 -eq 0 ]; then
echo_good "Unmounting drive 1"
umount $storage_loc1
fi
if [ $d2 -eq 0 ]; then
echo_good "Unmounting drive 2"
umount $storage_loc2
fi
fi
}
storagerestore() {
mount $storage_loc1
d1=$?
if [ $d1 -ne 0 ]; then
echo_bad "External drive 1 not mounted, exiting!"
return 1
else
prev_alias=$(alias rsync)
unalias rsync
eval "rsync -av --delete $storage1_dirs $src_loc"
alias "$prev_alias"
umount $storage_loc1
fi
}
# audio playback from command line
play() {
mpv --no-resume-playback --no-video --ytdl-format=bestaudio ytdl://ytsearch10:"$@"
}
# set-volume helper
setvol() {
ponymix --sink set-volume "$@"
}
project() {
screen_res=$(xdpyinfo | awk '/dimensions/{print $2}')
xrandr --output HDMI1 --auto --scale-from $screen_res
}
# plaintext web browsing given URL
# useful for e.g reading articles behind paywall such as Wall Street Journal
# I got this from https://news.ycombinator.com/item?id=14389986
web_view() {
curl "$@" | sed -n '/./{/<title/,/<\/title/p;/<p>/,/<\/p>/p;}' | vim -
}
# merge pdf's using ghostscript
pdfmerge() {
/usr/bin/gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -dPDFSETTINGS=/prepress -sOutputFile=$@
}
# Privileged access
if [ $UID -ne 0 ]; then
alias sudo='sudo '
alias scat='sudo cat'
alias svim='sudoedit'
alias root='sudo -s'
alias reboot='sudo systemctl reboot'
alias poweroff='sudo systemctl poweroff'
alias update='sudo pacmatic -Syu'
alias netctl='sudo netctl'
fi
## ls ## {{{
if [ "$is_mac" = "true" ]; then
alias ls='ls -G'
else
alias ls='ls -hF --color=auto'
fi
alias lr='ls -R' # recursive ls
alias ll='ls -l'
alias lA='ls -A'
alias la='ll -A'
alias lx='ll -BX' # sort by extension
alias lz='ll -rS' # sort by size
alias lt='ll -rt' # sort by date
alias lm='la | more'
# }}}
## git ##
alias gr='cd $(git rev-parse --show-toplevel)'
alias gus='git submodule foreach git pull origin master'
## Safety features ## {{{
alias chown='chown --preserve-root'
alias chmod='chmod --preserve-root'
alias chgrp='chgrp --preserve-root'
alias cls=' echo -ne "\033c"' # clear screen for real (it does not work in Terminology)
# }}}
## Make shell error tolerant ## {{{
alias :q=' exit'
alias :Q=' exit'
alias :x=' exit'
alias cd..='cd ..'
# }}}