Sample Header Ad - 728x90

Unix & Linux Stack Exchange

Q&A for users of Linux, FreeBSD and other Unix-like operating systems

Latest Questions

-5 votes
2 answers
104 views
Why is arch linux bash better than Ubuntu bash?
Both of them use bash, but the one used on arch linux has way better auto-completion. But why is that? Both of them claim to use normal Bash, so how can that be true? ---- I forgot to clarify that what I meant by Arch linux was it's installation ISO. I have never tried out the actual Arch linux. Als...
Both of them use bash, but the one used on arch linux has way better auto-completion. But why is that? Both of them claim to use normal Bash, so how can that be true? ---- I forgot to clarify that what I meant by Arch linux was it's installation ISO. I have never tried out the actual Arch linux. Also, I have tried ZSH and the auto-completion on ZSH seems similar to the arch bash's. Is it because of an additional package? --- The differences between Arch's Bash and Ubuntu's Bash is noticeable enough to understand what I'm talking about. Here is a little example: cat ./ (The command is not entered) - **Arch's Bash**: When I press TAB, all possible options are shown in a nice and very organized way, and when I press the down and up arrow keys, it allows me to select from those options. - **Ubuntu's Bash**: When I press TAB, all possible options are shown, sometimes in a nice and fairly organized way, but arrow keys just scroll between history of commands, not options. Not convenient. This is one way Arch's Bash is better than Ubuntu's Bash. This is assuming there are not too many options and around 16 options to choose from. Arch's ISO is the version released on July 2025.
Sul4ur (9 rep)
Aug 2, 2025, 03:16 PM • Last activity: Aug 4, 2025, 06:41 AM
141 votes
10 answers
63575 views
How do I get bash completion for command aliases?
I am looking to get tab-completion on my command line aliases, for example, say I defined the following alias : alias apt-inst='sudo aptitude install' Is there a way to get the completions provided by aptitude when I hit the tab key? i.e. when I write 'sudo aptitude install gnumer' and hit tab, apti...
I am looking to get tab-completion on my command line aliases, for example, say I defined the following alias : alias apt-inst='sudo aptitude install' Is there a way to get the completions provided by aptitude when I hit the tab key? i.e. when I write 'sudo aptitude install gnumer' and hit tab, aptitude completes this to gnumeric, or if there was uncertainty lists all the available packages starting with gnumer. If I do it using my alias, nothing - no completion.
levesque (3915 rep)
Nov 20, 2010, 04:13 PM • Last activity: Jul 21, 2025, 09:57 PM
2 votes
1 answers
80 views
Debian: bash-completion does not work with "sudo bash" and "su"
After installing `bash-completion` on Debian testing (nearly Debian 13), completion works without any additional configuration in my normal user account. This is because of `/etc/profile.d/bash_completion.sh`. When doing `sudo bash` to become root, completion does not work. It neither works when run...
After installing bash-completion on Debian testing (nearly Debian 13), completion works without any additional configuration in my normal user account. This is because of /etc/profile.d/bash_completion.sh. When doing sudo bash to become root, completion does not work. It neither works when running su to become root (but does when running su -). Why is that so? Is there anything I can do to fix that? (I test completion by typing apt and pressing the tab key.)
cweiske (614 rep)
Jul 19, 2025, 05:29 PM • Last activity: Jul 20, 2025, 09:28 PM
15 votes
2 answers
6765 views
What allows bash to autocomplete tmux "sub-commands"?
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 `" and bash autocompletes that to "`tmux new-session`" (I hope "sub-command" is the right term). **This doesn't happen on my home PC -- wh...
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" 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" 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.
StoneThrow (1937 rep)
Aug 14, 2020, 07:01 PM • Last activity: Jul 16, 2025, 11:06 PM
49 votes
8 answers
64890 views
Debian - apt (not apt-get) autocompletion not working
I am on Debian Jessie 8.6. I noticed that `apt-get` gets the expected bash autocompletion when pressing tab for packages and command, but when trying to use it with `apt` it does not work. I remember using xubuntu 16.04 where it worked, so I find it strange that it does not work here. Is there a way...
I am on Debian Jessie 8.6. I noticed that apt-get gets the expected bash autocompletion when pressing tab for packages and command, but when trying to use it with apt it does not work. I remember using xubuntu 16.04 where it worked, so I find it strange that it does not work here. Is there a way to enable it for the command apt as well? If so, how?
fullmontis (631 rep)
Sep 26, 2016, 03:23 PM • Last activity: Jul 8, 2025, 07:37 PM
3 votes
2 answers
2222 views
Bash autocomplete variables for other commands than cd
I have env variable `$SCRIPT`. Normaly I can use autocomplete vim $SC and completion works as expected. On some systems it does not work. I have bash completion loaded, but completion in these cases works only with directories (`cd $SCRIPT_DIREC ` is working). Mostly I have problem with bash 4.2. Wh...
I have env variable $SCRIPT. Normaly I can use autocomplete vim $SC and completion works as expected. On some systems it does not work. I have bash completion loaded, but completion in these cases works only with directories (cd $SCRIPT_DIREC is working). Mostly I have problem with bash 4.2. What shopt can enable it? EDIT: I have compared my shopt settings with Bash 4.3 where it's working and Bash 4.2 (Ubuntu server 12.04) where is NOT working, there were few differences (most of them 4.3 specific), set the rest the same, but nothing worked.
pevik (1587 rep)
Apr 24, 2014, 11:34 AM • Last activity: Jul 7, 2025, 11:09 PM
1 votes
0 answers
38 views
Disable command+filename completion in bash readline
I'm trying to use "read -e" to implement a user prompt with custom commands. For this I must disable the default command+filename completion. I tried this: complete -W 'cmd1 cmd2 cmd3' -D and indeed pressing tab once on an empty prompt started with "c", but pressing it twice did not present cmd1 cmd...
I'm trying to use "read -e" to implement a user prompt with custom commands. For this I must disable the default command+filename completion. I tried this: complete -W 'cmd1 cmd2 cmd3' -D and indeed pressing tab once on an empty prompt started with "c", but pressing it twice did not present cmd1 cmd2 cmd3, instead the usual bash aliases/OS programs in the PATH starting with "c". Any tips on how to do what I want? It seems there's "set disable-completion on" , but no "set disable-os-command-completion" or something similar. Thanks.
Rihad (21 rep)
Jun 19, 2025, 08:50 AM • Last activity: Jun 19, 2025, 11:00 AM
2 votes
2 answers
2043 views
zsh autocomplete without completing prompt
Tried to find this answer, but could not. I am new to zsh, and I like it a lot on my Mac. I am looking for an option to set it to autocomplete, but without putting the completion in the prompt until I hit enter. For example, if I type: cd Documents/ and then press tab, it will highlight the options...
Tried to find this answer, but could not. I am new to zsh, and I like it a lot on my Mac. I am looking for an option to set it to autocomplete, but without putting the completion in the prompt until I hit enter. For example, if I type: cd Documents/ and then press tab, it will highlight the options but ALSO add them to the prompt, so I have to either tab a ton to get to the one I want, or delete back. Here is what I mean: cd Documents/ (press tab) it shows: $ cd Documents/Apple Apple Banana Durian Orange Starfruit Tamarine But I am going through the list to get to Tamarine--I want to see the options and be able to continue to tab through them, but not have them added to my current prompt until I hit Enter. Is this possible? unsetopt automenu Gets me close, but then I cannot tab through the options. Does that make sense? Thanks!
nomeelnoj (21 rep)
Jul 2, 2017, 08:38 AM • Last activity: Jun 4, 2025, 01:03 PM
4 votes
1 answers
174 views
Change zsh autocompletion for rsync version 3.2.4 and newer
rsync changed how it escapes arguments in version 3.2.4 (released 15 Apr 2022), and zsh doesn't comply with the new behaviour. For example, if I have a file named "my test file.txt", autocomplete expands it to `rsync remote:my\\\ test\\\ file.txt` instead of `rsync remote:my\ text\ file.txt`. Yes I...
rsync changed how it escapes arguments in version 3.2.4 (released 15 Apr 2022), and zsh doesn't comply with the new behaviour. For example, if I have a file named "my test file.txt", autocomplete expands it to rsync remote:my\\\ test\\\ file.txt instead of rsync remote:my\ text\ file.txt. Yes I could use export RSYNC_OLD_ARGS=1but I would prefer not to. Does anyone know how and where I can modify the behaviour of zsh autocompletion for rsync so that it won't do the double escaping? 1. https://www.zsh.org/mla/workers/2022/msg00814.html 2. https://zsh.sourceforge.io/releases.html
cbg (43 rep)
May 28, 2025, 08:52 AM • Last activity: May 29, 2025, 04:37 AM
1 votes
0 answers
27 views
Display all commands matching a glob
How can I get Bash to list the first (or all) commands that match a given glob? For example, let's say I'm looking for a command called `cat`. I can do type cat and it will search `$PATH` and tell me there is a `cat` at `/usr/bin/cat`. But suppose I forgot its full name, but I remember that it start...
How can I get Bash to list the first (or all) commands that match a given glob? For example, let's say I'm looking for a command called cat. I can do type cat and it will search $PATH and tell me there is a cat at /usr/bin/cat. But suppose I forgot its full name, but I remember that it starts with "ca". Then I can type ca and press tab and Bash will list all available commands starting with "ca". What if I forgot what it starts with, but I just remember that it contains "at" as a substring? If I type \*at\* and press tab it doesn't work. If I type type \*at\* it doesn't work either.
k314159 (481 rep)
May 28, 2025, 03:15 PM
17 votes
3 answers
7940 views
Make BASH's Tab Completion Fill In First Match?
Is there any way to make BASH fill in the first match when I press TAB, kind of like the Windows command prompt? (It should still display the list of matches, but it should cycle through them when I keep on pressing tab.) i.e. the goal here is to be able to fill in ***any** match* with **only** the...
Is there any way to make BASH fill in the first match when I press TAB, kind of like the Windows command prompt? (It should still display the list of matches, but it should cycle through them when I keep on pressing tab.) i.e. the goal here is to be able to fill in ***any** match* with **only** the TAB key, given enough presses -- like in Windows.
user541686 (3163 rep)
Jul 19, 2011, 01:11 AM • Last activity: May 17, 2025, 05:15 PM
0 votes
2 answers
798 views
"_split_longopt: command not found" when trying tab-completion
For the past couple of weeks or so, I've noticed that, often, when I press the Tab key to try and complete a command in a bash shell in a terminal, I get an error message. It says: ``` bash: _split_longopt: command not found ``` What could cause this, and how can I fix it? Notes: * The file `/usr/sh...
For the past couple of weeks or so, I've noticed that, often, when I press the Tab key to try and complete a command in a bash shell in a terminal, I get an error message. It says:
bash: _split_longopt: command not found
What could cause this, and how can I fix it? Notes: * The file /usr/share/bash-completion/bash_completion is present, and I haven't modified it myself. It has a function named _comp__split_longopt. Note: I'm using Devuan Excalibur (~= Debian Trixie without systemd).
einpoklum (10753 rep)
Aug 11, 2024, 06:09 PM • Last activity: May 16, 2025, 07:31 AM
2 votes
1 answers
795 views
Fish shell, disable pager navigation through Tab / Shift Tab
Fish is a great shell (the best?) but its completion interface has a particular quirk that I personally don't like and would like to disable. It's expressed by this sentence in the tutorial: > Hit tab again to cycle through the possibilities. This means that, after hitting tab to complete the longes...
Fish is a great shell (the best?) but its completion interface has a particular quirk that I personally don't like and would like to disable. It's expressed by this sentence in the tutorial: > Hit tab again to cycle through the possibilities. This means that, after hitting tab to complete the longest common prefix (behavior A) and showing a menu of further entries, if you hit Tab again you start cycling through the entries (behavior B). If there a way to disable behavior B of the Tab key, or bind it to a different key, while keeping behavior A?
Tobia (739 rep)
Jan 31, 2020, 10:31 PM • Last activity: May 15, 2025, 11:33 AM
20 votes
4 answers
6313 views
ZSH: insert completion on first tab even if ambiguous?
Currently ZSH displays a menu when I first hit tab and the completion is ambiguous. So, if I have 'cd ' in the command prompt and I hit tab, it will show the different available completions. If I hit tab again, it will select the first available completion. I would like to merge these two steps into...
Currently ZSH displays a menu when I first hit tab and the completion is ambiguous. So, if I have 'cd ' in the command prompt and I hit tab, it will show the different available completions. If I hit tab again, it will select the first available completion. I would like to merge these two steps into a single press of the tab key. So, if I'm at 'cd ' and I tab, I would like ZSH to insert the first available match (when ambiguous) and display the menu, which I can then tab through if the first match wasn't the directory I had in mind. The ZSH setup tool put this in my .zshrc, in case any of this is affecting the behavior of my shell:
zstyle ':completion:*' completer _expand _complete _ignored
zstyle ':completion:*' list-colors ''
zstyle ':completion:*' list-prompt %SAt %p: Hit TAB for more, or the character to insert%s
zstyle ':completion:*' matcher-list 'm:{[:lower:][:upper:]}={[:upper:][:lower:]}' '' 'm:{[:lower:][:upper:]}={[:upper:][:lower:]}'
zstyle ':completion:*' menu select=5
zstyle ':completion:*' select-prompt %SScrolling active: current selection at %p%s
zstyle :compinstall filename '/home/robb/.zshrc'
rps (713 rep)
Apr 23, 2011, 04:49 PM • Last activity: May 14, 2025, 07:11 AM
4 votes
2 answers
280 views
How did I get the git commits to show up in autocomplete?
Git tab completion on my mac: ![Git tab completion on my mac][1] Git tab completion on my Ubuntu server: ![Git tab completion on my ubuntu server][2] [1]: https://i.sstatic.net/mM5Mu.png [2]: https://i.sstatic.net/puAiy.png On my mac and my Ubuntu server I get very different output from tab completi...
Git tab completion on my mac: Git tab completion on my mac Git tab completion on my Ubuntu server: Git tab completion on my ubuntu server On my mac and my Ubuntu server I get very different output from tab completion despite having the same version of zsh, same version of git, the same version of oh-my-zsh, and the same .zshrc file. I wanted to know what is giving me the ability to see commits on my mac using tab completion so that I can set it up on my ubuntu server.
William Young
Jun 21, 2016, 11:46 PM • Last activity: May 9, 2025, 03:06 PM
1 votes
1 answers
1796 views
How to prevent zsh path completion magic until I press TAB?
I have a hobby server with a significant numbr of USB hard drives. I have aggressive power management enabled, and a short spin-down timeout, as these drives are basically meant to be cold storage with quick accessibility when needed. So most of them spend 99.9% of their time in APM standby until I...
I have a hobby server with a significant numbr of USB hard drives. I have aggressive power management enabled, and a short spin-down timeout, as these drives are basically meant to be cold storage with quick accessibility when needed. So most of them spend 99.9% of their time in APM standby until I need to access them, at which point they spin up, and for single drives I have access within ten seconds, for drives in RAID, up to 30 seconds. The ZSH completion system is giving me headaches in this regard, since the arguably fantastic auto-completion magic it offers has some sort of automatic path validation going on as well, even when I don't press TAB, and even if I use my arrow keys to traverse the shell command history. For instance, I can type rsync, then press the up key to start traversing the history for my previous rsync commands, and immediately the completion magic starts to access filesystem paths in those commands to validate and do magic stuff on them. This not only causes huge pauses where zsh blocks and becomes unresponsive, it also spins up sleeping drives which increases wear on those spinners. Any paths to network mounts also cause delays due to their network nature. It also kicks in while writing a path, with me just typing letters, slashes and wildcards. I have found a lot of questions about similar gripes, [like this one](https://unix.stackexchange.com/questions/162078/stop-zsh-from-completing-parent-directories) , but I've yet to find something that addresses this precisely. On the mentioned post above, there's a link to the zsh Completion System docs, and while reading them I find myself still confused. From the docs I'm not even sure what the syntax for zstyle is, and I'm confused about a lot of the terminology. Basically I'm just looking for a way to say to zsh, "listen mate, I love what you're doing, but could you wait with all you wonderful magic until I press TAB?"
FlamingKitties (5029 rep)
Aug 26, 2022, 08:16 AM • Last activity: May 9, 2025, 10:53 AM
3 votes
1 answers
2868 views
How do I show a bash autocomplete result as a faded text in the terminal?
I'm using GNU bash, version 5.0.17(1)-release (x86_64-pc-linux-gnu). How do I see a preview of what happens if I press tab to autocomplete, similar to a fish shell. (Sorry, I'm new, so I may not be using the right terminology)
I'm using GNU bash, version 5.0.17(1)-release (x86_64-pc-linux-gnu). How do I see a preview of what happens if I press tab to autocomplete, similar to a fish shell. (Sorry, I'm new, so I may not be using the right terminology)
Joshua Foo JF (31 rep)
May 13, 2021, 01:23 PM • Last activity: May 9, 2025, 08:05 AM
4 votes
1 answers
250 views
Why does tab autocomplete sometimes not work?
In `bash` (Ubuntu 24.10, but I guess this would apply to other versions/distributions) when you type in a console a command you can use TAB to autocomplete the filenames of the current directory. Example: ```$ ls Doc``` TAB would propose the `Document` folder. This works for many commands, but not f...
In bash (Ubuntu 24.10, but I guess this would apply to other versions/distributions) when you type in a console a command you can use TAB to autocomplete the filenames of the current directory. Example:
$ ls Doc
TAB would propose the Document folder. This works for many commands, but not for other. On my system, for example, it does not work for sqlite3. Pressing TAB does nothing. Why does this happen? Is it the invoked program that has to handle the keypress or (as I naively thought) it is a feature of bash or even of gnome-terminal?
Mark (815 rep)
Apr 4, 2025, 06:56 AM • Last activity: Apr 26, 2025, 11:50 AM
0 votes
1 answers
40 views
No space after option with bash completion
I'm trying to filter bash-completion suggestions. Here `awf-gtk2 -s abc.png [TAB]` display `-h --help -s --screenshot` (it's ridiculous) / and `awf-gtk2 -s[TAB]` add a space after `-s` (perfect), with: ```bash _awf_gtk2_complete() { local cur prev COMPREPLY=() cur="${COMP_WORDS[COMP_CWORD]}" prev="$...
I'm trying to filter bash-completion suggestions. Here awf-gtk2 -s abc.png [TAB] display -h --help -s --screenshot (it's ridiculous) / and awf-gtk2 -s[TAB] add a space after -s (perfect), with:
_awf_gtk2_complete() {
	local cur prev
	COMPREPLY=()
	cur="${COMP_WORDS[COMP_CWORD]}"
	prev="${COMP_WORDS[COMP_CWORD-1]}"
	local opts="-h --help -s --screenshot"
	case "$prev" in
		-h|--help|-v|--version|-l|--list-themes)
			return 1 # stop
			;;
		-s|--screenshot)
			COMPREPLY=( $(compgen -d -- "$cur") )
			return 0
			;;
	esac
	COMPREPLY=( $(compgen -W "$opts" -- "$cur") )
}
complete -F _awf_gtk2_complete awf-gtk2
With ChatGPT (sorry), we did that:
# made in chatGPT
_awf_gtk3_complete() {
	local cur prev
	COMPREPLY=()
	cur="${COMP_WORDS[COMP_CWORD]}"
	prev="${COMP_WORDS[COMP_CWORD-1]}"

	local all_opts=(-h --help -v --version -l --list-themes -t --theme -s --screenshot --ltr --rtl)
	local single_opts=(-h --help -v --version -l --list-themes)

	declare -A opt_aliases=(
		[-h]=--help
		[--help]=-h
		[-v]=--version
		[--version]=-v
		[-l]=--list-themes
		[--list-themes]=-l
		[-t]=--theme
		[--theme]=-t
		[-s]=--screenshot
		[--screenshot]=-s
	)

	case "$prev" in
		-h|--help|-v|--version|-l|--list-themes)
			return 1 # stop
			;;
		-s|--screenshot)
			COMPREPLY=( $(compgen -d -- "$cur") )
			return 0
			;;
	esac

	local used=()
	local word
	for word in "${COMP_WORDS[@]:1}"; do
		if [[ "$word" == -* ]]; then
			used+=("$word")
			[[ -n "${opt_aliases[$word]}" ]] && used+=("${opt_aliases[$word]}")
		fi
	done

	local hide_single_use=false
	for word in "${used[@]}"; do
		case "$word" in
			-t|--theme|-s|--screenshot|--ltr|--rtl)
				hide_single_use=true
				break
				;;
		esac
	done

	local remaining_opts=()
	local opt
	for opt in "${all_opts[@]}"; do
		local skip=false
		for u in "${used[@]}"; do
			[[ "$opt" == "$u" ]] && skip=true && break
		done
		if $hide_single_use; then
			for su in "${single_opts[@]}"; do
				[[ "$opt" == "$su" ]] && skip=true && break
			done
		fi
		$skip || remaining_opts+=("$opt")
	done

	local opts=${remaining_opts[*]}
	COMPREPLY=( $(compgen -W "$opts" -- "$cur") )
}
complete -F _awf_gtk3_complete awf-gtk3
The idea: - if you are using -h --help -v --version -l --list-themes, completion suggests nothing else (it's ok) - if you are using -t --theme, completion suggests themes names by running the program (it's ok) - if you are using a short option, completion doesn't suggests the corresponding long option (it's ok) - if you are using one option, completion doesn't suggests again the same option (it's ok) - if you are using --ltr, completion doesn't suggests --rtl (but not yet, and it's not the problem) **The problem is**: awf-gtk3 -t[TAB] or awf-gtk3 --theme[TAB] does NOT add a space! (awf-gtk3 --th[TAB] add a space and it's perfect). **Why?**
luigifab (101 rep)
Apr 10, 2025, 08:53 PM • Last activity: Apr 11, 2025, 09:22 AM
0 votes
1 answers
17 views
create a completion function for tmux-manager
Here is my script: #!/usr/bin/env bash kill-all-sessions() { tmux kill-server } kill-other-sessions() { tmux kill-session -a } kill-unattached-sessions() { tmux list-sessions -F '#{session_name} #{session_attached}' | awk '$2 == 0 { print $1 }' | xargs -n1 tmux kill-session -t } list-attached-sessio...
Here is my script: #!/usr/bin/env bash kill-all-sessions() { tmux kill-server } kill-other-sessions() { tmux kill-session -a } kill-unattached-sessions() { tmux list-sessions -F '#{session_name} #{session_attached}' | awk '$2 == 0 { print $1 }' | xargs -n1 tmux kill-session -t } list-attached-sessions() { tmux list-sessions -F "#{session_attached} #{session_name} #{session_path}" | awk '$1 == 1 { print $2, $3 }' } # Main logic: check the argument and call the corresponding function case "$1" in kill-all) kill-all-sessions ;; kill-other) kill-other-sessions ;; kill-unattached) kill-unattached-sessions ;; list-attached) list-attached-sessions ;; *) echo "Usage: $0 {kill-all|kill-other|kill-unattached|list-attached}" exit 1 ;; esac I need a zsh completion function for this script. The code I came up with is: #compdef tmux-manager _tmux-manager() { local -a commands commands=( 'kill-all:Kill all tmux sessions' 'kill-other:Kill all sessions except the current one' 'kill-unattached:Kill only unattached sessions' 'list-attached:List only attached sessions' ) _describe 'command' commands } _tmux-manager "$@" The code is not working. What might be the solution.
Ahmad Ismail (2998 rep)
Apr 9, 2025, 04:13 PM • Last activity: Apr 9, 2025, 07:54 PM
Showing page 1 of 20 total questions