Visitar URL original
Document oh-my-zsh workaround for completion support · Issue #716 · cli/cli · GitHub
The Wayback Machine - https://web.archive.org/web/20200530010420/https://github.com/cli/cli/issues/716
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

Document oh-my-zsh workaround for completion support #716

Open
diminutivesloop opened this issue Mar 30, 2020 · 10 comments
Open

Document oh-my-zsh workaround for completion support #716

diminutivesloop opened this issue Mar 30, 2020 · 10 comments
Labels

Comments

@diminutivesloop
Copy link

@diminutivesloop diminutivesloop commented Mar 30, 2020

Describe the bug

After following the instructions for enabling shell completion I still can’t get the completion functionality to work. I’ve tried both the eval and Homebrew options. I’m on Mac OS 10.15.4 using zsh with Oh My Zsh and gh version 0.6.2.

Steps to reproduce the behavior

  1. Add the Homebrew completion snippet to .zshrc. and open a new terminal.
  2. Type gh
  3. Press Tab
  4. Run eval "$(gh completion -s zsh)”
  5. Repeat steps 2-3

Expected vs actual behavior

I expect to see completion options for gh commands but instead I get my shell’s standard file path completion.

@diminutivesloop diminutivesloop added the bug label Mar 30, 2020
@mislav
Copy link
Member

@mislav mislav commented Mar 31, 2020 •

Hi, you seem to be on the right track, and I don't know why completions are not working for you.

  1. First of all, ensure that you have installed gh via Homebrew and that /usr/local/share/zsh/site-functions/_gh file is present (assuming that your Homebrew prefix is /usr/local)
  2. You do not need eval "$(gh completion -s zsh)” in your zshrc nor the current running shell. Those instructions are only applicable for bash
  3. Make sure to restart your shell after configuration changes

Let us know how it went!

@diminutivesloop
Copy link
Author

@diminutivesloop diminutivesloop commented Mar 31, 2020

So my Homebrew prefix is /usr/local/homebrew and I do have the file /usr/local/homebrew/share/zsh/site-functions/_gh. I don’t have eval "$(gh completion -s zsh)” in my .zshrc but even after restarting my terminal I still don’t get the completions.

@mislav
Copy link
Member

@mislav mislav commented Apr 1, 2020

When do you echo $fpath, does the /usr/local/homebrew/share/zsh/site-functions directory appear in there?

If not, then double-check that you have this line in your zshrc

FPATH=$(brew --prefix)/share/zsh/site-functions:$FPATH

If yes, then double-check that FPATH is changed before oh-my-zsh gets loaded.

@diminutivesloop
Copy link
Author

@diminutivesloop diminutivesloop commented Apr 1, 2020

Yes I see the site-functions path in $fpath. For reference here’s my .zshrc file:

export PATH=/usr/local/homebrew/bin:~/.local/bin:$PATH:/opt/local/bin:/usr/local/mysql/bin:~/Scripts:$GOPATH/bin

# Path to your oh-my-zsh installation.
export ZSH="/Users/nathanielpalmer/.oh-my-zsh"

# Set name of the theme to load --- if set to "random", it will
# load a random theme each time oh-my-zsh is loaded, in which case,
# to know which specific one was loaded, run: echo $RANDOM_THEME
# See https://github.com/ohmyzsh/ohmyzsh/wiki/Themes
# ZSH_THEME="agnoster"
ZSH_THEME="robbyrussell"

# Set list of themes to pick from when loading at random
# Setting this variable when ZSH_THEME=random will cause zsh to load
# a theme from this variable instead of looking in ~/.oh-my-zsh/themes/
# If set to an empty array, this variable will have no effect.
# ZSH_THEME_RANDOM_CANDIDATES=( "robbyrussell" "agnoster" )

# Uncomment the following line to use case-sensitive completion.
# CASE_SENSITIVE="true"

# Uncomment the following line to use hyphen-insensitive completion.
# Case-sensitive completion must be off. _ and - will be interchangeable.
# HYPHEN_INSENSITIVE="true"

# Uncomment the following line to disable bi-weekly auto-update checks.
# DISABLE_AUTO_UPDATE="true"

# Uncomment the following line to automatically update without prompting.
# DISABLE_UPDATE_PROMPT="true"

# Uncomment the following line to change how often to auto-update (in days).
# export UPDATE_ZSH_DAYS=13

# Uncomment the following line if pasting URLs and other text is messed up.
# DISABLE_MAGIC_FUNCTIONS=true

# Uncomment the following line to disable colors in ls.
# DISABLE_LS_COLORS="true"

# Uncomment the following line to disable auto-setting terminal title.
# DISABLE_AUTO_TITLE="true"

# Uncomment the following line to enable command auto-correction.
# ENABLE_CORRECTION="true"

# Uncomment the following line to display red dots whilst waiting for completion.
# COMPLETION_WAITING_DOTS="true"

# Uncomment the following line if you want to disable marking untracked files
# under VCS as dirty. This makes repository status check for large repositories
# much, much faster.
# DISABLE_UNTRACKED_FILES_DIRTY="true"

# Uncomment the following line if you want to change the command execution time
# stamp shown in the history command output.
# You can set one of the optional three formats:
# "mm/dd/yyyy"|"dd.mm.yyyy"|"yyyy-mm-dd"
# or set a custom format using the strftime function format specifications,
# see 'man strftime' for details.
# HIST_STAMPS="mm/dd/yyyy"

