Hugo CLI autocompletion suggestions not appearing

Based on hugo gen autocomplete | Hugo I’m running this cmd to generate a zsh autocompletion file in /etc/:
sudo hugo gen autocomplete --type=zsh --completionfile=/etc/zsh-hugo-autocompletion
Note if I don’t include sudo I get ‘Error: invalid argument’ message.

I see the file is generated, but after I cd /etc/ I try sourcing the file a couple ways:
. ./zsh-hugo-autocompletion
source zsh-hugo-autocompletion
I then create a new terminal session a couple ways:

  • opening a new terminal in a different tab
  • quit the current terminal app and relaunch
  • quit current terminal app and try another

Afterwards autocompletion doesn’t seem to be working.

Specifically - after I type 'hugo ’ I’m thinking I should see command suggestions appear in the terminal after typing the space.

hugo env
hugo v0.83.1+extended darwin/amd64 BuildDate=unknown

Running on macOS Big Sur 11.4 and testing in iTerm2 and VSCode zsh terminals.

You misunderstand, how autocomplete files work. The directory /etc/ is a bad place for that file. Put it somewhere into your own user directory, depending on your system you should have a .config/ directory. Create a autocomplete directory there and in there add the file hugo creates.

Then look for a file that gets loaded when you start your terminal session. Depending on the system this can be anywhere from ~/.profile to a file specific to zah-shell. In there you add the line . autocompletefilepath.

This way it gets loaded each time you open a terminal session.

1 Like

Thanks for the insight! Got it working.

I’ve moved the output to ~/configs/autocompletions/_hugo for zsh fpath to find.

In my ~/.zshrc file I added the lines:

autoload -U compinit && compinit

After opening a new terminal and typing "hugo ", I can now hit the tab key and view a list of command suggestions. Then typing in a command and space if I hit the tab key again I can view more suggestions. Note it’s also possible to just hit the tab key twice instead of space+tab.

1 Like

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.