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

Support more shells by shtab #546

Merged
merged 1 commit into from
Sep 5, 2022
Merged

Support more shells by shtab #546

merged 1 commit into from
Sep 5, 2022

Conversation

Freed-Wu
Copy link
Contributor

@Freed-Wu Freed-Wu commented Aug 28, 2022

Support more shells by shtab

The disadvantage is importing a new dependency. However, shtab can support more
shells (bash/zsh/tcsh, and fish/posh in plan), and it can provide an option
--print-completion for user and packager to generate shell completion and for
developer to test, so I think it may be acceptable.

❯ pudb3 --print-completion bash|sudo tee /usr/share/bash-completion/completions/pudb3
❯ pudb3 --print-completion zsh|sudo tee /usr/share/zsh/site-functions/_pudb3
❯ pudb3 --print-completion tcsh|sudo tee /etc/profile.d/pudb3.completion.csh

I have tested bash/zsh can work. (I don't have installed tcsh)

BTW, shtab has a bug for zsh, that is pudb3 has script_args which nargs is
argparse.REMINDER, but shtab cannot support.
I temporarily fix it in my fork and send a PR to shtab.

This is a version after fixing. You can put it directed to the correct
directory.

❯ pudb3 --print-completion zsh
#compdef pudb3

# AUTOMATCALLY GENERATED by `shtab`


_shtab_pudb3_commands() {
  local _commands=(
    
  )
  _describe 'pudb3 commands' _commands
}

_shtab_pudb3_options=(
  "(- : *)"{-h,--help}"[show this help message and exit]"
  "(- : *)--print-completion[print shell completion script]:print_completion:(bash zsh tcsh)"
  {-s,--steal-output}"[]"
  {-m,--module}"[Debug as module or package instead of as a script]"
  {-le,--log-errors}"[Log internal errors to the given file]:log_errors:_files"
  "--pre-run[Run command before each program run]:pre_run:_command_names -e"
  "(- : *)--version[show program\'s version number and exit]"
  "(-)*:Arguments to pass to script or module:_script_args"
)


_shtab_pudb3() {
  local context state line curcontext="$curcontext"

  local one_or_more='(-)*'
  local reminder='(*)'
  if ((${_shtab_you_get_options[(I)${(q)one_or_more}*]} + ${_shtab_you_get_options[(I)${(q)reminder}*]} == 0)); then  # noqa: E501
    _shtab_pudb3_options+=(': :_shtab_pudb3_commands' '*::: :->pudb3')
  fi
  _arguments -C $_shtab_pudb3_options

  case $state in
    pudb3)
      words=($line[1] "${words[@]}")
      (( CURRENT += 1 ))
      curcontext="${curcontext%:*:*}:_shtab_pudb3-$line[1]:"
      case $line[1] in
        
      esac
  esac
}

# Custom Preamble
_script_args() {
  _arguments -S -s '(-)1:script_args:_files -g *.py' '*: :_files'
}

# End Custom Preamble


typeset -A opt_args
_shtab_pudb3 "$@"

Result:

❯ pudb3 <TAB>  # complete *.py and dirs, because pudb3 must run a py file
script_args
debug_me.py     doc/            examples/       manual-tests/   pudb/           pudb.egg-info/  test/
❯ pudb3 pudb/debug_me.py <TAB>  # complete all files, because we don't know pudb/debug_me.py's command line usage
file
debug_me.py           examples/             MANIFEST.in           pudb/                 README.rst            setup.cfg             test/
doc/                  LICENSE               manual-tests/         pudb.egg-info/        requirements.dev.txt  setup.py              try-the-debugger.sh*

The test failed. However, I haven't change pudb/var_view.py. What happened?

./pudb/var_view.py:50:1: B024 PudbCollection is an abstract base class, but it has no abstract methods. Remember to use @abstractmethod, @abstractclassmethod and/or @abstractproperty decorators.
./pudb/var_view.py:83:1: B024 PudbSequence is an abstract base class, but it has no abstract methods. Remember to use @abstractmethod, @abstractclassmethod and/or @abstractproperty decorators.
./pudb/var_view.py:116:1: B024 PudbMapping is an abstract base class, but it has no abstract methods. Remember to use @abstractmethod, @abstractclassmethod and/or @abstractproperty decorators.

@inducer
Copy link
Owner

inducer commented Aug 31, 2022

It looks like much of the diff here consists of spurious white space changes from code reformatting, making it harder to review than necessary. Please refrain from making such changes, and undo the ones you've made. Thanks!

@inducer
Copy link
Owner

inducer commented Aug 31, 2022

Also, see the linter failures here.

@Freed-Wu
Copy link
Contributor Author

Freed-Wu commented Sep 4, 2022

OK. All checks have passed.

@inducer inducer enabled auto-merge (rebase) September 5, 2022 03:33
@inducer
Copy link
Owner

inducer commented Sep 5, 2022

This is nice. Thanks!

@inducer inducer merged commit 656b1d3 into inducer:main Sep 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants