-
Notifications
You must be signed in to change notification settings - Fork 31
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
1 parent
96c1403
commit 72eeb4d
Showing
4 changed files
with
169 additions
and
33 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
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,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] | ||
} |
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,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' |
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,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 | ||
} |