-
Notifications
You must be signed in to change notification settings - Fork 594
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
209 additions
and
121 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
|
||
#!/bin/bash | ||
|
||
_ani_cli_autocomplete() { | ||
local cur prev opts | ||
|
||
# Get the current and previous words in the command line | ||
COMPREPLY=() | ||
cur="${COMP_WORDS[COMP_CWORD]}" | ||
prev="${COMP_WORDS[COMP_CWORD-1]}" | ||
|
||
# Define the main options | ||
opts=" | ||
-c --continue | ||
-d --download | ||
-D --delete | ||
-s --syncplay | ||
-S --select-nth | ||
-q --quality | ||
-v --vlc | ||
-V --version | ||
-h --help | ||
-e --episode | ||
--dub | ||
--rofi | ||
--skip | ||
--no-detach | ||
-N --nextep-countdown | ||
-U --update | ||
" | ||
|
||
# Check for conditional options | ||
if [[ "${COMP_WORDS[@]}" =~ "--no-detach" ]]; then | ||
opts+=" --exit-after-play" | ||
fi | ||
|
||
if [[ "${COMP_WORDS[@]}" =~ "-e" || "${COMP_WORDS[@]}" =~ "--episode" ]]; then | ||
opts+=" -r --range" | ||
fi | ||
|
||
# Use `compgen` to generate the options based on the current word | ||
COMPREPLY=($(compgen -W "${opts}" -- "$cur")) | ||
} | ||
|
||
# Register the completion function for `ani-cli` | ||
complete -F _ani_cli_autocomplete ani-cli |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
|
||
#!/bin/zsh | ||
|
||
# Enable autocompletion for zsh | ||
autoload -U compinit && compinit | ||
|
||
_ani-cli() { | ||
_arguments \ | ||
'(-c --continue)'{-c,--continue}'[Continue watching from history]' \ | ||
'(-d --download)'{-d,--download}'[Download the video instead of playing it]' \ | ||
'(-D --delete)'{-D,--delete}'[Delete the downloaded video]' \ | ||
'(-s --syncplay)'{-s,--syncplay}'[Use Syncplay to watch with friends]' \ | ||
'(-S --select-nth)'{-S,--select-nth}'[Select nth entry]' \ | ||
'(-q --quality)'{-q,--quality}'[Specify the video quality]' \ | ||
'(-v --vlc)'{-v,--vlc}'[Use VLC to play the video]' \ | ||
'(-V --version)'{-V,--version}'[Show the version of the script]' \ | ||
'(-h --help)'{-h,--help}'[Show help this help message]' \ | ||
'(-e --episode)'{-e,--episode}'[Specify the episode to watch]' \ | ||
'(-e --episode)'{-r,--range}'[Specify the range of episodes to watch]' \ | ||
'--dub[Dub the video]' \ | ||
'--rofi[Use rofi instead of fzf]' \ | ||
'--skip[Use ani-skip to skip the intro of the episode (mpv only)]' \ | ||
"--no-detach[ Don't detach the player (useful for in-terminal playback, mpv only)]" \ | ||
'(--no-detach)--exit-after-play[Exit after the video is played]' \ | ||
'--skip-title[Use given title as ani-skip query]' \ | ||
'(-N --nextep-countdown)'{-N,--nextep-countdown}'[Countdown to next episode]' \ | ||
'(-U --update)'{-U,--update}'[Update the script]' | ||
} | ||
|
||
# Register the completion function for `ani-cli` | ||
compdef _ani-cli ani-cli |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
#!/bin/sh | ||
|
||
# ############################################################################# | ||
# -----------------------< shell detecting completion >----------------------- | ||
# ############################################################################# | ||
|
||
# Detect the current shell | ||
detect_shell() { | ||
shell_name=$(basename "$SHELL") | ||
|
||
case "$shell_name" in | ||
bash) | ||
echo "bash" | ||
;; | ||
zsh) | ||
echo "zsh" | ||
;; | ||
*) | ||
echo "unsupported" | ||
;; | ||
esac | ||
} | ||
|
||
# Apply the appropriate setup based on the detected shell | ||
shell=$(detect_shell) | ||
|
||
print_completion () { | ||
case "$shell" in | ||
bash) | ||
cat << 'EOF' | ||
#!/bin/bash | ||
_ani_cli_autocomplete() { | ||
local cur prev opts | ||
# Get the current and previous words in the command line | ||
COMPREPLY=() | ||
cur="${COMP_WORDS[COMP_CWORD]}" | ||
prev="${COMP_WORDS[COMP_CWORD-1]}" | ||
# Define the main options | ||
opts=" | ||
-c --continue | ||
-d --download | ||
-D --delete | ||
-s --syncplay | ||
-S --select-nth | ||
-q --quality | ||
-v --vlc | ||
-V --version | ||
-h --help | ||
-e --episode | ||
--dub | ||
--rofi | ||
--skip | ||
--no-detach | ||
-N --nextep-countdown | ||
-U --update | ||
" | ||
# Check for conditional options | ||
if [[ "${COMP_WORDS[@]}" =~ "--no-detach" ]]; then | ||
opts+=" --exit-after-play" | ||
fi | ||
if [[ "${COMP_WORDS[@]}" =~ "-e" || "${COMP_WORDS[@]}" =~ "--episode" ]]; then | ||
opts+=" -r --range" | ||
fi | ||
# Use `compgen` to generate the options based on the current word | ||
COMPREPLY=($(compgen -W "${opts}" -- "$cur")) | ||
} | ||
# Register the completion function for `ani-cli` | ||
complete -F _ani_cli_autocomplete ani-cli | ||
EOF | ||
;; | ||
zsh) | ||
cat << 'EOF' | ||
#!/bin/zsh | ||
# Enable autocompletion for zsh | ||
autoload -U compinit && compinit | ||
_ani-cli() { | ||
_arguments \ | ||
'(-c --continue)'{-c,--continue}'[Continue watching from history]' \ | ||
'(-d --download)'{-d,--download}'[Download the video instead of playing it]' \ | ||
'(-D --delete)'{-D,--delete}'[Delete the downloaded video]' \ | ||
'(-s --syncplay)'{-s,--syncplay}'[Use Syncplay to watch with friends]' \ | ||
'(-S --select-nth)'{-S,--select-nth}'[Select nth entry]' \ | ||
'(-q --quality)'{-q,--quality}'[Specify the video quality]' \ | ||
'(-v --vlc)'{-v,--vlc}'[Use VLC to play the video]' \ | ||
'(-V --version)'{-V,--version}'[Show the version of the script]' \ | ||
'(-h --help)'{-h,--help}'[Show help this help message]' \ | ||
'(-e --episode)'{-e,--episode}'[Specify the episode to watch]' \ | ||
'(-e --episode)'{-r,--range}'[Specify the range of episodes to watch]' \ | ||
'--dub[Dub the video]' \ | ||
'--rofi[Use rofi instead of fzf]' \ | ||
'--skip[Use ani-skip to skip the intro of the episode (mpv only)]' \ | ||
"--no-detach[ Don't detach the player (useful for in-terminal playback, mpv only)]" \ | ||
'(--no-detach)--exit-after-play[Exit after the video is played]' \ | ||
'--skip-title[Use given title as ani-skip query]' \ | ||
'(-N --nextep-countdown)'{-N,--nextep-countdown}'[Countdown to next episode]' \ | ||
'(-U --update)'{-U,--update}'[Update the script]' | ||
} | ||
# Register the completion function for `ani-cli` | ||
compdef _ani-cli ani-cli | ||
EOF | ||
;; | ||
*) | ||
echo "Autocompletion is not yet supported for $shell. Sorry!" | ||
;; | ||
esac | ||
} | ||
|
||
# Generate and store the completion script | ||
print_completion > ~/_ani-cli-completion | ||
|
||
# Append the source command to the appropriate shell configuration file | ||
case "$shell" in | ||
bash) | ||
echo "source ~/_ani-cli-completion" >> ~/.bashrc | ||
;; | ||
zsh) | ||
echo "source ~/_ani-cli-completion" >> ~/.zshrc | ||
;; | ||
*) | ||
echo "Shell $shell is not supported for autocompletion setup." | ||
;; | ||
esac |