Skip to content

Commit

Permalink
Added completions
Browse files Browse the repository at this point in the history
  • Loading branch information
Misterio77 committed Sep 18, 2020
1 parent 96c1403 commit 72eeb4d
Show file tree
Hide file tree
Showing 4 changed files with 169 additions and 33 deletions.
64 changes: 31 additions & 33 deletions completions/bash
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ _flavours() {
current)
cmd+="__current"
;;
info)
cmd+="__info"
;;
list)
cmd+="__list"
;;
Expand All @@ -35,29 +32,45 @@ _flavours() {

case "${cmd}" in
flavours)
opts=" -v -h -V --verbose --completions --help --version current list info apply update"
opts=" -v -c -d -h -V --verbose --config --directory --completions --help --version current list apply update"
if [[ ${cur} == -* || ${COMP_CWORD} -eq 1 ]] ; then
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
fi
case "${prev}" in

--config)
COMPREPLY=($(compgen -f "${cur}"))
return 0
;;
-c)
COMPREPLY=($(compgen -f "${cur}"))
return 0
;;
--directory)
COMPREPLY=($(compgen -f "${cur}"))
return 0
;;
-d)
COMPREPLY=($(compgen -f "${cur}"))
return 0
;;
--completions)
COMPREPLY=($(compgen -W "bash elvish fish powershell zsh" -- ${cur}))
COMPREPLY=($(compgen -W "bash elvish fish powershell zsh" -- "${cur}"))
return 0
;;
*)
COMPREPLY=()
;;
esac
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
;;

flavours__apply)
opts=" -h -V --help --version $(flavours list) "
opts=" -h --help <pattern>... "
if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
fi
case "${prev}" in
Expand All @@ -66,28 +79,13 @@ _flavours() {
COMPREPLY=()
;;
esac
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
;;
flavours__current)
opts=" -h --help "
if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
return 0
fi
case "${prev}" in

*)
COMPREPLY=()
;;
esac
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
return 0
;;
flavours__info)
opts=" -h -V --help --version $(flavours list) "
if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
fi
case "${prev}" in
Expand All @@ -96,13 +94,13 @@ _flavours() {
COMPREPLY=()
;;
esac
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
;;
flavours__list)
opts=" -l -h -V --lines --help --version <pattern>... "
opts=" -l -h --lines --help <pattern>... "
if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
fi
case "${prev}" in
Expand All @@ -111,13 +109,13 @@ _flavours() {
COMPREPLY=()
;;
esac
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
;;
flavours__update)
opts=" -h -V --help --version lists schemes templates all"
opts=" -h --help <operation> "
if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
fi
case "${prev}" in
Expand All @@ -126,7 +124,7 @@ _flavours() {
COMPREPLY=()
;;
esac
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
;;
esac
Expand Down
54 changes: 54 additions & 0 deletions completions/elvish
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@

edit:completion:arg-completer[flavours] = [@words]{
fn spaces [n]{
repeat $n ' ' | joins ''
}
fn cand [text desc]{
edit:complex-candidate $text &display-suffix=' '(spaces (- 14 (wcswidth $text)))$desc
}
command = 'flavours'
for word $words[1:-1] {
if (has-prefix $word '-') {
break
}
command = $command';'$word
}
completions = [
&'flavours'= {
cand -c 'Specify a configuration file (Defaults to ~/.config/flavours/config.toml)'
cand --config 'Specify a configuration file (Defaults to ~/.config/flavours/config.toml)'
cand -d 'Specify a data directory (Defaults to ~/.local/share/flavours)'
cand --directory 'Specify a data directory (Defaults to ~/.local/share/flavours)'
cand --completions 'Generates completion for given shell, outputs to stdout'
cand -v 'Be more verbose'
cand --verbose 'Be more verbose'
cand -h 'Prints help information'
cand --help 'Prints help information'
cand -V 'Prints version information'
cand --version 'Prints version information'
cand current 'Prints last applied scheme name'
cand list 'Prints a list with all matching schemes'
cand apply 'Applies scheme, according to user configuration'
cand update 'Downloads schemes, templates, or updates their lists (from repos specified in sources.yml)'
}
&'flavours;current'= {
cand -h 'Prints help information'
cand --help 'Prints help information'
}
&'flavours;list'= {
cand -l 'Print each scheme on its own line'
cand --lines 'Print each scheme on its own line'
cand -h 'Prints help information'
cand --help 'Prints help information'
}
&'flavours;apply'= {
cand -h 'Prints help information'
cand --help 'Prints help information'
}
&'flavours;update'= {
cand -h 'Prints help information'
cand --help 'Prints help information'
}
]
$completions[$command]
}
18 changes: 18 additions & 0 deletions completions/fish
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
complete -c flavours -n "__fish_use_subcommand" -s c -l config -d 'Specify a configuration file (Defaults to ~/.config/flavours/config.toml)' -r -F
complete -c flavours -n "__fish_use_subcommand" -s d -l directory -d 'Specify a data directory (Defaults to ~/.local/share/flavours)' -r -f -a "(__fish_complete_directories)"
complete -c flavours -n "__fish_use_subcommand" -l completions -d 'Generates completion for given shell, outputs to stdout' -r -f -a "bash elvish fish powershell zsh"
complete -c flavours -n "__fish_use_subcommand" -s v -l verbose -d 'Be more verbose'
complete -c flavours -n "__fish_use_subcommand" -s h -l help -d 'Prints help information'
complete -c flavours -n "__fish_use_subcommand" -s V -l version -d 'Prints version information'
complete -c flavours -n "__fish_use_subcommand" -f -a "current" -d 'Prints last applied scheme name'
complete -c flavours -n "__fish_use_subcommand" -f -a "list" -d 'Prints a list with all matching schemes'
complete -c flavours -n "__fish_use_subcommand" -f -a "apply" -d 'Applies scheme, according to user configuration'
complete -c flavours -n "__fish_use_subcommand" -f -a "update" -d 'Downloads schemes, templates, or updates their lists (from repos specified in sources.yml)'
complete -c flavours -n "__fish_seen_subcommand_from current" -s h -l help -d 'Prints help information'
complete -c flavours -n "__fish_seen_subcommand_from list" -d 'Scheme name or glob pattern to match when listing scheme(s). If ommited, defaults to * (all installed schemes).' -r -f
complete -c flavours -n "__fish_seen_subcommand_from list" -s l -l lines -d 'Print each scheme on its own line'
complete -c flavours -n "__fish_seen_subcommand_from list" -s h -l help -d 'Prints help information'
complete -c flavours -n "__fish_seen_subcommand_from apply" -d 'Scheme to be applied, supports glob. If more than one is specified (or if glob pattern matched more than one), chooses one randomly. If ommited, defaults to * (all schemes).' -r -f
complete -c flavours -n "__fish_seen_subcommand_from apply" -s h -l help -d 'Prints help information'
complete -c flavours -n "__fish_seen_subcommand_from update" -d 'Update sources lists from repositories or (re)download schemes/templates specified in the lists. Default repositories for lists, and the lists themselves, can be manually changed.' -r -f -a "lists schemes templates all"
complete -c flavours -n "__fish_seen_subcommand_from update" -s h -l help -d 'Prints help information'
66 changes: 66 additions & 0 deletions completions/powershell
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@

using namespace System.Management.Automation
using namespace System.Management.Automation.Language

Register-ArgumentCompleter -Native -CommandName 'flavours' -ScriptBlock {
param($wordToComplete, $commandAst, $cursorPosition)

$commandElements = $commandAst.CommandElements
$command = @(
'flavours'
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('-')) {
break
}
$element.Value
}) -join ';'

