Zsh menu completion causes problems after zle reset-prompt
I found this workaround, to basically prevent calling "reset-prompt" when in a menu selection :
TRAPALRM() {
if [ "$WIDGET" != "complete-word" ]; then
zle reset-prompt
fi
}
Note that complete-word
may be different for you; I found it with an echo $WIDGET
in the TRAPALRM
call.
zsh: refresh prompt after running zle widget
reset-prompt
could rescue:
function cdd()
{
cd /
zle reset-prompt # XXX: added
}
reset-prompt
Force the prompts on both the left and right of the screen to be re-expanded, then redisplay the edit buffer. This reflects changes both to the prompt variables themselves and changes in the expansion of the values (for example, changes in time or directory, or changes to the value of variables referred to by the prompt).
Otherwise, the prompt is only expanded each time zle starts, and when the display as been interrupted by output from another part of the shell (such as a job notification) which causes the command line to be reprinted.
--- zshzle(1), reset-prompt, Miscellaneous, Widgets, zsh command line editor
widgets can only be called when ZLE is active
After two days, I finally managed to find a hint on how to achieve it thanks to the excellent fzf-tab-completion project:
https://github.com/lincheney/fzf-tab-completion/blob/master/zsh/fzf-zsh-completion.sh#L102
So actually, all that you need to do is:
#compdef takenote
local file=$( find -L "$HOME/notes/" -print 2> /dev/null | fzf-tmux +m )
compadd $file
TRAPEXIT() {
zle reset-prompt
}
return 0
And it finally works. Cheers!
PS1 config in zsh causes previous line to be removed after each prompt redraw
zsh
can't accurately determine the size of the prompt because it doesn't know that the terminal does not display the ANSI escape codes as printable characters. Use zsh
's own formatting escapes instead.
PS1=$'%F{cyan}%n%f at %F{yellow}%m%f in %F{green}%~%F{blue}$(vcs_info_wrapper)%B%F{yellow}$VIM_PROMPT%f%b\n$ '
zsh: update prompt with current time when a command is started
I had a struggle to make this:
It displays the date on the right side when the command has been executed.
It does not overwrite the command shown.
Warning: it may overwrite the current RPROMPT.
strlen () {
FOO=$1
local zero='%([BSUbfksu]|([FB]|){*})'
LEN=${#${(S%%)FOO//$~zero/}}
echo $LEN
}
# show right prompt with date ONLY when command is executed
preexec () {
DATE=$( date +"[%H:%M:%S]" )
local len_right=$( strlen "$DATE" )
len_right=$(( $len_right+1 ))
local right_start=$(($COLUMNS - $len_right))
local len_cmd=$( strlen "$@" )
local len_prompt=$(strlen "$PROMPT" )
local len_left=$(($len_cmd+$len_prompt))
RDATE="\033[${right_start}C ${DATE}"
if [ $len_left -lt $right_start ]; then
# command does not overwrite right prompt
# ok to move up one line
echo -e "\033[1A${RDATE}"
else
echo -e "${RDATE}"
fi
}
Sources:
- http://www.tldp.org/HOWTO/Bash-Prompt-HOWTO/x361.html
- https://stackoverflow.com/a/10564427/238913
Is it possible to disable zsh 'select' style's need to hit return in order to select an option?
zshmodules(1)'s "The zsh/complist module" could help. It is pointed in the zshcompsys(1)'s "Standard styles" 'menu' entry.
zmodload zsh/complist
# Below overrides default '^M' keybind.
bindkey -M complist '^M' .accpet-line
Here is a descripton of zsh manual at the very end of the zsh/complist module entry:
All movement functions wrap around at the edges; any other zle function not listed leaves menu selection and executes that function. It is possible to make widgets in the above list do the same by using the form of the widget with a
.
in front. For example, the widget.accept-line
has the effect of leaving menu selection and accepting the entire command line.--- zshmodules(1), menu selection, the zsh/complist module
Using custom colors in zsh PS1 (prompt) env var causes problems with whitespace
ANSI escape sequences don't take up any space on the terminal, so you have to tell zsh
that they don't contribute to the length of the prompt. You do this by wrapping them in %{...%}
.
PS1="%n@%m %{\e[38;5;197m%}%~ %# "
However, you don't need raw ANSI escape sequences in zsh
nearly as often as you do in bash
. You can specify a color directly using the %F
sequence, which zsh
knows how to handle when calculating the size of your prompt.
PS1='%n@%m %F{197}%~ %# '
Related Topics
How to Install Influxdb in Windows
Docker Copy with File Globbing
Docker MACvlan Network, Unable to Access Internet
Sftp on Linux Server Gives Error "Received Message Too Long"
How to Write One Script That Runs in Bash/Shell and Powershell
Why Doesn't "History | Vim" Work
Can Gdb Change the Assembly Code of a Running Program
How to Install R 3.1.2 on Linux Mint 17.1
What Does -Prune Option in Find Do
How to Give Highest Priority to Ethernet Interrupt in Linux
Openssl Encoding Errors While Converting Cer to Pem
Binary Data Over Serial Terminal
Replace a Text with a Variable
Get Link Speed Programmatically