Skip to content

Complete notebook files in ZSH completion #86

@flying-sheep

Description

@flying-sheep

Hi, I’m trying to get jupyter notebook <tab> to show me both subcommands and notebook files as options here.

sadly i don’t seem to get what’s going on. whatever i tried, it throws errors at some point.

can somebody explain how it works? my progress:

  • ${(P)subcmd}} means “expand to the value of the variable named $subcmd”. i.e. if subcmd=notebook, it expands to $notebook, which is previously set to the output of $(jupyter notebook --help-all | grep … | sed …)

    so ${(P)subcmd}} aka $notebook (in one branch) holds the _arguments-formatted options to the notebook subcommand

  • _${subcmd}_cmds aka _notebook_cmds (in one branch) holds _describe output.

below my most recent attempts:

  1. eval-string

    _alternative \
      'notebook:notebook:_files -g "*.ipynb"' \
      "subcommands:subcommands:{_${subcmd}_cmds && echo ${(P)subcmd}}" && ret=0

    at some point it prints the stuff instead of using it… do i have to do this? is there a better way? _alternative … "subcommands:subcommands:{$(_${subcmd}_cmds && echo ${(P)subcmd})}"

  2. function

    _cmds_and_opts() {
        _${subcmd}_cmds
        echo ${(P)subcmd}
    }
    _alternative \
      'notebook:notebook:_files -g "*.ipynb"' \
      "subcommands:subcommands:_cmds_and_opts" && ret=0

    huh? can’t i redefine functions? or what’s wrong

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions