-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinstall
executable file
·169 lines (144 loc) · 4.13 KB
/
install
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
#!/bin/bash
set -e
cat <<"EOF"
_ _ __ _ _
| | | | / _(_) |
__| | ___ | |_| |_ _| | ___ ___
/ _` |/ _ \| __| _| | |/ _ \/ __|
| (_| | (_) | |_| | | | | __/\__ \
\__,_|\___/ \__|_| |_|_|\___||___/
by @leonjza
https://github.com/leonjza/dotfiles
EOF
declare -a REQUIRED=( "git" "stow" "curl" )
declare -a OPTIONAL=( "zsh" "nvim" )
declare -a STOWABLES=( "tmux" "zsh" "p10k" )
###
function green() { command echo -e "$(tput setaf 2; tput bold)$*$(tput sgr0)"; }
function red() { command echo -e "$(tput setaf 1)$*$(tput sgr0)"; }
function yellow() { command echo -e "$(tput setaf 3)$*$(tput sgr0)"; }
function fn_exists() { declare -F "$1" > /dev/null; }
OKAY=true
BACKUPDIR=$HOME/.config/dotfile-backups
echo "checking prerequisites..."
echo
# required tools
for c in "${REQUIRED[@]}"
do
if ! command -v $c &> /dev/null
then
OKAY=false
red "$c (required) could not be found"
else
green "$c (required) is available"
fi
done
# optional tools
for c in "${OPTIONAL[@]}"
do
if ! command -v $c &> /dev/null
then
yellow "$c (optional) could not be found"
else
green "$c (optional) is available"
fi
done
if ! $OKAY
then
red "install the required prerequisites first please"
exit 1
fi
function f_usage() {
echo
echo "Usage: $0 <subcommand>"
echo "Subcommands:"
echo " install install software specific configuration"
echo " usage echo this usage information"
echo " stow stow configurations (aka, update symlinks)"
echo " unstow remove symlinks (removing configs)"
}
function f_backup() {
target=$1
mkdir -p $BACKUPDIR
if [[ -f $c ]] # exists
then
if [[ ! -L $c ]] # and is not a symlink
then
yellow "backing up $c to $BACKUPDIR"
mv $c $BACKUPDIR/$(basename $c)
fi
fi
}
# funcs
function f_install() {
echo
read -r -p "happy to continue setup for the installed tools? [y/N] " -n 1
echo
if [[ ! "$REPLY" =~ ^[Yy]$ ]]; then
yellow "doing nothing"
exit 1
fi
# zsh
if command -v zsh &> /dev/null
then
green "installing oh-my-zsh and plugins"
f_backup "$HOME/.zshrc"
# base oh-my-zsh
local temp="$(mktemp)"
curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh -o $temp
RUNZSH='no' sh $temp # https://github.com/robbyrussell/oh-my-zsh/blob/master/tools/install.sh#L24
rm -f $temp
# install zsh-syntax-highlighting
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting
# install zsh-autosuggestions
git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions
# install powerlevel10k
git clone --depth=1 https://github.com/romkatv/powerlevel10k.git ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes/powerlevel10k
else
yellow "skipping oh-my-zsh"
fi
# neovim
if command -v nvim &> /dev/null
then
green "installing neovim config, astrovim"
git clone --depth 1 https://github.com/AstroNvim/AstroNvim ~/.config/nvim
rm -rf ~/.config/nvim/.git
else
yellow "skipping neovim config"
fi
# other targets that dont have anything to download but need backups
f_backup "$HOME/.tmux.conf"
green "installation done. use the stow subcommand to link configurations."
}
function f_stow() {
echo "stowing configurations"
for s in "${STOWABLES[@]}"
do
stow -t $HOME/ --restow $s
done
}
function f_unstow() {
yellow "performing unstow"
echo "your old configs should be at $BACKUPDIR"
for s in "${STOWABLES[@]}"
do
stow -t $HOME/ --delete $s
done
}
# parse commandline arguments
subcommand=$1
case $subcommand in
"" | "usage" | "-h" | "--help")
f_usage
;;
*)
shift
if ! fn_exists f_${subcommand}
then
echo "error: '$subcommand' is not a known command."
echo " see: $0 usage"
exit 1
fi
f_${subcommand} $@
;;
esac