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:

TERMINAL // BASH
1hugo completion bash | tee /etc/bash_completion.d/hugo
2source /etc/bash_completion.d/hugo

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

TERMINAL // BASH
1hugo completion bash > ~/.hugo_completion.sh
2echo "source ~/.hugo_completion.sh" >> ~/.bashrc
3source ~/.bashrc

2. Test Auto-Completion

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

TERMINAL // BASH
1hugo [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:

TERMINAL // BASH
1hugo server[TAB]

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

TERMINAL // BASH
1sudo apt install bash-completion  # Debian/Ubuntu
2sudo yum install bash-completion  # RHEL/CentOS
3brew install bash-completion      # macOS

After installation, reload your shell:

TERMINAL // BASH
1exec 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.

Enlarged QR Code