add shell completion

parent 193b594a
ximperconf
/ximperconf
vendor/
builddir/
\ No newline at end of file
install_data(
'ximperconf.bash',
install_dir: join_paths(get_option('datadir'), 'bash-completion/completions'),
install_tag: 'runtime',
rename: 'ximperconf',
)
install_data(
'ximperconf.zsh',
install_dir: join_paths(get_option('datadir'), 'zsh/site-functions'),
install_tag: 'runtime',
rename: '_ximperconf',
)
install_data(
'ximperconf.fish',
install_dir: join_paths(get_option('datadir'), 'fish/vendor_completions.d'),
install_tag: 'runtime',
)
#!/bin/bash
# This is a shell completion script auto-generated by https://github.com/urfave/cli for bash.
# Macs have bash3 for which the bash-completion package doesn't include
# _init_completion. This is a minimal version of that function.
__ximperconf_init_completion() {
COMPREPLY=()
_get_comp_words_by_ref "$@" cur prev words cword
}
__ximperconf_bash_autocomplete() {
if [[ "${COMP_WORDS[0]}" != "source" ]]; then
local cur opts base words
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
if declare -F _init_completion >/dev/null 2>&1; then
_init_completion -n "=:" || return
else
__ximperconf_init_completion -n "=:" || return
fi
words=("${words[@]:0:$cword}")
requestComp="${words[*]} ${cur} --generate-shell-completion"
opts=$(eval "${requestComp}" 2>/dev/null)
COMPREPLY=($(compgen -W "${opts}" -- ${cur}))
return 0
fi
}
complete -o bashdefault -o default -o nospace -F __ximperconf_bash_autocomplete ximperconf
# ximperconf fish shell completion
function __fish_ximperconf_no_subcommand --description 'Test if there has been any subcommand yet'
for i in (commandline -opc)
if contains -- $i repo hyprland help h completion
return 1
end
end
return 0
end
function __fish_ximperconf_complete
set -l cmd (commandline -opc)
set -l current (commandline -ct)
if test (count $cmd) -gt 1
set -l args $cmd[2..-1]
ximperconf $args $current --generate-shell-completion 2>/dev/null
end
end
complete -c ximperconf -n '__fish_seen_subcommand_from hyprland; and __fish_seen_subcommand_from var; and __fish_seen_subcommand_from get' -f -a '(__fish_ximperconf_complete)'
complete -c ximperconf -n '__fish_seen_subcommand_from hyprland; and __fish_seen_subcommand_from var; and __fish_seen_subcommand_from unset' -f -a '(__fish_ximperconf_complete)'
complete -c ximperconf -n '__fish_seen_subcommand_from hyprland; and __fish_seen_subcommand_from module; and __fish_seen_subcommand_from enable' -f -a '(__fish_ximperconf_complete)'
complete -c ximperconf -n '__fish_seen_subcommand_from hyprland; and __fish_seen_subcommand_from module; and __fish_seen_subcommand_from disable' -f -a '(__fish_ximperconf_complete)'
complete -c ximperconf -n '__fish_seen_subcommand_from hyprland; and __fish_seen_subcommand_from module; and __fish_seen_subcommand_from toggle' -f -a '(__fish_ximperconf_complete)'
complete -c ximperconf -n '__fish_ximperconf_no_subcommand' -f -l help -s h -d 'show help'
complete -c ximperconf -n '__fish_ximperconf_no_subcommand' -f -l version -s v -d 'print the version'
complete -x -c ximperconf -n '__fish_ximperconf_no_subcommand' -a 'repo' -d 'Ximper repos'
complete -c ximperconf -n '__fish_seen_subcommand_from repo' -f -l help -s h -d 'show help'
complete -x -c ximperconf -n '__fish_seen_subcommand_from repo; and not __fish_seen_subcommand_from deferred' -a 'deferred' -d 'Deferred repo'
complete -c ximperconf -n '__fish_seen_subcommand_from repo; and __fish_seen_subcommand_from deferred' -f -l help -s h -d 'show help'
complete -x -c ximperconf -n '__fish_seen_subcommand_from repo; and __fish_seen_subcommand_from deferred; and not __fish_seen_subcommand_from info date last-update' -a 'info' -d 'Deferred repo info'
complete -c ximperconf -n '__fish_seen_subcommand_from repo; and __fish_seen_subcommand_from deferred; and __fish_seen_subcommand_from info' -f -l help -s h -d 'show help'
complete -x -c ximperconf -n '__fish_seen_subcommand_from repo; and __fish_seen_subcommand_from deferred; and not __fish_seen_subcommand_from info date last-update' -a 'date' -d 'Sisyphus archive date'
complete -c ximperconf -n '__fish_seen_subcommand_from repo; and __fish_seen_subcommand_from deferred; and __fish_seen_subcommand_from date' -f -l help -s h -d 'show help'
complete -x -c ximperconf -n '__fish_seen_subcommand_from repo; and __fish_seen_subcommand_from deferred; and not __fish_seen_subcommand_from info date last-update' -a 'last-update' -d 'Date of last update'
complete -c ximperconf -n '__fish_seen_subcommand_from repo; and __fish_seen_subcommand_from deferred; and __fish_seen_subcommand_from last-update' -f -l help -s h -d 'show help'
complete -x -c ximperconf -n '__fish_ximperconf_no_subcommand' -a 'hyprland' -d 'Hyprland Management'
complete -c ximperconf -n '__fish_seen_subcommand_from hyprland' -f -l help -s h -d 'show help'
complete -x -c ximperconf -n '__fish_seen_subcommand_from hyprland; and not __fish_seen_subcommand_from check module var' -a 'check' -d 'Check the Hyprland config'
complete -c ximperconf -n '__fish_seen_subcommand_from hyprland; and __fish_seen_subcommand_from check' -f -l help -s h -d 'show help'
complete -x -c ximperconf -n '__fish_seen_subcommand_from hyprland; and not __fish_seen_subcommand_from check module var' -a 'module' -d 'Hyprland modules'
complete -c ximperconf -n '__fish_seen_subcommand_from hyprland; and __fish_seen_subcommand_from module' -f -l user -s u -d 'use user modules'
complete -c ximperconf -n '__fish_seen_subcommand_from hyprland; and __fish_seen_subcommand_from module' -f -l help -s h -d 'show help'
complete -x -c ximperconf -n '__fish_seen_subcommand_from hyprland; and __fish_seen_subcommand_from module; and not __fish_seen_subcommand_from status info enable disable toggle' -a 'status' -d 'Hyprland module status'
complete -c ximperconf -n '__fish_seen_subcommand_from hyprland; and __fish_seen_subcommand_from module; and __fish_seen_subcommand_from status' -f -l help -s h -d 'show help'
complete -x -c ximperconf -n '__fish_seen_subcommand_from hyprland; and __fish_seen_subcommand_from module; and not __fish_seen_subcommand_from status info enable disable toggle' -a 'info' -d 'Information about modules'
complete -c ximperconf -n '__fish_seen_subcommand_from hyprland; and __fish_seen_subcommand_from module; and __fish_seen_subcommand_from info' -f -l filter -s f -r -d 'status filter'
complete -c ximperconf -n '__fish_seen_subcommand_from hyprland; and __fish_seen_subcommand_from module; and __fish_seen_subcommand_from info' -f -l help -s h -d 'show help'
complete -x -c ximperconf -n '__fish_seen_subcommand_from hyprland; and __fish_seen_subcommand_from module; and not __fish_seen_subcommand_from status info enable disable toggle' -a 'enable' -d 'enable module'
complete -c ximperconf -n '__fish_seen_subcommand_from hyprland; and __fish_seen_subcommand_from module; and __fish_seen_subcommand_from enable' -f -l help -s h -d 'show help'
complete -x -c ximperconf -n '__fish_seen_subcommand_from hyprland; and __fish_seen_subcommand_from module; and not __fish_seen_subcommand_from status info enable disable toggle' -a 'disable' -d 'disable module'
complete -c ximperconf -n '__fish_seen_subcommand_from hyprland; and __fish_seen_subcommand_from module; and __fish_seen_subcommand_from disable' -f -l help -s h -d 'show help'
complete -x -c ximperconf -n '__fish_seen_subcommand_from hyprland; and __fish_seen_subcommand_from module; and not __fish_seen_subcommand_from status info enable disable toggle' -a 'toggle' -d 'toggle module'
complete -c ximperconf -n '__fish_seen_subcommand_from hyprland; and __fish_seen_subcommand_from module; and __fish_seen_subcommand_from toggle' -f -l help -s h -d 'show help'
complete -x -c ximperconf -n '__fish_seen_subcommand_from hyprland; and not __fish_seen_subcommand_from check module var' -a 'var' -d 'Hyprland vars'
complete -c ximperconf -n '__fish_seen_subcommand_from hyprland; and __fish_seen_subcommand_from var' -f -l help -s h -d 'show help'
complete -x -c ximperconf -n '__fish_seen_subcommand_from hyprland; and __fish_seen_subcommand_from var; and not __fish_seen_subcommand_from list info get set unset' -a 'list' -d 'vars list'
complete -c ximperconf -n '__fish_seen_subcommand_from hyprland; and __fish_seen_subcommand_from var; and __fish_seen_subcommand_from list' -f -l help -s h -d 'show help'
complete -x -c ximperconf -n '__fish_seen_subcommand_from hyprland; and __fish_seen_subcommand_from var; and not __fish_seen_subcommand_from list info get set unset' -a 'info' -d 'vars info'
complete -c ximperconf -n '__fish_seen_subcommand_from hyprland; and __fish_seen_subcommand_from var; and __fish_seen_subcommand_from info' -f -l help -s h -d 'show help'
complete -x -c ximperconf -n '__fish_seen_subcommand_from hyprland; and __fish_seen_subcommand_from var; and not __fish_seen_subcommand_from list info get set unset' -a 'get' -d 'get var value'
complete -c ximperconf -n '__fish_seen_subcommand_from hyprland; and __fish_seen_subcommand_from var; and __fish_seen_subcommand_from get' -f -l help -s h -d 'show help'
complete -x -c ximperconf -n '__fish_seen_subcommand_from hyprland; and __fish_seen_subcommand_from var; and not __fish_seen_subcommand_from list info get set unset' -a 'set' -d 'set var value'
complete -c ximperconf -n '__fish_seen_subcommand_from hyprland; and __fish_seen_subcommand_from var; and __fish_seen_subcommand_from set' -f -l help -s h -d 'show help'
complete -x -c ximperconf -n '__fish_seen_subcommand_from hyprland; and __fish_seen_subcommand_from var; and not __fish_seen_subcommand_from list info get set unset' -a 'unset' -d 'unset var'
complete -c ximperconf -n '__fish_seen_subcommand_from hyprland; and __fish_seen_subcommand_from var; and __fish_seen_subcommand_from unset' -f -l help -s h -d 'show help'
complete -x -c ximperconf -n '__fish_ximperconf_no_subcommand' -a 'help' -d 'show help'
complete -c ximperconf -n '__fish_seen_subcommand_from completion' -f -l help -s h -d 'show help'
complete -x -c ximperconf -n '__fish_seen_subcommand_from completion; and not __fish_seen_subcommand_from help h' -a 'help' -d 'Shows a list of commands or help for one command'
#compdef ximperconf
compdef _ximperconf ximperconf
# This is a shell completion script auto-generated by https://github.com/urfave/cli for zsh.
_ximperconf() {
local -a opts # Declare a local array
local current
current=${words[-1]} # -1 means "the last element"
opts=("${(@f)$(${words[@]:0:#words[@]-1} ${current} --generate-shell-completion)}")
if [[ "${opts[1]}" != "" ]]; then
_describe 'values' opts
else
_files
fi
}
# Don't run the completion function when being source-ed or eval-ed.
# See https://github.com/urfave/cli/issues/1874 for discussion.
if [ "$funcstack[1]" = "_ximperconf" ]; then
_ximperconf
fi
package hyprland
import (
"context"
"fmt"
"ximperconf/config"
"github.com/urfave/cli/v3"
......@@ -49,22 +51,25 @@ func CommandList() *cli.Command {
Action: HyprlandInfoModulesCommand,
},
{
Name: "enable",
Usage: "enable module",
ArgsUsage: "module",
Action: HyprlandModuleEnableCommand,
Name: "enable",
Usage: "enable module",
ArgsUsage: "module",
Action: HyprlandModuleEnableCommand,
ShellComplete: ShellCompleteModule("enable"),
},
{
Name: "disable",
Usage: "disable module",
ArgsUsage: "module",
Action: HyprlandModuleDisableCommand,
Name: "disable",
Usage: "disable module",
ArgsUsage: "module",
Action: HyprlandModuleDisableCommand,
ShellComplete: ShellCompleteModule("disable"),
},
{
Name: "toggle",
Usage: "toggle module",
ArgsUsage: "module",
Action: HyprlandToggleModuleCommand,
Name: "toggle",
Usage: "toggle module",
ArgsUsage: "module",
Action: HyprlandToggleModuleCommand,
ShellComplete: ShellCompleteModule("all"),
},
},
},
......@@ -83,9 +88,10 @@ func CommandList() *cli.Command {
Action: HyprlandVarInfoCommand,
},
{
Name: "get",
Usage: "get var value",
Action: HyprlandVarGetCommand,
Name: "get",
Usage: "get var value",
Action: HyprlandVarGetCommand,
ShellComplete: ShellCompleteVarList,
},
{
Name: "set",
......@@ -93,12 +99,38 @@ func CommandList() *cli.Command {
Action: HyprlandVarSetCommand,
},
{
Name: "unset",
Usage: "unset var",
Action: HyprlandVarUnsetCommand,
Name: "unset",
Usage: "unset var",
Action: HyprlandVarUnsetCommand,
ShellComplete: ShellCompleteVarList,
},
},
},
},
}
}
func ShellCompleteVarList(ctx context.Context, cmd *cli.Command) {
if cmd.NArg() > 0 {
return
}
data, _ := hyprlandVarList()
for _, t := range data {
fmt.Println(t)
}
}
func ShellCompleteModule(filter string) func(ctx context.Context, cmd *cli.Command) {
return func(ctx context.Context, cmd *cli.Command) {
if cmd.NArg() > 0 {
return
}
userFlag := cmd.Bool("user")
data := hyprlandListModules(userFlag, filter)
for _, t := range data {
fmt.Println(t)
}
}
}
......@@ -32,7 +32,19 @@ func main() {
},
}
applyCommandSetting(rootCommand)
if err := rootCommand.Run(context.Background(), os.Args); err != nil {
os.Exit(1)
}
}
func applyCommandSetting(cliCommand *cli.Command) {
cliCommand.EnableShellCompletion = true
cliCommand.Suggest = true
cliCommand.HideHelpCommand = true
for _, sub := range cliCommand.Commands {
applyCommandSetting(sub)
}
}
......@@ -10,6 +10,10 @@ project('ximperconf',
go_root = run_command('printenv', 'GOROOT', check: false)
go_bin = go_root.returncode() != 0 ? find_program('go') : find_program(join_paths(go_root.stdout().strip(), 'bin', 'go'))
if get_option('shell_completion').enabled()
subdir('data/completion')
endif
custom_target(
'go-build',
build_by_default: true,
......
option('shell_completion', type: 'feature', value: 'enabled', description: 'Install shell completions')
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment