-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsetup
More file actions
executable file
·143 lines (130 loc) · 3.53 KB
/
setup
File metadata and controls
executable file
·143 lines (130 loc) · 3.53 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
#!/bin/sh
FILES="
bashrc
ctags
gdbinit
gitconfig
guile
ipython
inputrc
lambda-term-inputrc
psqlrc
ripgreprc
tmux.conf
vim
vimrc
"
BASEDIR=$(pwd)
MODE="nix"
ASTRONVIM_REPO="${ASTRONVIM_REPO:-git@github.com:sepeth/astronvim_conf.git}"
ASTRONVIM_DIR="${ASTRONVIM_DIR:-$HOME/.config/nvim}"
usage() {
echo "Usage: $0 [--legacy] [--target TARGET]"
echo " --legacy Run the previous symlink/Vundle flow"
echo " --target Home Manager flake target (default: auto-detect)"
}
while [ $# -gt 0 ]; do
case "$1" in
--legacy)
MODE="legacy"
shift
;;
--target)
if [ -z "$2" ]; then
echo "--target requires a value"
exit 1
fi
TARGET="$2"
shift 2
;;
-h|--help)
usage
exit 0
;;
*)
echo "Unknown option: $1"
usage
exit 1
;;
esac
done
safe_link() {
in="$BASEDIR/$1"
if [ -z "$2" ]; then
out=".$1"
else
out="$2"
fi
cd ~
if [ -h "$out" ]; then
echo "Already symlinked $out"
cd $OLDPWD
return
elif [ -f "$out" ] || [ -d "$out" ]; then
if [ ! -f "._$1" ]; then
echo "There's an existing $out, moving to ._$1"
mv "$out" "$(dirname $out)/._$1"
else
echo "There's already ._$1, can't create backup, skipping..."
fi
fi
ln -s $in $out
echo "Symlinked $out"
cd $OLDPWD
}
install_astronvim() {
if ! command -v git >/dev/null 2>&1; then
echo "git is not available; skipping AstroNvim config"
return
fi
mkdir -p "$(dirname "$ASTRONVIM_DIR")"
if [ -d "$ASTRONVIM_DIR/.git" ]; then
echo "AstroNvim config already present at $ASTRONVIM_DIR"
elif [ -e "$ASTRONVIM_DIR" ]; then
echo "Existing $ASTRONVIM_DIR found; skipping AstroNvim config"
else
git clone "$ASTRONVIM_REPO" "$ASTRONVIM_DIR"
echo "Cloned AstroNvim config to $ASTRONVIM_DIR"
fi
}
if [ "$MODE" = "legacy" ]; then
for f in $FILES; do
safe_link "$f"
done
safe_link "fish" ".config/fish"
git submodule update --init
vim +PluginInstall +qall
install_astronvim
else
if command -v nix >/dev/null 2>&1; then
if [ -z "$TARGET" ]; then
case "$(uname -s)" in
Darwin)
TARGET="sepeth-darwin"
;;
Linux)
if [ "$(uname -m)" = "aarch64" ]; then
TARGET="sepeth-linux-arm"
else
TARGET="sepeth-linux"
fi
;;
*)
echo "Unsupported OS; use --legacy or set a target manually."
exit 1
;;
esac
fi
# Note: `DOTFILES_REPO` is used by the activation hook to run `git submodule
# update --init` and to link `Vundle.vim` from your working tree. It requires
# `--impure` so Nix can read the environment variable.
DOTFILES_REPO="$BASEDIR" \
ASTRONVIM_REPO="$ASTRONVIM_REPO" \
ASTRONVIM_DIR="$ASTRONVIM_DIR" \
NIX_CONFIG="experimental-features = nix-command flakes" \
nix run nixpkgs#home-manager -- switch --flake .#"$TARGET" --impure -b bak
else
echo "nix is not available; run with --legacy or install Nix."
exit 1
fi
fi