zsh <tab> <tab> autocompletion only if there is unique match - zsh

I recently switched from bash to zsh and I am trying to figure out how to change the double tab autocomplete behavior. I'd like it to autocomplete only if there is a unique match.

This can be controlled by shell options. You can try it in interactive shell first, then add your preferred options to ~/.zshrc.
To make zsh auto complete behave more like bash, you can start with this:
setopt NO_AUTOLIST BASH_AUTOLIST NO_MENUCOMPLETE
Also check official zsh documentation, section 6 and especially subsection 6.2. Currently it can be found here: https://zsh.sourceforge.io/Guide/zshguide06.html#l147

Related

How can I get backward-delete-word to add to the current kill-ring in zsh?

I use zsh and I would like backward-kill-word in Emacs mode to behave like Emacs (and bash, fwiw). The behaviour that I have failed to reproduce is that when I press multiple backward-kill-word Emacs adds the killed text to the cut buffer (the first item in the killring) making it possible for me to yank everything with one yank command.
How can I configure zsh to behave like this aspect of Emacs editors?
Actually, by default, Zsh's cut buffer works exactly the same as in Emacs. Just use zsh -f to start Zsh without config files and try it.
However, are you perhaps using zsh-autosuggestions or zsh-syntax-highlighting? There are bugs in these plugins that break this feature:
https://github.com/zsh-users/zsh-autosuggestions/issues/363
https://github.com/zsh-users/zsh-syntax-highlighting/issues/150#issuecomment-658381485
Fixes have been submitted, but for zsh-autosuggestions, none have yet been merged, and for zsh-syntax-highlighting, the fix won't work until Zsh 5.9 has been released.
In the meantime, though, zsh-autocomplete contains a workaround that fixes the problem. If you add that plugin, your cut buffer will start functioning like normal again.

Never complete beyond ambiguous choices

I'm trying to figure out how to customize zsh completion so that it never completes beyond an ambiguous result by just hitting tab. Here's an example.
$ emacs f<TAB>
food fool
(completes into)
$ emacs foo
food fool
Importantly, if I press TAB after 'emacs foo' I would like zsh to beep instead of complete into the menu.
Thanks.
Descending into the completion menu is controlled via the AUTO_MENU option. This is a default option which can be turned off by setting in your .zshrc the 'no' prefixed option.
setopt noautomenu
ZSH Documentation: 16 Options

complete command's parameters with oh-my-zsh

Is there a way to make zsh complete parameters of commands (just like the fish shell do). For example, when I type ls -- and use TAB it will pop up a list of all ls parameters.
I know that I can use fish shell for this, and I know that fish shell is amazing, but there is a lot of missing functionalities in the fish shell. That's why I am looking to bring this parameter completion in zsh.
Try with single hyphen, like ls -. All built in commands are working fine. Btw for custom oh-my-zsh plugin autocompletion, it depends on plugin configuration.
oh-my-zsh has over 200 plugins for different commands. But unfortunately the auto completions are all hand made. So there will be never auto complete function for every command.

Tmux bracketed paste mode issue at command prompt in zsh shell

Problem steps like this:
copy text 'kill-server' to system clipboard
hit Prefix : to enter the tmux command prompt
hit command+v to paste
The result paste text is 200~kill-server201~ instead of kill-server. This weird bracketed paste mode text do not happen in shell prompt but in tmux command prompt, and I had tried to turn off bracketed paste mode but without luck.
Environment that has this issue:
Mac OS 10.11.1, iTerm, zsh 5.0.7, Tmux 2.1
Mac OS 10.10.1, iTerm, zsh 5.1.1, Tmux 1.9
Environment that without this issue:
Mac OS 10.11.1, iTerm, bash, Tmux 2.1
I'm posting this as an answer because it's a bit too long and I need some formatting... So here it goes.
I can reproduce only with zsh 5.1+. There's no reason to expect the problem on 5.0.x, because bracketed paste mode was introduced in 5.1. You might be doing something wrong in your testing, or there might be something peculiar about your setup, in which case you have to explain better. Also, iTerm2 probably doesn't play any part in this, since I could reproduce in Terminal.app just fine (of course they could both have the same defect...).
Considering bracketed paste mode is a ZLE feature, I think (disclaimer: the rest of this paragraph is purely my speculation) the real problem is that tmux uses the underlying shell's line editing features (ZLE, in zsh's case) in its command prompt to offer better editing experience (for instance, you have access to all the Emacs style shortcuts there), but its command prompt is a dumb term, and doesn't understand the bracketed paste sequences. So we have this weird situation of two modes of terminal emulation within tmux, one is fairly smart which happens within each pane, and the other is dumb which happens in its command prompt.
Solutions and workarounds:
This is probably worth reporting to tmux. https://github.com/tmux/tmux/issues.
Turn off ZLE bracketed paste. It does work, you're probably doing it wrong. If you don't mind losing bracketed paste in tmux, you could put the following somewhere in your shell init sequence:
(( $+TMUX )) && unset zle_bracketed_paste
In iTerm2, you have access to advanced paste (Edit->Paste Special->Advanced Paste..., or ⌥⌘V). Just uncheck "Bracketed paste mode", and you shouldn't see the escape sequences.
I solved this problem finally just deactivated the safe-paste plugin in my oh-my-zsh.
The safe-paste used to fix zsh up arrow completion issue. But now, the arrow completion issue is gone while inducing tmux bracketed paste problem. I haven't dived into the code of safe-paste yet. Hope to help others encountering the same problem.

Getting zsh to honor dircolors-solarized

So I'm faced up with this discrepancy between the way my ls displays colors via this:
https://github.com/seebi/dircolors-solarized
Between that, and how zsh tab autocompletion display colors. I'll make this clear with an image:
Cheers in advance for any insights as to how to reconcile these two realms of listing directories!
list-colors is the style used by Zsh to set completion colors, it has its own funny syntax, use the following to set it to match your LS_COLORS:
# colored completion - use my LS_COLORS
zstyle ':completion:*:default' list-colors ${(s.:.)LS_COLORS}
BTW, this line comes straight from the zsh manual, man zshall and then search for LS_COLORS.

Resources