-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.sh
executable file
·119 lines (104 loc) · 2.83 KB
/
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
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
#!/usr/bin/env bash
set -e -o pipefail
# The absolute path to this directory
DOTFILES_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"
# Dotfiles
dotFiles=$(ls -A "$DOTFILES_DIR/dotfiles")
for f in $dotFiles; do
ln -svfn \
"$DOTFILES_DIR/dotfiles/$f" \
"$HOME/$f"
done
# Now we have a ~/.profile. Source it to update $PATH.
. ~/.profile
# ~/bin
mkdir -p ~/bin
scriptFiles=$(ls -A "$DOTFILES_DIR/bin")
for f in $scriptFiles; do
ln -svfn \
"$DOTFILES_DIR/bin/$f" \
"$HOME/bin/$f"
done
# XDG ~/.config directory
mkdir -p ~/.config
xdgConfigs=$(ls -A "$DOTFILES_DIR/.config")
for f in $xdgConfigs; do
ln -svfn \
"$DOTFILES_DIR/.config/$f" \
"$HOME/.config/$f"
done
# SSH
mkdir -p ~/.ssh
ln -svfn \
"$DOTFILES_DIR/.ssh/config" \
~/.ssh/config
chmod 600 ~/.ssh/config
# Tmux
if [[ ! -d ~/.tmux/plugins/tpm ]]; then
echo "Tmux package manager is not installed. Installing!"
mkdir -p ~/.tmux/plugins
git clone https://github.com/tmux-plugins/tpm ~/.tmux/plugins/tpm
fi
# Pyenv
mkdir -p ~/.pyenv
ln -svf \
"$DOTFILES_DIR/.pyenv/default_packages" \
~/.pyenv/default-packages
# Link the contents of a directory in the dotfiles repo in ~/emacs.
#
# Parameters:
#
# - `dirName`: Name of a directory in the emacs/ directory of this project
#
# Example:
#
# linkEmacs "min-package"
function linkEmacs {
[[ -n "$1" ]] || {
echo "Error: param 1 is required"
return 1
}
dirName=$1
dotfilesEmacsDir="$DOTFILES_DIR/emacs/$dirName"
realEmacsDir=~/emacs/$dirName
# Create ~/emacs/<dirName>
mkdir -p $realEmacsDir
# Create symlinks in $realEmacsDir to every file in $dotfilesEmacsDir
files=$(find $dotfilesEmacsDir -type f -printf "%P\n")
for f in $files; do
# Create the subdirectory for this file if it doesn't exist
mkdir -p $realEmacsDir/$(dirname $f)
# Create symlink to this file in my dotfiles project
ln -svfn \
"$dotfilesEmacsDir/$f" \
"$realEmacsDir/$f"
done
}
# Set up chemacs2, installing it if necessary.
if [[ -d ~/.emacs.d ]]; then
pushd ~/.emacs.d
remote=$(basename $(git remote get-url origin))
if [[ ! $remote == "chemacs2.git" ]]; then
echo "$HOME/.emacs.d exists but it is not chemacs2"
exit 1
fi
echo "Updating chemacs2"
git pull
popd
else
echo "Cloning chemacs2 into $HOME/.emacs.d/"
git clone https://github.com/plexus/chemacs2.git ~/.emacs.d
fi
# Create Emacs config directories
mkdir -p ~/emacs
emacsDirs=$(find ./emacs -maxdepth 1 -type d -printf "%P\n")
for d in $emacsDirs; do
linkEmacs "$d"
done
# Top-level emacs files, shared among emacsen.
emacsFiles=$(find ./emacs -maxdepth 1 -type f -printf "%P\n")
for f in $emacsFiles; do
ln -svfn \
"$DOTFILES_DIR/emacs/$f" \
"$HOME/emacs/$f"
done