mirror of
https://github.com/TheLocehiliosan/yadm
synced 2024-10-27 20:34:27 +00:00
Reorganize shell completion code
This commit is contained in:
parent
2ff07c3fa6
commit
53e3288234
@ -1,54 +1,47 @@
|
|||||||
# Installation
|
# Installation
|
||||||
|
|
||||||
## Bash completions
|
|
||||||
|
|
||||||
### Prerequisites
|
### Prerequisites
|
||||||
|
|
||||||
**yadm** completion only works if Git completions are also enabled.
|
Bash and Zsh completion only works if Git completions are also enabled.
|
||||||
|
|
||||||
### Homebrew
|
## Homebrew
|
||||||
|
|
||||||
If using `homebrew` to install **yadm**, completions should automatically be
|
If using `homebrew` to install yadm, Bash, Zsh, and Fish completions should
|
||||||
handled if you also install `brew install bash-completion`. This might require
|
automatically be installed. For Bash and Zsh, you also must install
|
||||||
you to include the main completion script in your own bashrc file like this:
|
`bash-completion` or `zsh-completions`. This might require you to include the
|
||||||
|
main completion script in your own shell configuration like this:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
[ -f /usr/local/etc/bash_completion ] && source /usr/local/etc/bash_completion
|
[ -f /usr/local/etc/bash_completion ] && source /usr/local/etc/bash_completion
|
||||||
```
|
```
|
||||||
|
|
||||||
### Manual installation
|
## Bash (manual installation)
|
||||||
|
|
||||||
Copy the completion script locally, and add this to you bashrc:
|
Copy the completion script locally, and add this to you bashrc:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
[ -f /full/path/to/yadm.bash_completion ] && source /full/path/to/yadm.bash_completion
|
[ -f /path/to/yadm/completion/bash/yadm ] && source /path/to/yadm/completion/bash/yadm
|
||||||
```
|
```
|
||||||
|
|
||||||
## Zsh completions
|
## Zsh (manual installation)
|
||||||
|
|
||||||
### Homebrew
|
|
||||||
|
|
||||||
If using `homebrew` to install **yadm**, completions should handled automatically.
|
|
||||||
|
|
||||||
### Manual installation
|
|
||||||
|
|
||||||
Add the `completion/zsh` folder to `$fpath` in `.zshrc`:
|
Add the `completion/zsh` folder to `$fpath` in `.zshrc`:
|
||||||
|
|
||||||
```zsh
|
```zsh
|
||||||
fpath=(/full/path/to/yadm/completion/zsh $fpath)
|
fpath=(/path/to/yadm/completion/zsh $fpath)
|
||||||
autoload -U compinit
|
autoload -U compinit
|
||||||
compinit
|
compinit
|
||||||
```
|
```
|
||||||
|
|
||||||
### Installation using [zplug](https://github.com/b4b4r07/zplug)
|
## Zsh (using [zplug](https://github.com/b4b4r07/zplug))
|
||||||
|
|
||||||
Load `_yadm` as a plugin in your `.zshrc`:
|
Load `_yadm` as a plugin in your `.zshrc`:
|
||||||
|
|
||||||
```zsh
|
```zsh
|
||||||
fpath=("$ZPLUG_HOME/bin" $fpath)
|
fpath=("$ZPLUG_HOME/bin" $fpath)
|
||||||
zplug "TheLocehiliosan/yadm", rename-to:_yadm, use:"completion/yadm.zsh_completion", as:command, defer:2
|
zplug "TheLocehiliosan/yadm", use:"completion/zsh/_yadm", as:command, defer:2
|
||||||
```
|
```
|
||||||
|
|
||||||
## Fish completions
|
## Fish (manual installation)
|
||||||
### Manual installation
|
|
||||||
Copy the completion script `yadm.fish_completion` locally, rename it to `yadm.fish`, and add it to any folder within `$fish_complete_path`. For example, for local installation, you can copy it to `$HOME/.config/fish/completions/` and it will be loaded when `yadm` is invoked.
|
Copy the completion script `yadm.fish` to any folder within `$fish_complete_path`. For example, for local installation, you can copy it to `$HOME/.config/fish/completions/` and it will be loaded when `yadm` is invoked.
|
||||||
|
@ -1,164 +0,0 @@
|
|||||||
#compdef yadm
|
|
||||||
|
|
||||||
_yadm-alt() {
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
|
|
||||||
_yadm-bootstrap() {
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
|
|
||||||
_yadm-clone() {
|
|
||||||
_arguments \
|
|
||||||
'(--bootstrap --no-bootstrap)--bootstrap[force bootstrap, without prompt]' \
|
|
||||||
'(--bootstrap --no-bootstrap)--no-bootstrap[prevent bootstrap, without prompt]' \
|
|
||||||
'-b[branch name]:' \
|
|
||||||
'-f[force overwrite of existing repository]' \
|
|
||||||
'-w[work tree path]: :_files -/' \
|
|
||||||
'*:'
|
|
||||||
}
|
|
||||||
|
|
||||||
_yadm-config() {
|
|
||||||
# TODO: complete config names
|
|
||||||
}
|
|
||||||
|
|
||||||
_yadm-decrypt() {
|
|
||||||
_arguments \
|
|
||||||
'-l[list files]'
|
|
||||||
}
|
|
||||||
|
|
||||||
_yadm-encrypt() {
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
|
|
||||||
_yadm-enter() {
|
|
||||||
_arguments \
|
|
||||||
':command: _command_names -e' \
|
|
||||||
'*::arguments: _normal'
|
|
||||||
}
|
|
||||||
|
|
||||||
_yadm-git-crypt() {
|
|
||||||
# TODO: complete git-crypt options
|
|
||||||
}
|
|
||||||
|
|
||||||
_yadm-gitconfig() {
|
|
||||||
integer ret=1
|
|
||||||
_call_function ret _git-config
|
|
||||||
return ret
|
|
||||||
}
|
|
||||||
|
|
||||||
_yadm-help() {
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
|
|
||||||
_yadm-init() {
|
|
||||||
_arguments \
|
|
||||||
'-f[force overwrite of existing repository]' \
|
|
||||||
'-w[work tree path]: :_files -/'
|
|
||||||
}
|
|
||||||
|
|
||||||
_yadm-list() {
|
|
||||||
_arguments \
|
|
||||||
'-a[list all tracked files]'
|
|
||||||
}
|
|
||||||
|
|
||||||
_yadm-perms() {
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
|
|
||||||
_yadm-transcrypt() {
|
|
||||||
integer ret=1
|
|
||||||
_call_function ret _transcrypt
|
|
||||||
return ret
|
|
||||||
}
|
|
||||||
|
|
||||||
_yadm-upgrade() {
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
|
|
||||||
_yadm-version() {
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
|
|
||||||
_yadm_commands() {
|
|
||||||
local -a commands
|
|
||||||
commands=(
|
|
||||||
alt:'create links for alternates (yadm)'
|
|
||||||
bootstrap:'execute bootstrap (yadm)'
|
|
||||||
clone:'clone an existing repository (yadm)'
|
|
||||||
config:'configure an yadm setting'
|
|
||||||
decrypt:'decrypt files (yadm)'
|
|
||||||
encrypt:'encrypt files (yadm)'
|
|
||||||
enter:'run sub-shell with GIT variables set'
|
|
||||||
git-crypt:'run git-crypt commands for the yadm repository'
|
|
||||||
gitconfig:'run the git config command'
|
|
||||||
help:'display yadm help information'
|
|
||||||
init:'initialize an empty yadm repository'
|
|
||||||
list:'list files tracked by yadm'
|
|
||||||
perms:'fix perms for private files (yadm)'
|
|
||||||
transcrypt:'run transcrypt commands for the yadm repository'
|
|
||||||
upgrade:'upgrade legacy yadm paths'
|
|
||||||
version:'show yadm version'
|
|
||||||
)
|
|
||||||
|
|
||||||
zstyle ':completion:*:*:yadm:*' user-commands $commands
|
|
||||||
|
|
||||||
integer ret=1
|
|
||||||
_call_function ret _git_commands
|
|
||||||
|
|
||||||
zstyle -d ':completion:*:*:yadm:*' user-commands
|
|
||||||
return ret
|
|
||||||
}
|
|
||||||
|
|
||||||
_yadm() {
|
|
||||||
local curcontext=$curcontext state line
|
|
||||||
declare -A opt_args
|
|
||||||
|
|
||||||
_arguments -C \
|
|
||||||
'(-Y --yadm-dir)'{-Y,--yadm-dir}'[override the standard yadm directory]: :_files -/' \
|
|
||||||
'--yadm-data[override the standard yadm data directory]: :_files -/' \
|
|
||||||
'--yadm-repo[override the standard repo path]: :_files -/' \
|
|
||||||
'--yadm-config[override the standard config path]: :_files -/' \
|
|
||||||
'--yadm-encrypt[override the standard encrypt path]: :_files -/' \
|
|
||||||
'--yadm-archive[override the standard archive path]: :_files -/' \
|
|
||||||
'--yadm-bootstrap[override the standard bootstrap path]: :_files' \
|
|
||||||
'-d[print debug traces]' \
|
|
||||||
'--help[display yadm help information]' \
|
|
||||||
'--version[show yadm version]' \
|
|
||||||
'(-): :->command' \
|
|
||||||
'(-)*:: :->option-or-argument' && return
|
|
||||||
|
|
||||||
local -a repo_args
|
|
||||||
(( $+opt_args[--yadm-repo] )) && repo_args+=(--yadm-repo "$opt_args[--yadm-repo]")
|
|
||||||
(( $+opt_args[--yadm-data] )) && repo_args+=(--yadm-data "$opt_args[--yadm-data]")
|
|
||||||
local -x GIT_DIR="$(_call_program gitdir yadm "${repo_args[@]}" introspect repo)"
|
|
||||||
|
|
||||||
integer ret=1
|
|
||||||
case $state in
|
|
||||||
(command)
|
|
||||||
_yadm_commands && ret=0
|
|
||||||
;;
|
|
||||||
(option-or-argument)
|
|
||||||
curcontext=${curcontext%:*:*}:yadm-$words[1]:
|
|
||||||
|
|
||||||
if ! _call_function ret _yadm-$words[1]; then
|
|
||||||
curcontext=${curcontext%:*:*}:git-$words[1]:
|
|
||||||
if ! _call_function ret _git-$words[1]; then
|
|
||||||
if [[ $words[1] = \!* ]]; then
|
|
||||||
words[1]=${words[1]##\!}
|
|
||||||
_normal && ret=0
|
|
||||||
elif zstyle -T :completion:$curcontext: use-fallback; then
|
|
||||||
_default && ret=0
|
|
||||||
else
|
|
||||||
_message "unknown sub-command: $words[1]"
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
|
|
||||||
return ret
|
|
||||||
}
|
|
||||||
|
|
||||||
(( $+functions[_git_commands] )) || _git
|
|
||||||
_yadm "$@"
|
|
@ -1 +0,0 @@
|
|||||||
../yadm.zsh_completion
|
|
164
completion/zsh/_yadm
Normal file
164
completion/zsh/_yadm
Normal file
@ -0,0 +1,164 @@
|
|||||||
|
#compdef yadm
|
||||||
|
|
||||||
|
_yadm-alt() {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
_yadm-bootstrap() {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
_yadm-clone() {
|
||||||
|
_arguments \
|
||||||
|
'(--bootstrap --no-bootstrap)--bootstrap[force bootstrap, without prompt]' \
|
||||||
|
'(--bootstrap --no-bootstrap)--no-bootstrap[prevent bootstrap, without prompt]' \
|
||||||
|
'-b[branch name]:' \
|
||||||
|
'-f[force overwrite of existing repository]' \
|
||||||
|
'-w[work tree path]: :_files -/' \
|
||||||
|
'*:'
|
||||||
|
}
|
||||||
|
|
||||||
|
_yadm-config() {
|
||||||
|
# TODO: complete config names
|
||||||
|
}
|
||||||
|
|
||||||
|
_yadm-decrypt() {
|
||||||
|
_arguments \
|
||||||
|
'-l[list files]'
|
||||||
|
}
|
||||||
|
|
||||||
|
_yadm-encrypt() {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
_yadm-enter() {
|
||||||
|
_arguments \
|
||||||
|
':command: _command_names -e' \
|
||||||
|
'*::arguments: _normal'
|
||||||
|
}
|
||||||
|
|
||||||
|
_yadm-git-crypt() {
|
||||||
|
# TODO: complete git-crypt options
|
||||||
|
}
|
||||||
|
|
||||||
|
_yadm-gitconfig() {
|
||||||
|
integer ret=1
|
||||||
|
_call_function ret _git-config
|
||||||
|
return ret
|
||||||
|
}
|
||||||
|
|
||||||
|
_yadm-help() {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
_yadm-init() {
|
||||||
|
_arguments \
|
||||||
|
'-f[force overwrite of existing repository]' \
|
||||||
|
'-w[work tree path]: :_files -/'
|
||||||
|
}
|
||||||
|
|
||||||
|
_yadm-list() {
|
||||||
|
_arguments \
|
||||||
|
'-a[list all tracked files]'
|
||||||
|
}
|
||||||
|
|
||||||
|
_yadm-perms() {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
_yadm-transcrypt() {
|
||||||
|
integer ret=1
|
||||||
|
_call_function ret _transcrypt
|
||||||
|
return ret
|
||||||
|
}
|
||||||
|
|
||||||
|
_yadm-upgrade() {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
_yadm-version() {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
_yadm_commands() {
|
||||||
|
local -a commands
|
||||||
|
commands=(
|
||||||
|
alt:'create links for alternates (yadm)'
|
||||||
|
bootstrap:'execute bootstrap (yadm)'
|
||||||
|
clone:'clone an existing repository (yadm)'
|
||||||
|
config:'configure an yadm setting'
|
||||||
|
decrypt:'decrypt files (yadm)'
|
||||||
|
encrypt:'encrypt files (yadm)'
|
||||||
|
enter:'run sub-shell with GIT variables set'
|
||||||
|
git-crypt:'run git-crypt commands for the yadm repository'
|
||||||
|
gitconfig:'run the git config command'
|
||||||
|
help:'display yadm help information'
|
||||||
|
init:'initialize an empty yadm repository'
|
||||||
|
list:'list files tracked by yadm'
|
||||||
|
perms:'fix perms for private files (yadm)'
|
||||||
|
transcrypt:'run transcrypt commands for the yadm repository'
|
||||||
|
upgrade:'upgrade legacy yadm paths'
|
||||||
|
version:'show yadm version'
|
||||||
|
)
|
||||||
|
|
||||||
|
zstyle ':completion:*:*:yadm:*' user-commands $commands
|
||||||
|
|
||||||
|
integer ret=1
|
||||||
|
_call_function ret _git_commands
|
||||||
|
|
||||||
|
zstyle -d ':completion:*:*:yadm:*' user-commands
|
||||||
|
return ret
|
||||||
|
}
|
||||||
|
|
||||||
|
_yadm() {
|
||||||
|
local curcontext=$curcontext state line
|
||||||
|
declare -A opt_args
|
||||||
|
|
||||||
|
_arguments -C \
|
||||||
|
'(-Y --yadm-dir)'{-Y,--yadm-dir}'[override the standard yadm directory]: :_files -/' \
|
||||||
|
'--yadm-data[override the standard yadm data directory]: :_files -/' \
|
||||||
|
'--yadm-repo[override the standard repo path]: :_files -/' \
|
||||||
|
'--yadm-config[override the standard config path]: :_files -/' \
|
||||||
|
'--yadm-encrypt[override the standard encrypt path]: :_files -/' \
|
||||||
|
'--yadm-archive[override the standard archive path]: :_files -/' \
|
||||||
|
'--yadm-bootstrap[override the standard bootstrap path]: :_files' \
|
||||||
|
'-d[print debug traces]' \
|
||||||
|
'--help[display yadm help information]' \
|
||||||
|
'--version[show yadm version]' \
|
||||||
|
'(-): :->command' \
|
||||||
|
'(-)*:: :->option-or-argument' && return
|
||||||
|
|
||||||
|
local -a repo_args
|
||||||
|
(( $+opt_args[--yadm-repo] )) && repo_args+=(--yadm-repo "$opt_args[--yadm-repo]")
|
||||||
|
(( $+opt_args[--yadm-data] )) && repo_args+=(--yadm-data "$opt_args[--yadm-data]")
|
||||||
|
local -x GIT_DIR="$(_call_program gitdir yadm "${repo_args[@]}" introspect repo)"
|
||||||
|
|
||||||
|
integer ret=1
|
||||||
|
case $state in
|
||||||
|
(command)
|
||||||
|
_yadm_commands && ret=0
|
||||||
|
;;
|
||||||
|
(option-or-argument)
|
||||||
|
curcontext=${curcontext%:*:*}:yadm-$words[1]:
|
||||||
|
|
||||||
|
if ! _call_function ret _yadm-$words[1]; then
|
||||||
|
curcontext=${curcontext%:*:*}:git-$words[1]:
|
||||||
|
if ! _call_function ret _git-$words[1]; then
|
||||||
|
if [[ $words[1] = \!* ]]; then
|
||||||
|
words[1]=${words[1]##\!}
|
||||||
|
_normal && ret=0
|
||||||
|
elif zstyle -T :completion:$curcontext: use-fallback; then
|
||||||
|
_default && ret=0
|
||||||
|
else
|
||||||
|
_message "unknown sub-command: $words[1]"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
return ret
|
||||||
|
}
|
||||||
|
|
||||||
|
(( $+functions[_git_commands] )) || _git
|
||||||
|
_yadm "$@"
|
Loading…
Reference in New Issue
Block a user