-
Notifications
You must be signed in to change notification settings - Fork 0
/
aliasesjose.sh
executable file
·405 lines (385 loc) · 15.1 KB
/
aliasesjose.sh
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
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
#!/bin/bash
#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#
# SCRIPT: aliasesjose.sh
# USAGE: ./aliasesjose.sh
# PURPOSE: Shell script that adds 'cd(..'s), 'updatef' and 'cleanf', 'updateff', 'extract', faster folder navigation,
# 'mariadb' start/stop/status commands in .bash_aliases file, git commands gta gtm gtp gtl, and gtCreate
# system commands suspend hibernate. sudos instead of sudo -s. extract commands, counting lines of types of file, etc...
# TITLE: aliasesjose.sh
# AUTHOR: Jose Gracia
# VERSION: 1.1.0
# NOTES: If none of the aliases works to check that in your ~/.bashrc you have a line like: .~/.bash_aliases which is surrounded by an if.
# If this is not in your Linux distribution add it yourself.
# BASH_VERSION: GNU bash, 5.0.0-17-generic #18-Ubuntu SMP Tue Jun 4 15:34:08 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux
# LICENSE: GNU General Public License v3.0
# GITHUB: https://github.com/Josee9988/
# MAIL: [email protected]
#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#
# shellcheck disable=SC1090 disable=1117
bold=$(echo -en "\e[1m")
normal=$(echo -en "\e[0m")
underline=$(echo -en "\e[4m")
purple=$(echo -en "\e[35m")
blink=$(echo -en "\e[5m")
red=$(echo -en "\e[31m")
line='. ~/.bash_aliases'
lineSearch='if [ -f ~/.bash_aliases ]; then'
file=~/.bashrc
fileAlias=~/.bash_aliases
echo "We will create aliases in your ${blink}${purple}$fileAlias${normal} file."
echo ""
echo "#!/bin/bash" >>$fileAlias
echo "### Jose's bashrc modification ###" >>$fileAlias
echo "${red}${bold}updatef${normal} and ${red}${bold}cleanf${normal} aliases, updates and upgrades your system and cleans it."
read -p "Do you wish to install ${red}${bold}updatef and cleanf${normal} aliases? [Yy/Nn]" yn
case $yn in
[Yy]*)
## ADDING UPDATEF, CLEANF AND UPDATEFF ##
{
echo ""
echo "#updatef and cleanf must be executed as 'Superuser$'"
echo "#updatef Will check for updates for normal software installed and also for your distribution and after all"
echo "#cleanf will clean trash that you don't really need and will check if any installation has gone through any error."
echo "alias updatef='echo "Downloading software" && echo "" && apt-get update && echo "Updating distribution" && echo "" && apt dist-upgrade && echo "" && echo "Upgrading software" && echo "" && apt-get upgrade'"
echo "alias cleanf='echo "Cleaning trash..." && rm -rf /tmp/* && echo "" && apt-get autoclean && echo "" && echo "Removing and checking failed installations" && echo "" && apt-get autoremove && apt-get clean && apt-get check && apt install -f'"
echo ""
echo "# For all the update and upgrades and after that cleans your system. Updatef + cleanf all in one command"
echo "alias updateff='updatef && cleanf'"
} >>$fileAlias
;;
[Nn]*) echo "Not installing ${bold}updatef cleanf${normal}" ;;
*) echo "Please answer yes or no. Your installation now will continue not installing ${bold}updatef cleanf${normal}" ;;
esac
echo ""
## ADDING ..'s ##
echo "This file includes ${red}${bold}cd${normal} commands which makes going back from folders much faster."
echo "Example: ${red}...${normal} now equals to cd ../../../ (you can write from ${red}two${normal} dots to ${red}five${normal} dots)"
read -p "Do you wish to install ${red}${bold}cd${normal} aliases? [Yy/Nn]" yn
case $yn in
[Yy]*)
{
echo ""
echo "## Get rid of command not found ##"
echo "alias cd..='cd ..'"
echo ""
echo "## A quick way to move backwards from the current directory ##"
echo "alias ..='cd ..'"
echo "alias ...='cd ../../'"
echo "alias ....='cd ../../../'"
echo "alias .....='cd ../../../../'"
echo ""
} >>$fileAlias
;;
[Nn]*) echo "Not installing ${bold}cd${normal}" ;;
*) echo "Please answer yes or no. Your installation now will continue not installing ${bold}cd${normal}" ;;
esac
echo ""
## EXTRACT ##
echo "You can also install '${red}${bold}extract${normal}', which will uncompress almost any kind of compressed file, you will not need to worry what command decompresses which file, just '${red}${bold}extract${normal}'"
read -p "Do you wish to install ${red}${bold}extract${normal} aliases? [Yy/Nn]" yn
case $yn in
[Yy]*)
{
echo "## Use only 'extract' for most of your compressed files. ##"
echo "extract () {"
echo " if [ -f \"\$1\" ] ; then"
echo " case \"\$1\" in"
echo " *.tar.bz2) tar xvjf \"\$1\" ;;"
echo " *.tar.gz) tar xvzf \"\$1\" ;;"
echo " *.bz2) bunzip2 \"\$1\" ;;"
echo " *.rar) unrar x \"\$1\" ;;"
echo " *.gz) gunzip \"\$1\" ;;"
echo " *.tar) tar xvf \"\$1\" ;;"
echo " *.tbz2) tar xvjf \"\$1\" ;;"
echo " *.tgz) tar xvzf \"\$1\" ;;"
echo " *.zip) unzip \"\$1\" ;;"
echo " *.Z) uncompress \"\$1\" ;;"
echo " *.7z) 7z x \"\$1\" ;;"
echo " *) echo \"do not know how to extract \$1 ...\" ;;"
echo " esac "
echo " else "
echo " echo \"\$1 is not a valid file, or has spaces in it!\""
echo " fi "
echo " } "
echo ""
} >>$fileAlias
;;
[Nn]*) echo "Not installing ${bold}extract${normal}" ;;
*) echo "Please answer yes or no. Your installation now will continue not installing ${bold}extract${normal}" ;;
esac
echo ""
## MARIADB.SERVICE ##
echo "We also have 'mariadb' (start/stop/status/use) shortcuts"
read -p "Do you wish to install ${red}${bold}mariadb${normal} aliases? [Yy/Nn]" yn
case $yn in
[Yy]*)
{
echo "# For starting mariadb.service"
echo "alias startmaria='systemctl start mariadb.service'"
echo ""
echo "# For stopping mariadb.service"
echo "alias stopmaria='systemctl stop mariadb.service'"
echo ""
echo "# For knowing the status of mariadb.service"
echo "alias statusmaria='systemctl status mariadb.service'"
echo ""
echo "# Using mysql with root"
echo "alias usemaria='mysql -u root -p'"
} >>$fileAlias
;;
[Nn]*) echo "Not installing ${bold}mariadb${normal}" ;;
*) echo "Please answer yes or no. Your installation now will continue not installing ${bold}mariadb${normal}" ;;
esac
echo ""
## FAST NAVIGATION TO COMMON FOLDERS ##
read -p "Do you wish to install ${red}${bold}easy common folder navigation${normal} aliases? [Yy/Nn]" yn
case $yn in
[Yy]*)
wsl=false
read -p "Are you using ${red}${bold}WSL (Windows Subsystem for Linux)${normal}? [Yy/Nn]" ynwsl
case $ynwsl in
[Yy]*)
userName=$(cmd.exe /c 'echo %USERNAME%')
userName=${userName%$'\r'}
wsl=true
{
echo ""
echo "# do not write again ~/... "
echo "alias cdDesktop='cd /mnt/c/Users/$userName/Desktop'"
echo "alias cdDocuments='cd /mnt/c/Users/$userName/Documents'"
echo ""
echo "alias cddesktop='cd /mnt/c/Users/$userName/Desktop'"
echo "alias cddocuments='cd /mnt/c/Users/$userName/Documents'"
echo ""
echo "#Drives"
echo "alias cdc='cd /mnt/c/'"
echo "alias cdd='cd /mnt/d/'"
echo ""
} >>$fileAlias
;;
[Nn]*) echo "Not installing ${bold}WSL${normal}" ;;
*) echo "Please answer yes or no. Your installation now will continue not installing ${bold}easy common folder navigation${normal}" ;;
esac
if [ "$wsl" = false ]; then
{
echo ""
echo "# do not write again ~/..."
echo "alias cdDesktop='cd ~/Desktop/'"
echo "alias cdDocuments='cd ~/Documents/'"
echo "alias cdDownloads='cd ~/Downloads/'"
echo "alias cdTrash='cd ~/.local/share/Trash/'"
echo ""
echo "alias cddesktop='cd ~/Desktop/'"
echo "alias cddocuments='cd ~/Documents/'"
echo "alias cddownloads='cd ~/Downloads/'"
echo "alias cdtrash='cd ~/.local/share/Trash/'"
echo ""
} >>$fileAlias
fi
;;
[Nn]*) echo "Not installing ${bold}easy common folder navigation${normal}" ;;
*) echo "Please answer yes or no. Your installation now will continue not installing ${bold}easy common folder navigation${normal}" ;;
esac
echo ""
## GIT COMMANDS ##
echo "We also have 'git' (status/add/commit/push/log) shortcuts"
read -p "Do you wish to install ${red}${bold}git${normal} aliases? [Yy/Nn]" yn
case $yn in
[Yy]*)
{
echo "# Git"
echo "alias gts='git status'"
echo "alias gta='git add -A'"
echo "alias gtm='git commit -m '$1''"
echo "alias gtam='git commit -a -m '$1''"
echo "gtt() {"
echo " git tag \"\$1\" -m \"\$2\""
echo "}"
echo "alias gtps='git push'"
echo "alias gps='git push'"
echo "alias gpl='git pull'"
echo "alias gtpl='git pull'"
echo "alias gtp+='git push'"
echo "alias gtp-='git pull'"
echo "alias gtl='git log --color --graph --pretty=format:\"%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset\" --abbrev-commit --'"
echo "alias gtshow='git show'"
echo "alias gtstash='git stash'"
echo "alias gtinit='git init'"
echo ""
echo "#Create GitHub repository from terminal using GitHub API, with curl"
echo "gtCreate () {"
echo " cancel=false"
echo " unset email"
echo " unset name"
echo " unset description"
echo ""
echo " echo \"We will create a GitHub repository from scratch' you will need to have installed 'curl' and 'git'. \""
echo " echo """
echo ""
echo " while [ -z \"\$email\" ]; do"
echo " read -p 'Username or email address of your Github account: ' email"
echo " done"
echo " while [ -z \"\$name\" ]; do"
echo " read -p 'Name of the new repository: ' name"
echo " done"
echo " while [ -z \"\$description\" ]; do"
echo " read -p 'Description of the new repository: ' description"
echo " done"
echo ""
echo ' read -p "Do you wish to make the repository private?[Yy/Nn]: " yn'
echo " case \$yn in"
echo " [Yy]* )"
echo " curl -u \"\$email\" https://api.github.com/user/repos -d '{\"name\":\"'\"\$name\"'\",\"private\":\"true\",\"description\":\"'\"\$description\"'\"}'"
echo " ;;"
echo " [Nn]* )"
echo " curl -u \"\$email\" https://api.github.com/user/repos -d '{\"name\":\"'\"\$name\"'\",\"description\":\"'\"\$description\"'\"}'"
echo " ;;"
echo " * ) echo 'Please answer yes or no. Your installation will be aborted. Try again'"
echo " cancel=true"
echo " ;;"
echo " esac"
echo ""
echo " #creating local folder and initializing git"
echo " if [ \$cancel == false ]; then"
echo " mkdir -pv \"\$name\""
echo " if cd \"\$name\"; then echo \"Ok\"; else echo \"Fail when executing cd \$name\" exit; fi"
echo " git init"
echo " fi"
echo "}"
echo ""
} >>$fileAlias
;;
[Nn]*) echo "Not installing ${bold}git${normal}" ;;
*) echo "Please answer yes or no. Your installation now will continue not installing ${bold}git${normal}" ;;
esac
echo ""
## COUNT LINES ##
echo "${red}clines${normal} counts the lines of a folder and it's subdirectories from selected file types"
read -p "Do you wish to install ${red}${bold}clines${normal} aliases? [Yy/Nn]" yn
case $yn in
[Yy]*)
{
echo "## COUNT LINES ##"
echo "clines () { "
echo " if [ -z \"\$1\" ]; then"
echo " echo 'At least give one file type by parameter'"
echo " elif [ -z \"\$2\" ]; then"
echo " find -type f -name \"*.\$1\" -o -name \"*.\$2\" | xargs wc -l | sort -n"
echo " elif [ -z \"\$3\" ]; then"
echo " find -type f -name \"*.\$1\" -o -name \"*.\$2\" -o -name \"*.\$3\" | xargs wc -l | sort -n"
echo " elif [ -z \"\$4\" ]; then"
echo " find -type f -name \"*.\$1\" -o -name \"*.\$2\" -o -name \"*.\$3\" -o -name \"*.\$4\" | xargs wc -l | sort -n"
echo " elif [ -z \"\$5\" ]; then"
echo " find -type f -name \"*.\$1\" -o -name \"*.\$2\" -o -name \"*.\$3\" -o -name \"*.\$4\" -o -name \"*.\$5\" | xargs wc -l | sort -n"
echo " fi"
echo "} "
echo ""
} >>$fileAlias
;;
[Nn]*) echo "Not installing ${bold}mariadb${normal}" ;;
*) echo "Please answer yes or no. Your installation now will continue not installing ${bold}clines${normal}" ;;
esac
echo ""
## neofetch ##
echo "${red}sysinfo${normal} is an alias for neofetch"
read -p "Do you wish to install ${red}${bold}sysinfo${normal} aliases? [Yy/Nn]" yn
case $yn in
[Yy]*)
{
echo "alias sysinfo='neofetch'"
echo ""
} >>$fileAlias
;;
[Nn]*) echo "Not installing ${bold}sysinfo${normal}" ;;
*) echo "Please answer yes or no. Your installation now will continue not installing ${bold}sysinfo${normal}" ;;
esac
echo ""
## Sensors ##
echo "${red}temp${normal} is an alias for sensors"
read -p "Do you wish to install ${red}${bold}temp${normal} alias? [Yy/Nn]" yn
case $yn in
[Yy]*)
{
echo ""
echo "alias temp='sensors'"
echo "alias tmp='sensors'"
echo ""
} >>$fileAlias
;;
[Nn]*) echo "Not installing ${bold}temp${normal}" ;;
*) echo "Please answer yes or no. Your installation now will continue not installing ${bold}temp${normal}" ;;
esac
echo ""
## Extra Linux ##
echo "A lot of common commands for ${red}linux terminal${normal}"
read -p "Do you wish to install ${red}${bold}extra system linux${normal} aliases? [Yy/Nn]" yn
case $yn in
[Yy]*)
{
echo "#Extra linux commands"
echo "alias mkdir='mkdir -pv'"
echo "alias ping='time ping -c 7'"
echo "alias rm='rm -v'"
echo "alias mv='mv -v'"
echo "alias calc='bc -l'"
echo "alias lsall='ls -all'"
echo "alias rmall='rm -R'"
echo ""
echo "# might fix some sudo + alias problems"
echo "alias sudo='sudo '"
echo ""
echo "# An alias to save some milliseconds of your time :)"
echo "alias sudos='sudo -s'"
echo "alias suspend='systemctl suspend'"
echo "alias hibernate='systemctl hibernate'"
echo "alias defrag='sudo e4defrag -vc '\"\$1\"''"
echo "alias sysinf='cat /etc/os-release'"
echo "alias ram='free -h'"
echo "dusage() {"
echo " du -hsBM \"\$1\"* | sort -n"
echo "}"
echo "alias c='clear'"
echo ""
} >>$fileAlias
;;
[Nn]*) echo "Not installing ${bold}extra system linux${normal}" ;;
*) echo "Please answer yes or no. Your installation now will continue not installing ${bold}extra system linux${normal}" ;;
esac
echo "#End of Jose's bashrc modification" >>$fileAlias
## Checking if .bash_aliases is enabled in .bashrc file ##
if ! grep -q -x -F -e "$lineSearch" <"$file"; then
echo ""
echo "${underline}Enabling${normal} .bash_aliases in your .bashrc file"
{
echo ""
echo "if [ -f ~/.bash_aliases ]; then"
printf '%s\n' "$line"
echo "fi"
echo ""
} >>$file
fi
## Updating bash_aliases, so we can use the aliases without rebooting. ##
echo ""
echo "Updating bashrc's..."
source ~/.bash_aliases
. ~/.bash_aliases
source ~/.bashrc
. ~/.bashrc
## Final echos ##
echo ""
echo "${bold} ____ ____ _ ________"
echo " / __ \/ __ \/ | / / ____/"
echo " / / / / / / / |/ / __/ "
echo " / /_/ / /_/ / /| / /___ "
echo "/_____/\____/_/ |_/_____/ "
echo " "
echo "${normal}"
echo "We recomend you to ${bold}restart${normal} your ${underline}terminal${normal} and ${bold}read${normal} the ${underline}README${normal} file in github to check the aliases."
echo ""
echo "You will find more information and in the ${bold}${purple}README.MD${normal} file :)"
echo ""
echo "${bold}${underline}https://github.com/Josee9988/bashrcralias${normal}"
echo ""
echo "Thanks for using ${underline}Jose's .bash_aliases modification${normal}"
echo ""
exit