-
Notifications
You must be signed in to change notification settings - Fork 5
/
install.zsh
executable file
·70 lines (64 loc) · 2.04 KB
/
install.zsh
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
#!/usr/bin/env zsh
set -e
setopt EXTENDED_GLOB
# Find the current directory
local DOTFILES_DIR="$(cd $(dirname ${BASH_SOURCE[0]-$0}) && pwd)"
# Default values for configurable variables
local XDG_CONFIG_HOME=${XDG_CONFIG_HOME:-$HOME/.config}
local INSTALL_DIR=${INSTALL_DIR:-$HOME}
# Prompt the user
if [ -z ${DOTFILES_NONINTERACTIVE+x} ]; then
echo "Installing dotfiles in $DOTFILES_DIR into $XDG_CONFIG_HOME and $INSTALL_DIR"
echo "You can override these with \$XDG_CONFIG_HOME and \$INSTALL_DIR, respectively"
echo -n "Continue? "
read REPLY
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
echo "Cowardly refusing to link dotfiles"
exit 1
fi
fi
# Install everything that belongs in $XDG_CONFIG_HOME
echo
echo "Linking XDG_CONFIG_HOME configurations..."
local XDG_LINKS=(
"$DOTFILES_DIR/init.lua:$XDG_CONFIG_HOME/nvim/init.lua"
"$DOTFILES_DIR/kitty.conf:$XDG_CONFIG_HOME/kitty/kitty.conf"
"$DOTFILES_DIR/helix:$XDG_CONFIG_HOME"
)
for LINK in $XDG_LINKS; do
local FILE=`echo $LINK | awk -F":" '{print $1}'`
local TARGET=`echo $LINK | awk -F":" '{print $2}'`
if [[ ! -a $TARGET ]]; then
mkdir -p $(dirname $TARGET)
print -P -- " %F{002}Linking file:%f $FILE => $TARGET"
ln -s $FILE $TARGET
else
print -P -- " %F{011}Link already exists:%f $FILE => $TARGET"
fi
done
# Install everything that belongs in $HOME
echo
echo "Linking the dotfiles..."
for FILE in $DOTFILES_DIR/(.??*)(.N); do
local TARGET=$INSTALL_DIR/${FILE:t}
if [[ ! -a $INSTALL_DIR/${FILE:t} ]]; then
print -P -- " %F{002}Linking file:%f $FILE => $TARGET"
ln -s $FILE $INSTALL_DIR/${FILE:t}
else
print -P -- " %F{011}Link already exists:%f $FILE => $TARGET"
fi
done
# Homebrew installation
if [ -z ${DOTFILES_NONINTERACTIVE+x} ] && which brew > /dev/null; then
echo
echo "Homebrew installation detected."
echo "Do you want to install Brewfile contents?"
echo -n "Continue? "
read REPLY
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
echo "Cowardly refusing to install brew packages"
exit 1
else
brew bundle install $DOTFILES_DIR/Brewfile
fi
fi