-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·88 lines (72 loc) · 2.23 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·88 lines (72 loc) · 2.23 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
#!/usr/bin/env bash
#
# install.sh — installs the Foreglow theme family for Vim and/or Neovim.
#
# Usage:
# ./install.sh [theme]
#
# theme one of: foreglow (default) | afterglow | airglow | alpenglow
set -euo pipefail
REPO_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
THEMES=(foreglow afterglow airglow alpenglow)
THEME="${1:-foreglow}"
is_valid_theme() {
local t="$1"
for known in "${THEMES[@]}"; do
[[ "$t" == "$known" ]] && return 0
done
return 1
}
if ! is_valid_theme "$THEME"; then
echo "Unknown theme: $THEME"
echo "Choose one of: ${THEMES[*]}"
exit 1
fi
install_for() {
local pack_root="$1" # e.g. ~/.vim or ~/.config/nvim
local rc_file="$2" # e.g. ~/.vimrc or ~/.config/nvim/init.vim
local label="$3" # "Vim" or "Neovim"
local start_dir="$pack_root/pack/themes/start"
local dest="$start_dir/foreglow"
mkdir -p "$start_dir"
for other in "${THEMES[@]}"; do
local other_dir="$start_dir/$other"
if [[ -d "$other_dir" && "$other_dir" != "$dest" ]]; then
rm -rf "$other_dir"
fi
done
rm -rf "$dest"
mkdir -p "$dest"
cp -r "$REPO_DIR/autoload" "$dest/"
cp -r "$REPO_DIR/colors" "$dest/"
[[ -d "$REPO_DIR/doc" ]] && cp -r "$REPO_DIR/doc" "$dest/"
[[ -d "$REPO_DIR/after" ]] && cp -r "$REPO_DIR/after" "$dest/"
mkdir -p "$(dirname "$rc_file")"
touch "$rc_file"
# Strip any previously-managed block, then write a fresh one.
if grep -q '" >>> foreglow >>>' "$rc_file"; then
local tmp
tmp="$(mktemp)"
awk '/" >>> foreglow >>>/{skip=1} /" <<< foreglow <<</{skip=0; next} !skip' "$rc_file" > "$tmp"
mv "$tmp" "$rc_file"
fi
{
echo '" >>> foreglow >>>'
echo 'syntax on'
echo 'filetype plugin indent on'
echo "if has('termguicolors')"
echo ' set termguicolors'
echo 'endif'
echo "colorscheme $THEME"
echo '" <<< foreglow <<<'
} >> "$rc_file"
echo "[$label] Installed '$THEME' -> $dest"
echo "[$label] Configured in $rc_file"
}
install_for "$HOME/.vim" "$HOME/.vimrc" "Vim"
if command -v nvim >/dev/null 2>&1; then
install_for "$HOME/.config/nvim" "$HOME/.config/nvim/init.vim" "Neovim"
fi
echo ""
echo "Done. Restart Vim/Neovim to see '$THEME'."
echo "Re-run with a different name any time, e.g.: ./install.sh airglow"