Command line completion

Command-line completion is a feature in shells (Bash, Fish, Zsh, ...) to automatically complete a command, argument, or option. Usually, the completion is triggered by pressing the tab key once or twice after typing hledger. (The exact behavior may differ in shells other than Bash.)


The completions handle hledger's CLI:

Installation for end users

Completions are currently only implemented for the Bash shell.

Please check first if the completions for hledger are already installed on your distribution. Refer to the last paragraph of this section for how to test that.

To install the completions manually, follow this steps:

Example installation script:

curl https://raw.githubusercontent.com/simonmichael/hledger/master/shell-completion/hledger-completion.bash > ~/.hledger-completion.bash
echo 'source ~/.hledger-completion.bash' >> ~/.bashrc
bash  # open a new bash to try it

Now, try it by typing hledger (with a space after the command) and press the tab key twice. You should see a list of appropriate completions for hledger. Then you can type a part of one of the suggestions and press tab again to complete it. If you only see filenames, the completions are not correctly installed.

Completion scripts for other shells

You're welcome to add completion scripts for other shells (e.g. Fish or Zsh)! It should not be too hard. All available hledger options and commands are already there. Only the shell hooks and logic is missing.

Please refer to the README in the shell-completion folder.