Skip to content
Completion in shell buffers using native mechanisms
Emacs Lisp
Branch: master
Clone or download

Latest commit

Fetching latest commit…
Cannot retrieve the latest commit at this time.


Type Name Latest commit message Commit time
Failed to load latest commit information.

Native complete

This package interacts with a shell’s native completion functionality to provide the same completions in Emacs that you would get from the shell itself.


Currently this has been tested in

  • bash
  • csh
  • various CAD tool shells

Emacs setup

This package contains two completion functions; native-complete-at-point and company-native-complete. native-complete-at-point is a “completion at point function” (capf) and can be enabled by adding it to completion-at-point-functions in a shell buffer. company-native-complete is an asynchronous backend for the company completion framework. It is enabled by adding it to company-backends.

These functions look at the shell prompt or process name to determine which completion style to use. A completion style is the mechanism used to get the candidates from the native shell. Most shells support <tab> , but some shells won’t give you all the candidates consistently without using a different mechanism. There are currently the following completion styles:

M-* and echo

Which completion mechanism to use is determined by the shell-file-name, which is the executable that is used to start your shell. If the mechanism can’t be determined from that, or if you use subshells that are a different type, you can use native-complete-style-regex-alist. This variable is a alist of (prompt-regex . mechanism) pairs. If the prompt of the current shell matches prompt-regex then the corresponding mechanism will be used. For example, if your prompt is of the form user> and your shell is bash, you could you the following setting to configure that.

(setq native-complete-style-regex-alist '(("[a-z]+> " . bash)))

To test what completion style your shell is using, evaluate M-: (native-complete-get-completion-style) when the point is at an empty prompt. The default completion mechanism is tab.

native-complete-exclude-regex is a regular expression that is used to match potential candidates that should not appear in the final completion list.

prompt components in completion list

if you encouter an issue where parts of your shell prompt are showing up as completion candidates you can add a function to comint-redirect-filter-functions to remove the prompt line from the process output. See the doc string of that variable for more details.

shell setup


Run native-complete-setup-bash in Emacs before you load your first shell.

(with-eval-after-load 'shell

If the HISTCONTROL environment variable is not set to ignorespace or ignoreboth you will get a lot of garbage in your shell history.

export HISTCONTROL=ignoreboth


Make sure editing is enabled.

set edit
You can’t perform that action at this time.