-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathto-setup.sh
75 lines (59 loc) · 1.65 KB
/
to-setup.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
#!/bin/bash
#Author: Leandro Silva (http://grafluxe.com)
#Copyright: 2021 Leandro Silva
#License: MIT
dir_here=$(dirname $0);
dir_install=~/.to;
fi_profile_bash=~/.profile;
fi_profile_zsh=~/.zshrc;
fi_main_here=$dir_here/to.sh;
fi_completion_here=$dir_here/to-completion.sh;
fi_help_here=$dir_here/to-help.txt;
fi_license_here=$dir_here/LICENSE.md;
fi_main=$dir_install/to.sh;
fi_completion=$dir_install/to-completion.sh;
fi_help=$dir_install/to-help.txt;
fi_license=$dir_install/LICENSE.md;
fi_routes=$dir_install/to-routes.txt;
function has_src {
cat $1 | grep "to.sh" | wc -l;
}
# bash
if [[ -f $fi_profile_bash ]]; then
has_src_bash=$(has_src $fi_profile_bash);
else
has_src_bash="0";
fi
if [ $has_src_bash = "0" ]; then
echo "\nif [ -f ~/.to/to.sh ]; then\n source ~/.to/to.sh;\nfi\n" >> $fi_profile_bash;
fi;
# zsh
if [[ -f $fi_profile_zsh ]]; then
has_src_zsh=$(has_src $fi_profile_zsh);
else
has_src_zsh="0";
fi
if [ $has_src_zsh = "0" ]; then
load="\nif [ -f ~/.to/to.sh ]; then\n";
load+=" autoload -Uz compinit && compinit\n";
load+=" autoload -Uz bashcompinit && bashcompinit\n";
load+=" emulate sh -c 'source ~/.to/to.sh'\n";
load+="fi\n";
echo $load >> $fi_profile_zsh;
fi;
if [ ! -d "$dir_install" ]; then
mkdir -p $dir_install;
cp $fi_main_here $fi_main;
cp $fi_completion_here $fi_completion;
cp $fi_help_here $fi_help;
cp $fi_license_here $fi_license;
touch $fi_routes;
msg="Installed Successfully\n";
msg+="-\n";
msg+="To begin, open a new shell tab/window, then run the 'to --help' command.";
else
msg+="Already Installed\n";
msg+="-\n";
msg+="For help, run the 'to --help' command.";
fi;
echo "$msg";