Jaigarage

Hugo CLI

Enable Hugo Auto-Completion in Bash

Auto-completion for command-line interface (CLI) tools significantly enhances productivity by reducing typing, minimizing errors, and making it easier to discover available commands and options. If you want auto-completion for Hugo commands in the terminal (CLI), you can enable shell completion for Bash. Hugo provides built-in auto-completion scripts.

1. Generate and Apply Auto-Completion Script

Run the following command to generate the Hugo auto-completion script and apply it to your current session:

hugo completion bash | tee /etc/bash_completion.d/hugo
source /etc/bash_completion.d/hugo

If you don’t have root permissions, save it in your home directory instead:

hugo completion bash > ~/.hugo_completion.sh
echo "source ~/.hugo_completion.sh" >> ~/.bashrc
source ~/.bashrc

2. Test Auto-Completion

Once this is enabled, you can type hugo followed by pressing Tab to see available subcommands:

hugo [TAB][TAB]

This should suggest Hugo commands like new, server, config, etc.

3. Verify Auto-Completion

To check if auto-completion is working correctly, restart your terminal and try:

hugo server[TAB]

If completion does not work, ensure that Bash completion is installed:

sudo apt install bash-completion  # Debian/Ubuntu
sudo yum install bash-completion  # RHEL/CentOS
brew install bash-completion      # macOS

After installation, reload your shell:

exec bash

Conclusion

Enabling auto-completion for the Hugo CLI significantly boosts your productivity by streamlining command entry and reducing errors. With these steps, you can now navigate and manage your Hugo projects more efficiently, leveraging the full power of the command line with ease.

Tags: