Dismiss ZSH completion list after typing a character - macos

In Fish shell when you press tab, list of completions is shown and if you start typing again it id dismissed
In ZSH after I star typing the completion menu is still shown and useless
Is there a way to make ZSH auto-completion behave the same way as Fish, so dismissing the list after typing?

I do not get this behavior with ZSH 5.7.1.
This is what's in my zshrc:
autoload -Uz compinit && compinit
source $SOFTWARE_HOME/zinit/bin/zinit.zsh
autoload -Uz _zinit
(( ${+_comps} )) && _comps[zinit]=_zinit
zinit ice depth=1; zinit light romkatv/powerlevel10k
zinit light zdharma/fast-syntax-highlighting
zinit light zsh-users/zsh-completions
zinit light zsh-users/zsh-autosuggestions
zinit light zsh-users/zsh-history-substring-search
setopt glob_complete
setopt menu_complete
zstyle ':completion:*' menu select
bindkey '^[[A' history-substring-search-up
bindkey '^[[B' history-substring-search-down
export HISTORY_SUBSTRING_SEARCH_HIGHLIGHT_FOUND=(none)
These are my options:
❯ setopt
combiningchars
extendedglob
extendedhistory
globcomplete
histfindnodups
incappendhistory
interactive
login
menucomplete
monitor
promptsubst
pushdsilent
shinstdin
zle

AUTO_MENU : which Automatically use menu completion after the second consecutive request for completion, for example by pressing the tab key repeatedly
MENU_COMPLETE : On an ambiguous completion, instead of listing possibilities or beeping, insert the first match immediately. Then when completion is requested again, remove the first match and insert the second match, etc. When there are no more matches, go back to the first one again
zsh defaults to AUTO_MENU.
if you change it to MENU_AUTOCOMPLETE with setopt menu_complete then it will work almost like fish.
to autoload this setting just save it to your .zshrc config file.
if you want additional information about options you can go to zsh options manual man zshoptions.

Related

How to get Bash's revert-line in zsh

Since macOS changed to zsh as default, I try to update my keybindings for it.
In bash I could use the following command:
bind '"\C-a": revert-line' # Revert/resets the changed history line while you are on it with the the cursor
I do not find any function like that on zsh.
bindkey "^a" what-to-put-here
Do you know how to accomplish it with zsh?
revert-line is a function provided by readline. While, ZSH doesn't depend on readline. ZSH has its own editor in command line called ZLE(ZSH Line Editor).
There doesn't seem to be a reset all function in the ZLE builtins. Correct me if I'm wrong.
undo may be an alternative for you.
undo
Incrementally undo the last text modification. When called from a user-defined widget, takes an optional argument indicating a previous state of the undo history as returned by the UNDO_CHANGE_NO variable; modifications are undone until that state is reached, subject to any limit imposed by the UNDO_LIMIT_NO variable.
bindkey "^a" undo

For further research: terminology about manipulating command before hitting RET in terminal

I just found out in zsh if I have a variable, namely abc="cba", and if I type echo ${!abc} and pressing enter, it doesnt go as command but instead open new prompt below with expanded variable echo ${abc="cba"}.
And probably included that powerful zsh plugin that let us automatically insert sudo just by double tapping Esc.
So for further studying and probably opening new possibilities, what is the right terminology about that typed-command-but-not-entered manipulation?
Thanks...
Those seem to be unrelated. The first is zsh asking you to verify history expansion. The second is a ZLE (Zsh Line Editor) widget with a keybinding to modify the current command line. You can see what this ZLE widget looks like in oh-my-zsh the source code.

Constantly updated clock in zsh prompt without any drawback?

I use the following in my zshrc file:
RPROMPT="%{$fg_bold[blue]%}%n#%M, %D %T%{$reset_color%}"
TMOUT=1
TRAPALRM() { zle reset-prompt }
It works fine, until I use the completion menu:
zmodload -i zsh/complist
zstyle ':completion:*' menu select
Now, the items in the menu become invisible whenever the prompt refreshes (because of the zle reset-prompt). If that wasn't enough, I also get segfaults when navigating the menu…
So, is there a way to update the time in my prompt without breaking anything?
Thank you.

zsh: how to autocomplete file names after python script name?

I've just moved from bash to zsh. It's a great terminal shell, but I'm missing one property - file name completion for non-standard executables.
For example, If ls gives thread_pool_examples and thread_pools:
Then typing du, space and tab would autocomplete the common prefix thread_pool, nd another click will iterate over the options:
Clicking Enter will pick the highlighted item.
The problem is that this does not work with my custom scripts. For example, if I run rmf - a Python executable in my path - and click tab, no autocomplete options will appear.
Any ideas how to make zsh autocomplete filenames for every executable?
Honestly, IMO something in your shell configuration is breaking things up. Try doing this to verify it:
zsh -f # starts a new shell ignoring your configuration
autoload compinit
compinit
./my-shell-script [TAB]
it completes with files. That is the default.
FWIW, if you want to bind a particular completer to a command/alias etc, you can do
compdef _jstack jstack
# simple _files completion
compdef _files my-local-python-script
# restrict to some file extensions
compdef '_files -g "*.(eps|ps|pdf)"' okular

Which shortcut in Zsh does the same as Ctrl-U in Bash?

In Bash, when I am typing a command, I press Ctrl+U, all characters from the beginning of the line to the cursor are going to be removed. However, in zsh, if I pressed Ctrl+U, the whole line is gone.
How to do the same in Zsh as in Bash?
It sounds like you'd like for Ctrl+U to be bound to backward-kill-line rather than kill-whole-line, so add this to your .zshrc:
bindkey \^U backward-kill-line
The bindkey builtin and the available editing commands (“widgets”) are documented in the zshzle man page.

Resources