-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlcf.sh
executable file
·139 lines (116 loc) · 2.75 KB
/
lcf.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
#!/bin/bash
# Installs the config files in the repository to the system
# WARNING this overwrites the current files in the repository.
show_help(){
echo "Avalible options.."
echo "To install use option -i and to update the files in the repo use option -u."
echo "-b Install bash configs"
echo "-n Install nvim configs"
echo "-h Show help information"
}
update=false
install=false
install_bash=false
install_nvim=false
update_bash=false
update_nvim=false
# Parse cl option
while getopts "iubnh" opt; do
case ${opt} in
u)
update=true ;;
i)
install=true ;;
b)
install_bash=true ;;
n)
install_nvim=true ;;
h) # Show help
show_help ;;
esac
done
install_all_configs()
{
echo "Installing all configs...."
sudo cp -rp ./configs/. ~
echo "Instalation complete."
}
update_all_configs()
{
echo "Updatating all configs in the repo..."
mapfile -t configsLc < <(ls configs/.config)
mapfile -t configsEx < <(ls ~/.config)
echo "Local configs"
for conf in "${configsLc[@]}"; do
cp -r ~/.config/$conf .config/.config
done
}
# If no options provided, exit the progra
if [[ $# -eq 0 ]]; then
echo "Do you want to install all configs?"
read -p "Press enter to continue or ^C to cancle..."
install_all_configs
exit 1
elif [[($install == true && $update == true) || ( $install == false && $update == false) ]]; then
echo "You must either provide the -i or -u option, not both of neither."
read -p "Press enter to continue..."
exit 1
fi
# Function to install bash config
install_bash_config()
{
echo "Installing bash config..."
cp .config/bash/.bashrc bash/.bash_aliases ~/
echo "Bash configs installed, please run [source ~./.bashrc] to complete the setup."
}
# Function to install vim config
install_nvim_config()
{
echo "Installing nvim config..."
cp -r .congig/nvim/ ~/.config/
echo "Installation complete."
}
update_bash_config()
{
echo "Updating bash configs... "
cp -r ~/.bashrc ~/.bash_aliases ./.config/bash/
echo "Updating complete."
}
update_nvim_config()
{
echo "Updateing nvim configs..."
cp -r ~/.config/nvim ./.config/
echo "Updating complete."
}
# Main installation function
install_configs()
{
if $install_bash; then
install_bash_config
fi
if $install_nvim; then
install_nvim_config
fi
}
update_configs()
{
echo "Updating configs..."
if $install_bash; then
update_bash_config
fi
if $install_nvim; then
update_nvim_config
fi
}
show_repo_diff()
{
echo "Current changes in the repo so far since last commit."
git diff
}
# Check if we need to install or update and call according funciton
if $install; then
install_configs
else
update_configs
show_repo_diff
fi