-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
auto man&completion: add dynamic + add cat example
- Loading branch information
1 parent
724eca9
commit 28505c3
Showing
25 changed files
with
759 additions
and
322 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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,35 @@ | ||
#compdef uu_arch | ||
|
||
autoload -U is-at-least | ||
|
||
_uu_arch() { | ||
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[@]}" \ | ||
'-h[Print help]' \ | ||
'--help[Print help]' \ | ||
'-V[Print version]' \ | ||
'--version[Print version]' \ | ||
&& ret=0 | ||
} | ||
|
||
(( $+functions[_uu_arch_commands] )) || | ||
_uu_arch_commands() { | ||
local commands; commands=() | ||
_describe -t commands 'uu_arch commands' commands "$@" | ||
} | ||
|
||
if [ "$funcstack[1]" = "_uu_arch" ]; then | ||
_uu_arch "$@" | ||
else | ||
compdef _uu_arch uu_arch | ||
fi |
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,34 @@ | ||
|
||
using namespace System.Management.Automation | ||
using namespace System.Management.Automation.Language | ||
|
||
Register-ArgumentCompleter -Native -CommandName 'uu_arch' -ScriptBlock { | ||
param($wordToComplete, $commandAst, $cursorPosition) | ||
|
||
$commandElements = $commandAst.CommandElements | ||
$command = @( | ||
'uu_arch' | ||
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) { | ||
'uu_arch' { | ||
[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 | ||
} |
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,53 @@ | ||
#compdef uu_cat | ||
|
||
autoload -U is-at-least | ||
|
||
_uu_cat() { | ||
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[@]}" \ | ||
'-A[equivalent to -vET]' \ | ||
'--show-all[equivalent to -vET]' \ | ||
'-b[number nonempty output lines, overrides -n]' \ | ||
'--number-nonblank[number nonempty output lines, overrides -n]' \ | ||
'-e[equivalent to -vE]' \ | ||
'-E[display \$ at end of each line]' \ | ||
'--show-ends[display \$ at end of each line]' \ | ||
'-n[number all output lines]' \ | ||
'--number[number all output lines]' \ | ||
'-s[suppress repeated empty output lines]' \ | ||
'--squeeze-blank[suppress repeated empty output lines]' \ | ||
'-t[equivalent to -vT]' \ | ||
'-T[display TAB characters at ^I]' \ | ||
'--show-tabs[display TAB characters at ^I]' \ | ||
'-v[use ^ and M- notation, except for LF (\\n) and TAB (\\t)]' \ | ||
'--show-nonprinting[use ^ and M- notation, except for LF (\\n) and TAB (\\t)]' \ | ||
'-u[(ignored)]' \ | ||
'-h[Print help]' \ | ||
'--help[Print help]' \ | ||
'-V[Print version]' \ | ||
'--version[Print version]' \ | ||
'::file:_files' \ | ||
&& ret=0 | ||
} | ||
|
||
(( $+functions[_uu_cat_commands] )) || | ||
_uu_cat_commands() { | ||
local commands; commands=() | ||
_describe -t commands 'uu_cat commands' commands "$@" | ||
} | ||
|
||
if [ "$funcstack[1]" = "_uu_cat" ]; then | ||
_uu_cat "$@" | ||
else | ||
compdef _uu_cat uu_cat | ||
fi |
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,51 @@ | ||
|
||
using namespace System.Management.Automation | ||
using namespace System.Management.Automation.Language | ||
|
||
Register-ArgumentCompleter -Native -CommandName 'uu_cat' -ScriptBlock { | ||
param($wordToComplete, $commandAst, $cursorPosition) | ||
|
||
$commandElements = $commandAst.CommandElements | ||
$command = @( | ||
'uu_cat' | ||
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) { | ||
'uu_cat' { | ||
[CompletionResult]::new('-A', 'A ', [CompletionResultType]::ParameterName, 'equivalent to -vET') | ||
[CompletionResult]::new('--show-all', 'show-all', [CompletionResultType]::ParameterName, 'equivalent to -vET') | ||
[CompletionResult]::new('-b', 'b', [CompletionResultType]::ParameterName, 'number nonempty output lines, overrides -n') | ||
[CompletionResult]::new('--number-nonblank', 'number-nonblank', [CompletionResultType]::ParameterName, 'number nonempty output lines, overrides -n') | ||
[CompletionResult]::new('-e', 'e', [CompletionResultType]::ParameterName, 'equivalent to -vE') | ||
[CompletionResult]::new('-E', 'E ', [CompletionResultType]::ParameterName, 'display $ at end of each line') | ||
[CompletionResult]::new('--show-ends', 'show-ends', [CompletionResultType]::ParameterName, 'display $ at end of each line') | ||
[CompletionResult]::new('-n', 'n', [CompletionResultType]::ParameterName, 'number all output lines') | ||
[CompletionResult]::new('--number', 'number', [CompletionResultType]::ParameterName, 'number all output lines') | ||
[CompletionResult]::new('-s', 's', [CompletionResultType]::ParameterName, 'suppress repeated empty output lines') | ||
[CompletionResult]::new('--squeeze-blank', 'squeeze-blank', [CompletionResultType]::ParameterName, 'suppress repeated empty output lines') | ||
[CompletionResult]::new('-t', 't', [CompletionResultType]::ParameterName, 'equivalent to -vT') | ||
[CompletionResult]::new('-T', 'T ', [CompletionResultType]::ParameterName, 'display TAB characters at ^I') | ||
[CompletionResult]::new('--show-tabs', 'show-tabs', [CompletionResultType]::ParameterName, 'display TAB characters at ^I') | ||
[CompletionResult]::new('-v', 'v', [CompletionResultType]::ParameterName, 'use ^ and M- notation, except for LF (\n) and TAB (\t)') | ||
[CompletionResult]::new('--show-nonprinting', 'show-nonprinting', [CompletionResultType]::ParameterName, 'use ^ and M- notation, except for LF (\n) and TAB (\t)') | ||
[CompletionResult]::new('-u', 'u', [CompletionResultType]::ParameterName, '(ignored)') | ||
[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 | ||
} |
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,38 @@ | ||
_uu_arch() { | ||
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="uu_arch" | ||
;; | ||
*) | ||
;; | ||
esac | ||
done | ||
|
||
case "${cmd}" in | ||
uu_arch) | ||
opts="-h -V --help --version" | ||
if [[ ${cur} == -* || ${COMP_CWORD} -eq 1 ]] ; then | ||
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) | ||
return 0 | ||
fi | ||
case "${prev}" in | ||
*) | ||
COMPREPLY=() | ||
;; | ||
esac | ||
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) | ||
return 0 | ||
;; | ||
esac | ||
} | ||
|
||
complete -F _uu_arch -o nosort -o bashdefault -o default uu_arch |
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,28 @@ | ||
|
||
use builtin; | ||
use str; | ||
|
||
set edit:completion:arg-completer[uu_arch] = {|@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 = 'uu_arch' | ||
for word $words[1..-1] { | ||
if (str:has-prefix $word '-') { | ||
break | ||
} | ||
set command = $command';'$word | ||
} | ||
var completions = [ | ||
&'uu_arch'= { | ||
cand -h 'Print help' | ||
cand --help 'Print help' | ||
cand -V 'Print version' | ||
cand --version 'Print version' | ||
} | ||
] | ||
$completions[$command] | ||
} |
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,2 @@ | ||
complete -c uu_arch -s h -l help -d 'Print help' | ||
complete -c uu_arch -s V -l version -d 'Print version' |
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,38 @@ | ||
_uu_cat() { | ||
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="uu_cat" | ||
;; | ||
*) | ||
;; | ||
esac | ||
done | ||
|
||
case "${cmd}" in | ||
uu_cat) | ||
opts="-A -b -e -E -n -s -t -T -v -u -h -V --show-all --number-nonblank --show-ends --number --squeeze-blank --show-tabs --show-nonprinting --help --version [file]..." | ||
if [[ ${cur} == -* || ${COMP_CWORD} -eq 1 ]] ; then | ||
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) | ||
return 0 | ||
fi | ||
case "${prev}" in | ||
*) | ||
COMPREPLY=() | ||
;; | ||
esac | ||
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) | ||
return 0 | ||
;; | ||
esac | ||
} | ||
|
||
complete -F _uu_cat -o nosort -o bashdefault -o default uu_cat |
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,45 @@ | ||
|
||
use builtin; | ||
use str; | ||
|
||
set edit:completion:arg-completer[uu_cat] = {|@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 = 'uu_cat' | ||
for word $words[1..-1] { | ||
if (str:has-prefix $word '-') { | ||
break | ||
} | ||
set command = $command';'$word | ||
} | ||
var completions = [ | ||
&'uu_cat'= { | ||
cand -A 'equivalent to -vET' | ||
cand --show-all 'equivalent to -vET' | ||
cand -b 'number nonempty output lines, overrides -n' | ||
cand --number-nonblank 'number nonempty output lines, overrides -n' | ||
cand -e 'equivalent to -vE' | ||
cand -E 'display $ at end of each line' | ||
cand --show-ends 'display $ at end of each line' | ||
cand -n 'number all output lines' | ||
cand --number 'number all output lines' | ||
cand -s 'suppress repeated empty output lines' | ||
cand --squeeze-blank 'suppress repeated empty output lines' | ||
cand -t 'equivalent to -vT' | ||
cand -T 'display TAB characters at ^I' | ||
cand --show-tabs 'display TAB characters at ^I' | ||
cand -v 'use ^ and M- notation, except for LF (\n) and TAB (\t)' | ||
cand --show-nonprinting 'use ^ and M- notation, except for LF (\n) and TAB (\t)' | ||
cand -u '(ignored)' | ||
cand -h 'Print help' | ||
cand --help 'Print help' | ||
cand -V 'Print version' | ||
cand --version 'Print version' | ||
} | ||
] | ||
$completions[$command] | ||
} |
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,12 @@ | ||
complete -c uu_cat -s A -l show-all -d 'equivalent to -vET' | ||
complete -c uu_cat -s b -l number-nonblank -d 'number nonempty output lines, overrides -n' | ||
complete -c uu_cat -s e -d 'equivalent to -vE' | ||
complete -c uu_cat -s E -l show-ends -d 'display $ at end of each line' | ||
complete -c uu_cat -s n -l number -d 'number all output lines' | ||
complete -c uu_cat -s s -l squeeze-blank -d 'suppress repeated empty output lines' | ||
complete -c uu_cat -s t -d 'equivalent to -vT' | ||
complete -c uu_cat -s T -l show-tabs -d 'display TAB characters at ^I' | ||
complete -c uu_cat -s v -l show-nonprinting -d 'use ^ and M- notation, except for LF (\\n) and TAB (\\t)' | ||
complete -c uu_cat -s u -d '(ignored)' | ||
complete -c uu_cat -s h -l help -d 'Print help' | ||
complete -c uu_cat -s V -l version -d 'Print version' |
Oops, something went wrong.