-
Notifications
You must be signed in to change notification settings - Fork 0
/
vim_menu_owns
executable file
·56 lines (47 loc) · 1.13 KB
/
vim_menu_owns
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
#!/bin/bash
_source="$HOME/.config/nvim/colors.txt"
_target="$HOME/.config/nvim/lua/ak/color.lua"
_dmenu() {
# dmenu -g 2 -- grid patch
dmenu -i -l 20 -p "Select vim theme ($_active_theme)"
}
_a_file() {
_new_theme="$1"
_vim
}
_names() {
cat "$_source"
}
_dark_colors() {
_new_theme="$(_names | sort -z | _dmenu)"
if [ "$?" = 0 ]; then
_vim
sed -i 's/local prefer_light =.*/local prefer_light = false/' "$_target"
fi
}
_light_colors() {
_new_theme="$(_names | sort -z | _dmenu)"
if [ "$?" = 0 ]; then
_vim
sed -i 's/local prefer_light =.*/local prefer_light = true/' "$_target"
fi
}
_vim() {
if [ -f "$_target" ]; then
sed -i "s/local color.*$/local color = \"$_new_theme\"/" "$_target"
fi
}
_find_active_theme() {
grep -E "local color.*$" "$_target" | sed -r -e "s/(^local color = \")([^\"].*)(\"$)/\2/"
}
_active_theme="$(_find_active_theme)"
_new_theme=_active_theme
while getopts "hldf:" o; do
case "${o}" in
h) printf 'l is light theme, d is darktheme, f is a literal...' && exit ;;
l) _light_colors ;;
d) _dark_colors ;;
f) _a_file "$OPTARG" ;;
*) printf "Invalid option: -%s\\n" "$OPTARG" && exit ;;
esac
done