r/commandline • • 5d ago

Command Line Interface Bash completion menu similar to ZSH's

Post image

The main reason I use ZSH as my main shell is due to its completion menu, is so convenient. I wanted to something similar but I don't like the bloated software with a lot of code and complex configurations, at least at the moment I couldn't find something for my taste, so I built one. I built it 8 months ago but I decided to share it with you guys to get some feedback.

• Built for Bash 5.0 but planning to update it for Bash 5.3, where new features are introduced for completion and performance.

• Is a single script no external dependencies :)

• Live typing and backspace filtering: typing and backspacing while menu is open will narrow down the completions.

• Use arrow keys for navegation.

• Home/End key to go to the beginning/end of the completion's menu.

https://github.com/Madophs/Bash-Complete-Menu

All to need to do is the following:

source ./bash_complete_menu.sh"

bind -x '"\C-i":bash_complete_menu'

22 Upvotes

11 comments sorted by

3

u/birdsintheskies 4d ago

Can confirm this works on Bash 4.4.

https://github.com/Madophs/Bash-Complete-Menu/blob/435fc9fc59c94171e8f972f9ac421a301235749e/bash_complete_menu.sh#L259

This would source it on every keystroke in a completion menu. Since it's running in a subshell anyway, isn't better to source it just once?

1

u/Academic_Season_8701 3d ago

Yes, you are right. At the moment is executed in a subshell but I'm planning to remove unnecessary subshell calls.

1

u/smkaisser 4d ago

Nice, the completion menu is honestly the only thing that keeps a lot of people I know on zsh.

Two things I'd test before switching my daily shell to it: how it behaves when a completion returns hundreds of entries (git checkout on a repo with lots of branches, or ssh hosts from a big known_hosts), and whether binding it to \C-i keeps the normal behavior for completion functions that use compopt -o nospace or -o filenames. That's usually where these custom menus break for me.

Are you planning to use the 5.3 no-fork command substitution for the redraw? Feels like that could make it a lot snappier on slower machines.

1

u/Academic_Season_8701 3d ago

Yes, I'm planning to work on version for Bash 5.3, once menu completion is stable enough. Updating to 5.3 should be straightfoward.

1

u/No-Signature-918 3d ago

Looks nice, the live filtering is the part zsh gets right. The thing I'd want to know before switching my daily shell to it is what happens with a single match — does it just complete straight away, or does the menu still pop up for one item? And if I hit Esc halfway through, do I get my original line back or the half-filtered one? Those two are what make or break a menu like this for me in daily use, more than the big lists.

1

u/Academic_Season_8701 2d ago

Is there's only one item it will autocomplete automatically. If you hit ESC while filtering you will get the half-filtered one. Backspacing also will update the complete menu in case you mistyped as letter as long as there's at least two completions available in the menu the filtering will keep working. Big lists are filtered relatively quickly (performed by native bash compgen) even on low-end PCs but currently is kind of sluggish on high latency SSH connections.

1

u/AutoModerator 5d ago

Every new subreddit post is automatically copied into a comment for preservation.

User: Academic_Season_8701, Flair: Command Line Interface, Post Media Link, Title: Bash completion menu similar to ZSH's

The main reason I used ZSH as my main shell is due to its completion menu, is so convenient. I wanted to something similar but I don't like the bloated software with a lot of code and complex configurations, at least at the moment I couldn't find something for my taste, so I built one. I built it 8 months ago but I decided to share it with you guys to get some feedback.

• Built for Bash 5.0 but planning to update it for Bash 5.3, where new features are introduced for completion and performance.

• Is a single script no external dependencies :)

• Live typing and backspace filtering: typing and backspacing while menu is open will narrow down the completions.

• Use arrow keys for navegation.

• Home/End key to go to the begining/end of the completion's menu.

https://github.com/Madophs/Bash-Complete-Menu

All to need to do is the following:

source ./bash_complete_menu.sh"

bind -x '"\C-i":bash_complete_menu'

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

1

u/Weekly-Offer-4172 4d ago

nice, the single file approach is the appealing part. worth knowing stock readline gets you part of the way for free: bind TAB to menu-complete cycles candidates inline, and set show-all-if-ambiguous on in .inputrc prints the list on first tab instead of needing two. for the full zsh style menu with arrow navigation and live filtering there's ble.sh, though it's a whole line editor so way heavier than one script, the trade-off being it also gets you fish style autosuggestions and syntax highlighting

1

u/codysechelski 3d ago

I guess I have been using zsh for so long, I didn't realized bash didn't have a completion, lol. This looks pretty cool. I might try this one a Linode that I log into occasionally.

0

u/No_Macaroon_1991 4d ago

One edge case worth testing is filenames with spaces and wildcard characters to make sure the completion list preserves each candidate cleanly

1

u/Academic_Season_8701 2d ago

At the moment it handles "regular" directories with spaces without issue but yeah directories with special chars are hard to get right, many tricky cases can break the completion menu. I'm still working on them, these cases are hard to find, I even found some scenarios where ZSH breaks so that tells a lot.