# Would you like to use another custom folder than $ZSH/custom?
# ZSH_CUSTOM=/path/to/new-custom-folder

# Which plugins would you like to load?
# Standard plugins can be found in ~/.oh-my-zsh/plugins/*
# Custom plugins may be added to ~/.oh-my-zsh/custom/plugins/
# Example format: plugins=(rails git textmate ruby lighthouse)
# Add wisely, as too many plugins slow down shell startup.
plugins=(
  vi-mode
  history-substring-search
  git
  zsh-nvm
  npm
  timer
  vscode
)

# Homebrew completions
if type brew &>/dev/null; then
  FPATH=$(brew --prefix)/share/zsh/site-functions:$FPATH

  autoload -Uz compinit
  compinit
fi

source $ZSH/oh-my-zsh.sh

# User configuration

# export MANPATH="/usr/local/man:$MANPATH"

# You may need to manually set your language environment
# export LANG=en_US.UTF-8

# Preferred editor for local and remote sessions
if [[ -n $SSH_CONNECTION ]]; then
  export EDITOR='vim'
else
  export EDITOR='code'
fi

# Compilation flags
# export ARCHFLAGS="-arch x86_64"

# Set personal aliases, overriding those provided by oh-my-zsh libs,
# plugins, and themes. Aliases can be placed here, though oh-my-zsh
# users are encouraged to define aliases within the ZSH_CUSTOM folder.
# For a full list of active aliases, run `alias`.
alias zshconfig="$EDITOR ~/.zshrc"
alias ohmyzsh="$EDITOR ~/.oh-my-zsh"
alias reload='source ~/.zshrc'

# Key Bindings
# bind UP and DOWN arrow keys
zmodload zsh/terminfo
bindkey "$terminfo[kcuu1]" history-substring-search-up
bindkey "$terminfo[kcud1]" history-substring-search-down

# bind k and j for VI mode
bindkey -M vicmd 'k' history-substring-search-up
bindkey -M vicmd 'j' history-substring-search-down

prompt_context(){}
@mislav
Copy link
Member

@mislav mislav commented Apr 2, 2020

@diminutivesloop Thank you for sharing. I see nothing wrong with your setup. The only thing I can suggest is temporarily replacing your zshrc with a minimal one that just modifies FPATH and turns on completions, nothing else, then see if that helps gh completions. If it does, then it is the extra stuff in your zshrc that sabotages it. If it never works in any scenario, then I'm at a loss— you could check other paths in FPATH for whether they contain an unrelated _gh file or try upgrading zsh 😕

@diminutivesloop
Copy link
Author

@diminutivesloop diminutivesloop commented Apr 2, 2020 •

Ok so the culprit appears to be this block of code in oh-my-zsh.sh:

if [[ $ZSH_DISABLE_COMPFIX != true ]]; then
  source $ZSH/lib/compfix.zsh
  # If completion insecurities exist, warn the user
  handle_completion_insecurities
  # Load only from secure directories
  compinit -i -C -d "${ZSH_COMPDUMP}"
else
  # If the user wants it, load from all found directories
  compinit -u -C -d "${ZSH_COMPDUMP}"
fi

It doesn’t matter whether ZSH_DISABLE_COMPFIX is set to true or false.

So I can fix the problem either by commenting out the above block of code or by adding rm -f ~/.zcompdump; compinit to .zshrc after source $ZSH/oh-my-zsh.sh to forcibly rebuild zcompdump as described in the Homebrew shell completion docs.

@SuaYoo
Copy link

@SuaYoo SuaYoo commented Apr 2, 2020

I have a similar setup. My workaround in .zshrc:

if type brew &>/dev/null; then
  FPATH=$(brew --prefix)/share/zsh/site-functions:$FPATH
  # Despite homebrew docs, running compinit after loading oh-my-zsh
  # seems to work, without the need to rebuild zcompdump
  #autoload -Uz compinit
  #compinit
fi

source $ZSH/oh-my-zsh.sh

if type brew &>/dev/null; then
  autoload -Uz compinit
  # Use `-u` to silence `zsh compinit: insecure directories`
  # See: https://stackoverflow.com/a/19601821/4378637
  compinit -u
fi
@mislav
Copy link
Member

@mislav mislav commented Apr 3, 2020 •

Thank you both for your input! When you do land on a working solution that feels alright, please report so here so we can update our documentation for setting up zsh 👌

@mislav mislav added docs and removed bug labels Apr 3, 2020
@diminutivesloop
Copy link
Author

@diminutivesloop diminutivesloop commented Apr 4, 2020 •

My solution is to add the following to .zshrc after source $ZSH/oh-my-zsh.sh:

if type brew &>/dev/null; then
  FPATH=$(brew --prefix)/share/zsh/site-functions:$FPATH

  autoload -Uz compinit
    rm -f ~/.zcompdump; compinit
fi

Unlike the solution provided by @SuaYoo I don’t pass the -u to compinit and I update FPATH after source $ZSH/oh-my-zsh.sh. I tried removing the line to rebuild zcompdump but whenever I did that it broke other completions such as those provided by the npm plugin.

@vilmibm
Copy link
Member

@vilmibm vilmibm commented May 13, 2020

It sounds like this is worth documenting in the manual area for gh completion.

@vilmibm vilmibm changed the title can’t get completions to work Document oh-my-zsh workaround for completion support May 13, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants
You can’t perform that action at this time.