mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-25 08:41:05 +00:00
feat(completions): generate shell completion scripts
This commit is contained in:
parent
e6fb999d1b
commit
fb10da6857
7 changed files with 217 additions and 0 deletions
39
config/completions/_yazi
Normal file
39
config/completions/_yazi
Normal file
|
|
@ -0,0 +1,39 @@
|
||||||
|
#compdef yazi
|
||||||
|
|
||||||
|
autoload -U is-at-least
|
||||||
|
|
||||||
|
_yazi() {
|
||||||
|
typeset -A opt_args
|
||||||
|
typeset -a _arguments_options
|
||||||
|
local ret=1
|
||||||
|
|
||||||
|
if is-at-least 5.2; then
|
||||||
|
_arguments_options=(-s -S -C)
|
||||||
|
else
|
||||||
|
_arguments_options=(-s -C)
|
||||||
|
fi
|
||||||
|
|
||||||
|
local context curcontext="$curcontext" state line
|
||||||
|
_arguments "${_arguments_options[@]}" \
|
||||||
|
'--cwd-file=[Write the cwd on exit to this file]:CWD_FILE:_files' \
|
||||||
|
'--chooser-file=[Write the selected files on open emitted by the chooser mode]:CHOOSER_FILE:_files' \
|
||||||
|
'--clear-cache[Clear the cache directory]' \
|
||||||
|
'-h[Print help]' \
|
||||||
|
'--help[Print help]' \
|
||||||
|
'-V[Print version]' \
|
||||||
|
'--version[Print version]' \
|
||||||
|
'::cwd -- Set the current working directory:_files' \
|
||||||
|
&& ret=0
|
||||||
|
}
|
||||||
|
|
||||||
|
(( $+functions[_yazi_commands] )) ||
|
||||||
|
_yazi_commands() {
|
||||||
|
local commands; commands=()
|
||||||
|
_describe -t commands 'yazi commands' commands "$@"
|
||||||
|
}
|
||||||
|
|
||||||
|
if [ "$funcstack[1]" = "_yazi" ]; then
|
||||||
|
_yazi "$@"
|
||||||
|
else
|
||||||
|
compdef _yazi yazi
|
||||||
|
fi
|
||||||
37
config/completions/_yazi.ps1
Normal file
37
config/completions/_yazi.ps1
Normal file
|
|
@ -0,0 +1,37 @@
|
||||||
|
|
||||||
|
using namespace System.Management.Automation
|
||||||
|
using namespace System.Management.Automation.Language
|
||||||
|
|
||||||
|
Register-ArgumentCompleter -Native -CommandName 'yazi' -ScriptBlock {
|
||||||
|
param($wordToComplete, $commandAst, $cursorPosition)
|
||||||
|
|
||||||
|
$commandElements = $commandAst.CommandElements
|
||||||
|
$command = @(
|
||||||
|
'yazi'
|
||||||
|
for ($i = 1; $i -lt $commandElements.Count; $i++) {
|
||||||
|
$element = $commandElements[$i]
|
||||||
|
if ($element -isnot [StringConstantExpressionAst] -or
|
||||||
|
$element.StringConstantType -ne [StringConstantType]::BareWord -or
|
||||||
|
$element.Value.StartsWith('-') -or
|
||||||
|
$element.Value -eq $wordToComplete) {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
$element.Value
|
||||||
|
}) -join ';'
|
||||||
|
|
||||||
|
$completions = @(switch ($command) {
|
||||||
|
'yazi' {
|
||||||
|
[CompletionResult]::new('--cwd-file', 'cwd-file', [CompletionResultType]::ParameterName, 'Write the cwd on exit to this file')
|
||||||
|
[CompletionResult]::new('--chooser-file', 'chooser-file', [CompletionResultType]::ParameterName, 'Write the selected files on open emitted by the chooser mode')
|
||||||
|
[CompletionResult]::new('--clear-cache', 'clear-cache', [CompletionResultType]::ParameterName, 'Clear the cache directory')
|
||||||
|
[CompletionResult]::new('-h', 'h', [CompletionResultType]::ParameterName, 'Print help')
|
||||||
|
[CompletionResult]::new('--help', 'help', [CompletionResultType]::ParameterName, 'Print help')
|
||||||
|
[CompletionResult]::new('-V', 'V ', [CompletionResultType]::ParameterName, 'Print version')
|
||||||
|
[CompletionResult]::new('--version', 'version', [CompletionResultType]::ParameterName, 'Print version')
|
||||||
|
break
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
$completions.Where{ $_.CompletionText -like "$wordToComplete*" } |
|
||||||
|
Sort-Object -Property ListItemText
|
||||||
|
}
|
||||||
46
config/completions/yazi.bash
Normal file
46
config/completions/yazi.bash
Normal file
|
|
@ -0,0 +1,46 @@
|
||||||
|
_yazi() {
|
||||||
|
local i cur prev opts cmd
|
||||||
|
COMPREPLY=()
|
||||||
|
cur="${COMP_WORDS[COMP_CWORD]}"
|
||||||
|
prev="${COMP_WORDS[COMP_CWORD-1]}"
|
||||||
|
cmd=""
|
||||||
|
opts=""
|
||||||
|
|
||||||
|
for i in ${COMP_WORDS[@]}
|
||||||
|
do
|
||||||
|
case "${cmd},${i}" in
|
||||||
|
",$1")
|
||||||
|
cmd="yazi"
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
case "${cmd}" in
|
||||||
|
yazi)
|
||||||
|
opts="-h -V --cwd-file --chooser-file --clear-cache --help --version [CWD]"
|
||||||
|
if [[ ${cur} == -* || ${COMP_CWORD} -eq 1 ]] ; then
|
||||||
|
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
case "${prev}" in
|
||||||
|
--cwd-file)
|
||||||
|
COMPREPLY=($(compgen -f "${cur}"))
|
||||||
|
return 0
|
||||||
|
;;
|
||||||
|
--chooser-file)
|
||||||
|
COMPREPLY=($(compgen -f "${cur}"))
|
||||||
|
return 0
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
COMPREPLY=()
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
|
||||||
|
return 0
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
}
|
||||||
|
|
||||||
|
complete -F _yazi -o nosort -o bashdefault -o default yazi
|
||||||
31
config/completions/yazi.elv
Normal file
31
config/completions/yazi.elv
Normal file
|
|
@ -0,0 +1,31 @@
|
||||||
|
|
||||||
|
use builtin;
|
||||||
|
use str;
|
||||||
|
|
||||||
|
set edit:completion:arg-completer[yazi] = {|@words|
|
||||||
|
fn spaces {|n|
|
||||||
|
builtin:repeat $n ' ' | str:join ''
|
||||||
|
}
|
||||||
|
fn cand {|text desc|
|
||||||
|
edit:complex-candidate $text &display=$text' '(spaces (- 14 (wcswidth $text)))$desc
|
||||||
|
}
|
||||||
|
var command = 'yazi'
|
||||||
|
for word $words[1..-1] {
|
||||||
|
if (str:has-prefix $word '-') {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
set command = $command';'$word
|
||||||
|
}
|
||||||
|
var completions = [
|
||||||
|
&'yazi'= {
|
||||||
|
cand --cwd-file 'Write the cwd on exit to this file'
|
||||||
|
cand --chooser-file 'Write the selected files on open emitted by the chooser mode'
|
||||||
|
cand --clear-cache 'Clear the cache directory'
|
||||||
|
cand -h 'Print help'
|
||||||
|
cand --help 'Print help'
|
||||||
|
cand -V 'Print version'
|
||||||
|
cand --version 'Print version'
|
||||||
|
}
|
||||||
|
]
|
||||||
|
$completions[$command]
|
||||||
|
}
|
||||||
5
config/completions/yazi.fish
Normal file
5
config/completions/yazi.fish
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
complete -c yazi -l cwd-file -d 'Write the cwd on exit to this file' -r -F
|
||||||
|
complete -c yazi -l chooser-file -d 'Write the selected files on open emitted by the chooser mode' -r -F
|
||||||
|
complete -c yazi -l clear-cache -d 'Clear the cache directory'
|
||||||
|
complete -c yazi -s h -l help -d 'Print help'
|
||||||
|
complete -c yazi -s V -l version -d 'Print version'
|
||||||
14
config/completions/yazi.nu
Normal file
14
config/completions/yazi.nu
Normal file
|
|
@ -0,0 +1,14 @@
|
||||||
|
module completions {
|
||||||
|
|
||||||
|
export extern yazi [
|
||||||
|
cwd?: string # Set the current working directory
|
||||||
|
--cwd-file: string # Write the cwd on exit to this file
|
||||||
|
--chooser-file: string # Write the selected files on open emitted by the chooser mode
|
||||||
|
--clear-cache # Clear the cache directory
|
||||||
|
--help(-h) # Print help
|
||||||
|
--version(-V) # Print version
|
||||||
|
]
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
export use completions *
|
||||||
45
config/completions/yazi.ts
Normal file
45
config/completions/yazi.ts
Normal file
|
|
@ -0,0 +1,45 @@
|
||||||
|
const completion: Fig.Spec = {
|
||||||
|
name: "yazi",
|
||||||
|
description: "",
|
||||||
|
options: [
|
||||||
|
{
|
||||||
|
name: "--cwd-file",
|
||||||
|
description: "Write the cwd on exit to this file",
|
||||||
|
isRepeatable: true,
|
||||||
|
args: {
|
||||||
|
name: "cwd_file",
|
||||||
|
isOptional: true,
|
||||||
|
template: "filepaths",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "--chooser-file",
|
||||||
|
description: "Write the selected files on open emitted by the chooser mode",
|
||||||
|
isRepeatable: true,
|
||||||
|
args: {
|
||||||
|
name: "chooser_file",
|
||||||
|
isOptional: true,
|
||||||
|
template: "filepaths",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "--clear-cache",
|
||||||
|
description: "Clear the cache directory",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: ["-h", "--help"],
|
||||||
|
description: "Print help",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: ["-V", "--version"],
|
||||||
|
description: "Print version",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
args: {
|
||||||
|
name: "cwd",
|
||||||
|
isOptional: true,
|
||||||
|
template: "filepaths",
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
export default completion;
|
||||||
Loading…
Add table
Reference in a new issue