zed-industries / zed

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
https://zed.dev
Other
49.76k stars 3.06k forks source link

Zsh completion #17413

Open haasn opened 2 months ago

haasn commented 2 months ago

Check for existing issues

Describe the feature

It would be useful to bundle Zed with a completion file definition for zsh, one of the most popular shells. This is because the default completion rules break the moment you include parameters like --wait in the invocation.

If applicable, add mockups / screenshots to help present your vision of the feature

ChatGPT offers us this skeleton:

#compdef zed

_arguments -s \
  '(-w --wait)'{-w,--wait}'[Wait for all of the given paths to be opened/closed before exiting]' \
  '(-a --add)'{-a,--add}'[Add files to the currently open workspace]' \
  '(-n --new)'{-n,--new}'[Create a new workspace]' \
  '(-v --version)'{-v,--version}'[Print Zed's version and the app path]' \
  '--foreground[Run zed in the foreground (useful for debugging)]' \
  '--zed=[Custom path to Zed.app or the zed binary]:path:_files' \
  '--dev-server-token=[Run zed in dev-server mode]:dev server token' \
  '(-h --help)'{-h,--help}'[Print help (see a summary with \'-h\')]' \
  '*:paths:->files_with_position'

# Complete paths with optional :line:row syntax
_files_with_position() {
  _files && compadd -S ':'
  if [[ $compstate[insert] == * ]]; then
    compstate[insert]=menu
  fi
}

Copilot meanwhile has this to offer:

#compdef zed

local -a args

args+=(
  '(-w --wait)'{-w,--wait}'[Wait for all of the given paths to be opened/closed before exiting]'
  '(-a --add)'{-a,--add}'[Add files to the currently open workspace]'
  '(-n --new)'{-n,--new}'[Create a new workspace]'
  '(-v --version)'{-v,--version}'[Print Zed\'s version and the app path]'
  '--foreground[Run zed in the foreground (useful for debugging)]'
  '--zed[Custom path to Zed.app or the zed binary]:ZED:_files'
  '--dev-server-token[Run zed in dev-server mode]:DEV_SERVER_TOKEN:_files'
  '(-h --help)'{-h,--help}'[Print help (see a summary with \'-h\')]'
  '*:PATHS_WITH_POSITION:_files'
)

_arguments -s $args
haasn commented 2 months ago

FYI, you can work around the motivating issue by adding this to your .zshrc:

compdef _gnu_generic zed