-
Notifications
You must be signed in to change notification settings - Fork 0
/
install_aliases.sh
executable file
·62 lines (53 loc) · 2.18 KB
/
install_aliases.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
#!/usr/bin/sh
echo "\e[33m# simple shell script to add the my-commands alias to the alias file\e[0m"
echo '# ~/.bashrc.d/ dir will be created if it does not exist and system is Fedora style'
echo '# ~/.bashrc.d/aliases file will be created if it does not exist and system is Fedora style'
echo '# ~/.bash_aliases file will be created if it does not exist and system is Ubuntu style'
string_fzf="alias my-fzf-commands='chosen_command=\$(cat ~/.dotfiles/my-commands/commands_list.txt | fzf ) ; eval \$chosen_command '"
string_sel="alias my-sel-commands='PS3=\"Select command: \"; mapfile -t items < ~/.dotfiles/my-commands/commands_list.txt; select item in \"\${items[@]}\"; do eval \$item;break; done'"
fedora_style(){
# for Fedora
echo '. mkdir -p ~/.bashrc.d'
mkdir -p ~/.bashrc.d
echo '. touch -a ~/.bashrc.d/aliases'
touch -a ~/.bashrc.d/aliases
if grep -Fq "my-commands" ~/.bashrc.d/aliases
then
echo '. my-commands tag found in file ~/.bashrc.d/aliases; good, do nothing'
else
# the key part, adding the alias to the aliases file
echo '! alias not found in file ~/.bashrc.d/aliases; write it in'
echo '#### my-commands ####' >> ~/.bashrc.d/aliases
echo "$string_fzf" >> ~/.bashrc.d/aliases
echo "$string_sel" >> ~/.bashrc.d/aliases
fi
}
ubuntu_style(){
# for Ubuntu style bash_aliases
echo '. touch -a ~/.bash_aliases'
touch -a ~/.bash_aliases
if grep -Fq "my-commands" ~/.bash_aliases
then
echo '. my-commands tag found in file ~/.bash_aliases; good, do nothing'
else
# the key part, adding the alias to the aliases file
echo '! alias not found in file ~/.bash_aliases; write it in'
echo '#### my-commands ####' >> ~/.bash_aliases
echo "$string_fzf" >> ~/.bash_aliases
echo "$string_sel" >> ~/.bash_aliases
fi
}
main_function() {
if grep -Fq '~/.bash_aliases' ~/.bashrc
then
echo '. .bashrc calls on .bash_aliases: this system is Ubuntu style'
ubuntu_style
fi
if grep -Fq '~/.bashrc.d/aliases' ~/.bashrc
then
echo '. .bashrc calls on .bashrc.d/aliases: this system is Fedora style'
fedora_style
fi
}
#run the main function
main_function