-
Notifications
You must be signed in to change notification settings - Fork 1
/
setup_env
executable file
·176 lines (145 loc) · 3.59 KB
/
setup_env
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
#!/bin/bash
ENV_DIR=`pwd`
DST_DIR=${HOME}
OS=`uname`
LOCAL_EXT=".local"
SYMLINK_EXT=".symlink"
function op_if_does_not_exist() {
local op=$1
local msg=$2
local src="${ENV_DIR}/$3"
local dst="${DST_DIR}/$4"
if [ -e $dst ]
then
local symbol="$(tput setaf 1)✗$(tput sgr0)"
else
$op "${src}" "${dst}"
local symbol="$(tput setaf 2)✓$(tput sgr0)"
fi
echo "${symbol} ${msg}: $3"
}
function link_if_does_not_exist() {
op_if_does_not_exist "ln -sf" "Link" $1 $2
}
function link_hidden() {
link_if_does_not_exist "$1" ".$1"
}
function link() {
link_if_does_not_exist "$1" "$1"
}
function copy_if_does_not_exist() {
op_if_does_not_exist "cp -n" "Copy" $1 $2
}
function copy_hidden() {
copy_if_does_not_exist "$1" ".$1"
}
function op_on_topic() {
local op=$1
local ext=$2
local topic=$3
for rc in $(ls $topic/*$ext 2> /dev/null)
do
topicrc=`basename ${rc%$ext}`
$op $rc .${topicrc}
done
}
function copy_locals() {
op_on_topic copy_if_does_not_exist $LOCAL_EXT $1
}
function link_symlinks() {
op_on_topic link_if_does_not_exist $SYMLINK_EXT $1
}
function setup_topic() {
local topic=$1
# link the topic directory
link_hidden $topic
# copy the local templates
copy_locals $topic
# link the local symlinks
link_symlinks $topic
}
function setup_bin() {
mkdir ${DST_DIR}/bin 2> /dev/null
for i in $(ls bin)
do
link bin/$i
done
}
function setup_qt_app() {
local app=$1
# make the qt configuration directory if it does not exist
qt_config_dir=".local/share"
mkdir ${DST_DIR}/$qt_dir 2> /dev/null
link_if_does_not_exist "$app" "$qt_config_dir/$app"
}
function install_app {
local app=$1
if command -v "$app" > /dev/null; then
echo "$app already installed"
elif command -v apt > /dev/null; then
sudo apt-get install "$app"
elif command -v pacman > /dev/null; then
sudo pacman -S "$app"
else
echo "Cannot run install_app, unsupported package manager."
fi
}
function build_app {
local app=$1
local command=$2
if command -v "$app" > /dev/null; then
echo "$app already installed"
else
$command
fi
}
function git_pull_or_clone {
local repo=$1
local dst=$2
if [ -e $dst ]; then
echo "Pulling $repo"
$(cd $dst || git pull)
else
echo "Cloning $repo"
git clone $repo $dst
fi
}
function announce {
local announcement=$1
echo "*******************************************************************"
echo "$announcement"
echo "*******************************************************************"
}
# setup topics
setup_topic bash
setup_topic shell
setup_topic synergy
setup_topic tmux
setup_topic vim
setup_topic nvim
setup_topic git
setup_topic zsh
setup_topic input
setup_topic tmuxinator
[ $OS == "Linux" ] && setup_topic i3
[ $OS == "Linux" ] && setup_topic rofi
[ $OS == "Linux" ] && setup_topic polybar
[ $OS == "Linux" ] && setup_qt_app albert
setup_bin
# install applications with simple setup
install_app git
install_app tmux
install_app zsh
install_app cmake
install_app nodejs
install_app curl
# setup vim application
install_app vim
git_pull_or_clone https://github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim
vim +PlugInstall +qall
# setup fzf application
git_pull_or_clone https://github.com/junegunn/fzf.git ~/.fzf
build_app fzf ~/.fzf/install
# setup tmux application
git_pull_or_clone https://github.com/tmux-plugins/tpm ~/.tmux/plugins/tmp
announce "Remember to start tmux and install plugins \"prefix+I\""