9

I'm trying to replicate some useful features from my work PC at home.

At work, bash will helpfully autocomplete tmux "sub-commands": e.g. I type "tmux new-s<tab>" and bash autocompletes that to "tmux new-session" (I hope "sub-command" is the right term). This doesn't happen on my home PC -- what can I do to set this up on my home PC?

I've looked around online and found some references to auto-complete within tmux, e.g. to auto-complete commands like move-window -- but that's not what I'm looking for.
I also found reference to a feature called "bash complete" -- but on my work PC, I don't find any reference to tmux in my ~/.bash_completion file or my /etc/bash_completion.d/ directory.

Can someone please explain either where/how else my work PC might have set up its tmux "sub-command" autocompletion (so that I can refer/learn from a working example), or how I can/should set this up?

Interesting side-note: both my work and home PCs autocomplete git "sub-commands"; e.g. typing "git clo<tab>" autocompletes to "git clone". I didn't do anything specific to set that up -- for both git and tmux, all I did as far as setup was "sudo apt install git" and "sudo apt install tmux", respectively.

2
  • Check output of complete -p tmux.
    – Cyrus
    Aug 14, 2020 at 19:13
  • @Cyrus - on both work and home PCs, complete -p tmux outputs "-bash: complete: tmux: no completion specification"
    – StoneThrow
    Aug 14, 2020 at 20:39

2 Answers 2

8

laktak's answer worked on my Ubuntu 22.04 desktop. I simply ran:

curl https://raw.githubusercontent.com/imomaliev/tmux-bash-completion/master/completions/tmux > ~/.bash_completion
3
  • works for me "Ubuntu 20.04.1 LTS" Feb 2, 2023 at 3:24
  • 2
    Works for me in Ubuntu 22.04 as well! I just copied the file in more dedicated folder like /etc/bash_completion.d/: curl https://raw.githubusercontent.com/imomaliev/tmux-bash-completion/master/completions/tmux | sudo tee /etc/bash_completion.d/tmux > /dev/null May 12, 2023 at 14:13
  • Beware that this overwrites anything you might have previously had in ~/.bash_completion Also, this only takes effect after doing something like . /etc/bash_completion, which is common in a ~/.bashrc.
    – nealmcb
    Jan 15 at 17:16
5

You can get your systems completion dir from pkg-config --variable=completionsdir bash-completion (/usr/share/bash-completion/completions/)

This is where dynamic completions are set up:

$ complete -p git
-bash: complete: git: no completion specification
$ git st<TAB>
st       stage    stash    status   sti
$ complete -p git
complete -o bashdefault -o default -o nospace -F __git_wrap__git_main git

If you want to set up tmux auto complete follow https://russellparker.me/post/2018/02/16/tmux-bash-autocomplete/

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .