Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shell completions #86

Open
Freed-Wu opened this issue Apr 26, 2022 · 2 comments
Open

Shell completions #86

Freed-Wu opened this issue Apr 26, 2022 · 2 comments
Labels
enhancement New feature or request

Comments

@Freed-Wu
Copy link

How about add shell completions (bash/zsh/...) for this program just like other program?

Thanks.

@Freed-Wu Freed-Wu changed the title [feaure] Add shell completions [feature] Add shell completions Apr 26, 2022
@sharkdp sharkdp added the enhancement New feature or request label Apr 27, 2022
@sharkdp sharkdp changed the title [feature] Add shell completions Shell completions Apr 27, 2022
@sharkdp
Copy link
Owner

sharkdp commented Apr 27, 2022

Sure, sounds like a good idea.

@Freed-Wu
Copy link
Author

/usr/share/zsh/site-completions/_vivid

#compdef vivid

# This is based on _ip

local -a help
help=({-h,--help}':Prints help information')

local -a subcmd_files
subcmd_files=(/$'[^\0]##\0'/ ':file:file name:_files')

local -a subcmd_themes
subcmd_themes=(/$'[^\0]##\0'/ ":file:file name:($(command vivid themes))")

local -a subcmd_color_mode
subcmd_color_mode=(/$'[^\0]##\0'/ ':bit:(8 or 24):(8-bit 24-bit)')

local -a subcmds
subcmds=(
  'generate:Generate a LS_COLORS expression:$generate_cmds'
  'preview:Preview a given theme:$preview_cmds'
  'themes:Prints list of available themes:$themes_cmds'
  'help:Prints this message or the help of the given subcommand(s):$help_cmds'
)

# TODO: -h/-V disable all completions
local -a args
args=(
    # Command word.  Don't care what that is.
    /$'[^\0]#\0'/
)
_regex_words options "global options" \
  {-m,--color-mode}':Type of ANSI colors to be used (default, 24-bit):$subcmd_color_mode' \
  {-d,--database}':Path to filetypes database (filetypes.yml):$subcmd_files' \
  {-h,--help}':Prints help information' \
  {-V,--version}':Prints version information' \
  "$help[@]"
args+=("$reply[@]" "#")

local -a help_cmds
_regex_words \
  help-commands "help command" \
  ${subcmds%%:\$*}
help_cmds=("$reply[@]")

local -a themes_cmds
_regex_words \
  themes-commands "themes command" \
  "$help[@]"
themes_cmds=("$reply[@]")

local -a generate_cmds
generate_cmds=("(" $subcmd_themes "|" "$themes_cmds[@]" ")")

local -a preview_cmds
preview_cmds=("$generate_cmds[@]")

_regex_words commands "vivid command" \
  "$subcmds[@]"
args+=("$reply[@]")

_regex_arguments _vivid "${args[@]}"

_vivid "$@"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants