-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmakesymlinks.sh
More file actions
executable file
·177 lines (155 loc) · 4.95 KB
/
makesymlinks.sh
File metadata and controls
executable file
·177 lines (155 loc) · 4.95 KB
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
177
#!/usr/bin/env bash
set -e # Exit immediately if a command exits with a non-zero status
############################
# .make.sh
# This script creates symlinks from the home directory to any desired dotfiles in ~/dotfiles
dir=~/dotfiles # dotfiles directory
olddir=~/dotfiles_old # old dotfiles backup directory
files=("bash_aliases" "vimrc" "vim" "tmux.conf" "gitignore_global" "inputrc" "zsh_aliases" "pdbrc" "pdbrc.py") # list of files/folders to symlink in homedir
# Add shell specific rc file
case "$(detect_shell)" in
zsh)
files+=("zshrc")
;;
*)
files+=("bashrc")
;;
esac
detect_shell() {
basename "$SHELL"
}
detect_os() {
local os="$(uname)"
case "$os" in
Darwin)
echo "macos"
;;
Linux)
if [ -f /etc/os-release ]; then
. /etc/os-release
case "$ID" in
ubuntu)
echo "ubuntu"
;;
rhel|centos)
echo "redhat"
;;
*)
echo "linux"
;;
esac
else
echo "linux"
fi
;;
*)
echo "unknown"
;;
esac
}
os_specific_setup() {
local os_name
os_name=$(detect_os)
case "$os_name" in
macos)
echo "macOS detected"
if command -v brew >/dev/null 2>&1; then
xargs brew install < "$dir/brew_requirements.txt"
fi
;;
ubuntu)
echo "Ubuntu detected"
if command -v apt-get >/dev/null 2>&1; then
sudo apt-get update
fi
;;
redhat)
echo "RedHat detected"
if command -v yum >/dev/null 2>&1; then
sudo yum update -y
fi
;;
*)
echo "OS $os_name not specifically handled"
;;
esac
}
create_backup() {
# Create dotfiles_old in homedir
echo -n "Creating $olddir for backup of any existing dotfiles in ~ ..."
mkdir -p "$olddir" && echo "done" || echo "failed"
}
move_and_link_files() {
for file in "${files[@]}"; do # Use "${files[@]}" to loop over array items
local src="${HOME}/.${file}"
local dest="$dir/$file"
if [ -e "$src" ]; then
echo "Moving existing dotfile $file from ~ to $olddir"
mv "$src" "$olddir"
fi
echo "Creating symlink to $file in home directory."
ln -s "$dest" "$src"
done
if [ ! -d ~/.config/htop/ ]; then
echo "making .htoprc"
mkdir -p ~/.config/htop
fi
if [ ! -d ~/.config/nvim/ ]; then
echo "Creating symlink for nvim config"
ln -s "$dir/nvim" ~/.config/nvim
fi
}
setup_git() {
echo "Setting git settings"
git config --global core.excludesfile ~/.gitignore_global
git config --global diff.tool nvimdiff
git config --global difftool.prompt false
git config --global merge.tool vimdiff
git config --global merge.tool nvimdiff
git config --global mergetool.keepBackup false
git config --global init.defaultBranch main
git config --global rerere.enabled true
git config --global rerere.autoUpdate true
git config --global branch.sort -committerdate
git config --global alias.blame "blame -w -C -C -C"
git config --global alias.graph "log --oneline --branches --graph --decorate"
git config --global alias.fpush "push --force-with-lease"
# Additional configurations
git config --global color.ui auto
git config --global core.editor nvim
git config --global pull.rebase false
git config --global fetch.prune true
git config --global alias.st "status"
git config --global alias.co "checkout"
git config --global alias.ci "commit"
git config --global alias.br "branch"
git config --global alias.lg "log --oneline --graph --decorate --all"
git config --global alias.unstage "reset HEAD --"
git config --global alias.last "log -1 HEAD"
git config --global alias.visual "!gitk"
git config --global push.default simple
}
setup_new_files() {
ln -s $dir/htoprc ~/.config/htop/htoprc
# Create a directory for vim temporary files
echo "making vim_tmp dir"
mkdir -p ~/.vim_tmp
# Set the global .gitignore script
echo "Setting up ipython evn"
if [ ! -d ~/.ipython/profile_default/ ]; then
echo "making .ipython dir"
mkdir -p ~/.ipython/profile_default/startup/
fi
ln -s $dir/ipython/profile_default/ipython_config.py ~/.ipython/profile_default/ipython_config.py
ln -s $dir/ipython/profile_default/startup/ipython_startup.py ~/.ipython/profile_default/startup/ipython_startup.py
}
main() {
create_backup
cd ~ || exit
move_and_link_files
cd ~ || exit
setup_new_files
setup_git
os_specific_setup
}
main "$@"