Completing in the Eshell or Shell
When completing in the Eshell I recommend conservative local settings without auto completion, such that the completion behavior is similar to widely used shells like Bash, Zsh or Fish.
(add-hook 'eshell-mode-hook (lambda ()
(setq-local corfu-auto nil)
(corfu-mode)))When pressing ‘RET’ while the Corfu popup is visible, the corfu-insert command will be invoked. This command does inserts the currently selected candidate, but it does not send the prompt input to Eshell or the Comint process. Therefore you often have to press ‘RET’ twice which feels like an unnecessary double confirmation. Fortunately it is easy to improve this by using the command corfu-send instead.
(keymap-set corfu-map "RET" #'corfu-send)Shell completion uses the flexible Pcomplete mechanism internally, which allows you to program the completions per shell command. If you want to know more, look into this blog post, which shows how to configure Pcomplete for git commands. Pcomplete offers the ‘pcomplete-from-help’ function which parses the --help output of a command and produces completions for command line options. In the past, before Emacs 29, Pcomplete had a few bugs, which had to be worked around using the Cape library (Completion at point extensions). In case you discover any remaining Pcomplete issues, please report them upstream.