Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
zle defined widget inside a prompt_theme_setup function
- X-seq: zsh-users 23314
- From: Doron Behar <doron.behar@xxxxxxxxx>
- To: zsh-users@xxxxxxx
- Subject: zle defined widget inside a prompt_theme_setup function
- Date: Fri, 6 Apr 2018 00:47:58 +0300
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:subject:message-id:mime-version:content-disposition :user-agent; bh=sFjIFW7g0rOO5cedglf/60p6ZCgLtaTuBzNlJxe5af4=; b=NG74uYUUYQNLNtgZjgKrvg1o4f0b+lPUkMfnskJiyv0mRYMTKDZ7icWxw3oCpCRCEz 6S7jQRXE2cLG/GxT7v0gZMeznjy8a1AfgeyudcA+MVpM5ZXk6meqgJ8FndV1tVi7DdaX wDLNbW41zCJ+c0WR3jEVzsOZSf6tNFgmBwxdjpzjxJSZjTnzkh6yz+oCXcFq25fMJNFL cgAH1jsJ/Bd1lVBo59VFaQ9EdV/LizPcWhF99uL+48KC3F9Eabb1sHo2R4D4xDPj0L82 8EDLdSB+z4GWDl/QfmFEdWeVXm+Wr05Ey2gAzlXqbQd0KnKxCx8MVlABgs0JhhoPI9E2 e8Yw==
- List-help: <mailto:zsh-users-help@zsh.org>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:zsh-users@zsh.org>
- List-unsubscribe: <mailto:zsh-users-unsubscribe@zsh.org>
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
Hello ZSH users,
As explained under section 26.6 of the manual
(http://zsh.sourceforge.net/Doc/Release/User-Contributions.html#Prompt-Themes)
I've created a function `prompt_my_setup` which I've putt in my `fpath`
for my theme called `my` as follows:
prompt_my_setup(){
PS1='%M %% '
}
Since I use vi like keys in ZLE, I wanted to have an indicator telling
me whether I'm on INSERT mode or NORMAL mode. I've googled the subject
and encountered this answer:
https://unix.stackexchange.com/a/1029/135796
That works. I was trying to use this `prompt_my_setup` file:
prompt_my_setup(){
add-zsh-hook preexec prompt_my_preexec
PS1_base='%M %% '
zle -N zle-line-init
zle -N zle-keymap-select
terminfo_down_sc=$terminfo[cud1]$terminfo[cuu1]$terminfo[sc]$terminfo[cud1]
}
prompt_my_precmd () {
vcs_info
}
function zle-line-init zle-keymap-select {
PS1_2="${${KEYMAP/vicmd/-- NORMAL --}/(main|viins)/-- INSERT --}"
PS1="%{$terminfo_down_sc$PS1_2$terminfo[rc]%}$PS1_base"
zle reset-prompt
}
prompt_my_preexec () {
print -rn -- $terminfo[el];
}
prompt_my_setup
That works as well but the problem is that after running `prompt my`, I
can't revert back to any other prompt and the prompt stays the same
unless I make the functions `zle-line-init` and `zle-keymap-select`
empty.
I've read throughly the manual and especially section 26.6.4:
http://zsh.sourceforge.net/Doc/Release/User-Contributions.html#Writing-Themes
It seems that the `prompt_cleanup` should do it but it doesn't work
neither it's usage makes any sense to me. Allow me to explain:
I tried to add the following to the file `prompt_my_setup`, please
correct me if this usage is wrong:
prompt_my_cleanup () {
function zle-line-init zle-keymap-select {
}
}
prompt_cleanup prompt_my_cleanup
If I run `prompt my` on startup, I get my prompt setup just fine, with
my ZLE indicator showing just fine.
As I said, if for example I run afterwards `prompt adam1`, I don't see
any change in the prompt, unless I manually run `prompt_my_cleanup`
which makes `zle-line-init` and `zle-keymap-select` empty.
Wouldn't it make more sense if in the same manner as when a user
defines `prompt_THEME_setup` and `prompt_THEME_help` or
`prompt_THEME_preview`, he would define `prompt_THEME_clean`? So that
this function will be ran whenever his prompt is removed?
I'd appreciate any help / opinions, thanks.
Messages sorted by:
Reverse Date,
Date,
Thread,
Author