$completions = @(switch ($command) {
'flavours' {
[CompletionResult]::new('-c', 'c', [CompletionResultType]::ParameterName, 'Specify a configuration file (Defaults to ~/.config/flavours/config.toml)')
[CompletionResult]::new('--config', 'config', [CompletionResultType]::ParameterName, 'Specify a configuration file (Defaults to ~/.config/flavours/config.toml)')
[CompletionResult]::new('-d', 'd', [CompletionResultType]::ParameterName, 'Specify a data directory (Defaults to ~/.local/share/flavours)')
[CompletionResult]::new('--directory', 'directory', [CompletionResultType]::ParameterName, 'Specify a data directory (Defaults to ~/.local/share/flavours)')
[CompletionResult]::new('--completions', 'completions', [CompletionResultType]::ParameterName, 'Generates completion for given shell, outputs to stdout')
[CompletionResult]::new('-v', 'v', [CompletionResultType]::ParameterName, 'Be more verbose')
[CompletionResult]::new('--verbose', 'verbose', [CompletionResultType]::ParameterName, 'Be more verbose')
[CompletionResult]::new('-h', 'h', [CompletionResultType]::ParameterName, 'Prints help information')
[CompletionResult]::new('--help', 'help', [CompletionResultType]::ParameterName, 'Prints help information')
[CompletionResult]::new('-V', 'V', [CompletionResultType]::ParameterName, 'Prints version information')
[CompletionResult]::new('--version', 'version', [CompletionResultType]::ParameterName, 'Prints version information')
[CompletionResult]::new('current', 'current', [CompletionResultType]::ParameterValue, 'Prints last applied scheme name')
[CompletionResult]::new('list', 'list', [CompletionResultType]::ParameterValue, 'Prints a list with all matching schemes')
[CompletionResult]::new('apply', 'apply', [CompletionResultType]::ParameterValue, 'Applies scheme, according to user configuration')
[CompletionResult]::new('update', 'update', [CompletionResultType]::ParameterValue, 'Downloads schemes, templates, or updates their lists (from repos specified in sources.yml)')
break
}
'flavours;current' {
[CompletionResult]::new('-h', 'h', [CompletionResultType]::ParameterName, 'Prints help information')
[CompletionResult]::new('--help', 'help', [CompletionResultType]::ParameterName, 'Prints help information')
break
}
'flavours;list' {
[CompletionResult]::new('-l', 'l', [CompletionResultType]::ParameterName, 'Print each scheme on its own line')
[CompletionResult]::new('--lines', 'lines', [CompletionResultType]::ParameterName, 'Print each scheme on its own line')
[CompletionResult]::new('-h', 'h', [CompletionResultType]::ParameterName, 'Prints help information')
[CompletionResult]::new('--help', 'help', [CompletionResultType]::ParameterName, 'Prints help information')
break
}
'flavours;apply' {
[CompletionResult]::new('-h', 'h', [CompletionResultType]::ParameterName, 'Prints help information')
[CompletionResult]::new('--help', 'help', [CompletionResultType]::ParameterName, 'Prints help information')
break
}
'flavours;update' {
[CompletionResult]::new('-h', 'h', [CompletionResultType]::ParameterName, 'Prints help information')
[CompletionResult]::new('--help', 'help', [CompletionResultType]::ParameterName, 'Prints help information')
break
}
})

$completions.Where{ $_.CompletionText -like "$wordToComplete*" } |
Sort-Object -Property ListItemText
}

0 comments on commit 72eeb4d

Please sign in to comment.