-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathautocomplete.sh
More file actions
executable file
·154 lines (127 loc) · 5.72 KB
/
autocomplete.sh
File metadata and controls
executable file
·154 lines (127 loc) · 5.72 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
144
145
146
147
148
149
150
151
152
153
154
#!/bin/bash
# walrs Auto-completion Installer
# Simple, single-file installer that detects shell using $SHELL
set -e
# Get shell from $SHELL variable
CURRENT_SHELL=$(basename "$SHELL")
# Create completion based on shell
case "$CURRENT_SHELL" in
"fish")
echo "Installing Fish completion..."
# Create fish completions directory
mkdir -p ~/.config/fish/completions
# Write fish completion file
cat > ~/.config/fish/completions/walrs.fish << 'EOF'
# walrs completion for fish shell
# Clear existing completions
complete -c walrs -e
# Basic flags
complete -c walrs -s i -l image -d "path to image or directory" -r -F
complete -c walrs -s r -l reload -d "reload without changing the wallpaper"
complete -c walrs -s R -l reload-no -d "will be removed in the next update; use -w instead"
complete -c walrs -s t -l theme -d "use external theme file from .config/walrs/colorschemes" -r -F
complete -c walrs -s g -l generate -d "generate & save theme to .config/walrs/colorschemes" -x
complete -c walrs -s s -l saturation -d "set saturation value (-128 to 127)" -x
complete -c walrs -s b -l brightness -d "set brightness value (-128 to 127)" -x
complete -c walrs -s S -l scripts -d "skip running scripts in ~/.config/walrs/scripts/"
complete -c walrs -s W -l walless -d "skip changing the wallpaper"
complete -c walrs -s q -l quiet -d "set quit mode (no output)"
complete -c walrs -s v -l version -d "show version"
complete -c walrs -l help -d "display help"
complete -c walrs -a help -d "display help"
# Saturation and brightness numeric completion
for i in (seq -128 127)
complete -c walrs -s s -l saturation -x -a "$i"
complete -c walrs -s b -l brightness -x -a "$i"
end
EOF
echo -e "Fish completion installed to: ~/.config/fish/completions/walrs.fish"
;;
"zsh")
echo "Installing Zsh completion..."
# Create zsh completions directory
mkdir -p ~/.zsh/completions
# Write zsh completion file
cat > ~/.zsh/completions/_walrs << 'EOF'
#compdef walrs
_walrs() {
local context state line
typeset -A opt_args
_arguments \
'(-i --image)'{-i,--image}'[path to image or directory]:image file:_files -g "*.{jpg,jpeg,png,bmp,gif,tiff,webp}(-.)"' \
'(-r --reload)'{-r,--reload}'[reload without changing the wallpaper]' \
'(-R --reload-no)'{-R,--reload-no}'[will be removed in the next update; use -w instead]' \
'(-t --theme)'{-t,--theme}'[use external theme file from .config/walrs/colorschemes]:theme file:_files -g "*.json(-.)"' \
'(-g --generate)'{-g,--generate}'[generate & save theme to .config/walrs/colorschemes]:theme name:' \
'(-s --saturation)'{-s,--saturation}'[set saturation value (-128 to 127)]:saturation:({-128..127})' \
'(-b --brightness)'{-b,--brightness}'[set brightness value (-128 to 127)]:brightness:({-128..127})' \
'(-S --scripts)'{-S,--scripts}'[skip running scripts in ~/.config/walrs/scripts/]' \
'(-W --walless)'{-W,--walless}'[skip changing the wallpaper]' \
'(-q --quiet)'{-q,--quiet}'[set quit mode (no output)]' \
'(-v --version)'{-v,--version}'[show version]' \
'(--help)--help[display usage information]'
}
_walrs "$@"
EOF
# Add to fpath in .zshrc if not already there
if ! grep -q "fpath=(.*\.zsh/completions" ~/.zshrc 2>/dev/null; then
echo 'fpath=(~/.zsh/completions $fpath)' >> ~/.zshrc
echo -e "Added ~/.zsh/completions to fpath in ~/.zshrc"
fi
echo -e "Zsh completion installed to: ~/.zsh/completions/_walrs"
echo -e "Restart zsh or run: source ~/.zshrc && compinit"
;;
"bash")
echo "Installing Bash completion..."
# Try different locations for bash completion
if [ -d "/usr/share/bash-completion/completions" ] && [ -w "/usr/share/bash-completion/completions" ]; then
COMPLETION_DIR="/usr/share/bash-completion/completions"
elif [ -d "/etc/bash_completion.d" ] && [ -w "/etc/bash_completion.d" ]; then
COMPLETION_DIR="/etc/bash_completion.d"
else
# Use user directory
COMPLETION_DIR="$HOME/.local/share/bash-completion/completions"
mkdir -p "$COMPLETION_DIR"
fi
# Write bash completion file
cat > "$COMPLETION_DIR/walrs" << 'EOF'
_walrs_completion() {
shopt -s extglob
local cur prev opts
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
opts="-i --image -r --reload -R --reload-no -t --theme -g --generate -s --saturation -b --brightness -S --scripts -W --walless -q --quiet -v --version --help help"
case ${prev} in
-i|--image)
COMPREPLY=( $(compgen -f -X '!*.@(jpg|jpeg|png|bmp|gif|tiff|webp)' -- "${cur}") )
COMPREPLY+=( $(compgen -d -- "${cur}") )
return 0
;;
-t|--theme)
COMPREPLY=( $(compgen -f -X '!*.json' -- "${cur}") )
return 0
;;
-g|--generate)
COMPREPLY=( $(compgen -W "" -- "${cur}") )
return 0
;;
-s|--saturation|-b|--brightness)
COMPREPLY=( $(compgen -W "$(seq -128 127)" -- "${cur}") )
return 0
;;
esac
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
}
complete -F _walrs_completion walrs
EOF
echo "source ~/.local/share/bash-completion/completions/walrs" >> ~/.bashrc
echo -e "Bash completion installed to: $COMPLETION_DIR/walrs"
;;
*)
echo -e "Unsupported shell: $CURRENT_SHELL"
echo -e "Supported shells: fish, zsh, bash"
exit 1
;;
esac