Closed jacobo-diaz closed 2 years ago
@jacobo-diaz we actually use this ourselves but it's zle .reset-prompt
for us.
Thanks @JanDeDobbeleer, but it's not working for me with zle .reset-prompt
. The path changes, but the segment is not updated unless I issue a command (with Enter
only does not work either). This is the same behaviour as with zle reset-prompt
.
@jacobo-diaz weird as we do the same to render the transient prompt (which works). I'm not the expert, but you can have a look at the init script.
@jacobo-diaz I tried your script but it doesn't even change the dir for me. Same setup, nothing works.
Thanks @JanDeDobbeleer. In my case, with carriage return (Enter
) the prompt does not update, but the dir changes. If you issue pwd
(or some other command, for that matter), then the prompt updates.
We get the PWD from go directly (and need to as otherwise it's not cross platform anymore, $PWD
doesn't work in some cases).
So you're saying in your case, the folder doesn't change on enter? Because that's not how I understood the initial bug report.
That also implies pushd
doesn't update $PWD
, or that this case is inaccessible from go due to the underlying system constraints.
The expected behaviour is that when Shift+arrow
is pressed, the directory changes and then the path segment in the prompt should update accordingly.
What happens with oh-my-posh is that the directory changes, but the path segment in the prompt is not updated to reflect that change. Moreover, if you generate the prompt again pushing Enter
, the path segment is not updated either (although, you're already in another directory). The only way to update the path segment in the prompt is issuing a new command (for instance pwd
, but any command works).
You can reproduce the expected behaviour creating a .zshrc
with only the code that I posted above and then changing dirs with Shift+left/right
. You'll see the prompt updating in place.
@jacobo-diaz I did exactly that, and the snippet, while it seems it should work, doesn't work for me. Outside of that, I can do everything, pushd and popd work according to expectations so I'm pretty sure something else is wrong.
I'm sorry, I'm tired. Do you add the snippet before or after initializing oh-my-posh? I'll give it a whirl tomorrow. The only thing I don't get is that we also refresh the prompt. Can you successfully enable transient prompt for oh-my-posh? Because otherwise it might be worthwhile to update zsh.
Thanks a lot for your time, @JanDeDobbeleer! If I add the snippet after initializing oh-my-posh, the behaviour is the same. I can enable the transient prompt, but doesn't work either.
I tried with zsh 5.8 on macOS and with zsh 5.5.1 on Linux.
@jacobo-diaz the fact transient prompt doesn't work actually implies something is wrong on zsh. As that does work. Can you share your entire .zshrc
?
Using a simple .zshrc
like this, you can reply the issue:
# Cycle through dirstack
insert-cycledleft () {
emulate -L zsh
setopt nopushdminus
builtin pushd -q +1 &>/dev/null || true
# zle reset-prompt
zle .reset-prompt # For Oh My Posh
}
zle -N insert-cycledleft
insert-cycledright () {
emulate -L zsh
setopt nopushdminus
builtin pushd -q -0 &>/dev/null || true
# zle reset-prompt
zle .reset-prompt # For Oh My Posh
}
zle -N insert-cycledright
bindkey "\e[1;6D" insert-cycledleft # Shift + left arrow
bindkey "\e[1;6C" insert-cycledright # Shift + right arrow
# Save dirstack history to .zdirs
# (adapted from https://github.com/grml/grml-etc-core/blob/master/etc/zsh/zshrc#L1547)
DIRSTACKSIZE=${DIRSTACKSIZE:-20}
dirstack_file=${dirstack_file:-${HOME}/.zdirs}
if [[ -f ${dirstack_file} ]] && [[ ${#dirstack[*]} -eq 0 ]] ; then
dirstack=( ${(f)"$(< $dirstack_file)"} )
[[ -d $dirstack[1] ]] && cd $dirstack[1] && cd $OLDPWD
fi
chpwd_functions+=(chpwd_dirpersist)
chpwd_dirpersist() {
if (( $DIRSTACKSIZE <= 0 )) || [[ -z $dirstack_file ]]; then return; fi
local -ax my_stack
my_stack=( ${PWD} ${dirstack} )
builtin print -l ${(u)my_stack} >! ${dirstack_file}
}
eval "$(oh-my-posh --init --shell zsh --config ~/posh.toml)"
And the posh.toml
file:
"$schema" = "https://raw.githubusercontent.com/JanDeDobbeleer/oh-my-posh/main/themes/schema.json"
console_title = true
console_title_style = "template"
console_title_template = "{{ .Shell }} in {{ .Folder }}"
final_space = true
version = 1.0
[[blocks]]
alignment = "left"
type = "prompt"
[[blocks.segments]]
background = "#ff479c"
foreground = "#ffffff"
powerline_symbol = "\ue0b0"
style = "powerline"
type = "path"
[blocks.segments.properties]
folder_separator_icon = " \ue0b1 "
style = "folder"
template = " {{ .Path }} "
If you comment the line where Oh-my-posh is loaded, then the behaviour is as expected.
@jacobo-diaz I have no what I'm missing but shift+left (or right) only prints either D or C with that config. Found another key-map that makes it reproducible.
@jacobo-diaz found the issue. This isn't related to oh-my-posh but the fact that you don't execute the precmd_functions before resetting. This works:
eval "$(oh-my-posh --init --shell zsh --config ~/posh.toml)"
# Cycle through dirstack
insert-cycledleft () {
emulate -L zsh
setopt nopushdminus
builtin pushd -q +1 &>/dev/null || true
# zle reset-prompt
local precmd
for precmd in $precmd_functions; do
$precmd
done
zle .reset-prompt # For Oh My Posh
}
zle -N insert-cycledleft
insert-cycledright () {
emulate -L zsh
setopt nopushdminus
builtin pushd -q -0 &>/dev/null || true
# zle reset-prompt
local precmd
for precmd in $precmd_functions; do
$precmd
done
zle .reset-prompt # For Oh My Posh
}
zle -N insert-cycledright
bindkey "\e\e[D" insert-cycledleft # Shift + left arrow
bindkey "\e\e[C" insert-cycledright # Shift + right arrow
# Save dirstack history to .zdirs
# (adapted from https://github.com/grml/grml-etc-core/blob/master/etc/zsh/zshrc#L1547)
DIRSTACKSIZE=${DIRSTACKSIZE:-20}
dirstack_file=${dirstack_file:-${HOME}/.zdirs}
if [[ -f ${dirstack_file} ]] && [[ ${#dirstack[*]} -eq 0 ]] ; then
dirstack=( ${(f)"$(< $dirstack_file)"} )
[[ -d $dirstack[1] ]] && cd $dirstack[1] && cd $OLDPWD
fi
chpwd_functions+=(chpwd_dirpersist)
chpwd_dirpersist() {
if (( $DIRSTACKSIZE <= 0 )) || [[ -z $dirstack_file ]]; then return; fi
local -ax my_stack
my_stack=( ${PWD} ${dirstack} )
builtin print -l ${(u)my_stack} >! ${dirstack_file}
}
It works. Thanks a lot @JanDeDobbeleer! I was confused because it worked with the default (and some other) prompts. Cheers!
This issue has been automatically locked since there has not been any recent activity (i.e. last half year) after it was closed. It helps our maintainers focus on the active issues. If you have found a problem that seems similar, please open a discussion first, complete the body with all the details necessary to reproduce, and mention this issue as reference.
Code of Conduct
What happened?
zle reset-prompt
does not update the prompt. That's needed to update the Path segment when changing paths withShift+arrow
using the following code:Theme
jandedobbeleer.omp
What OS are you seeing the problem on?
macOS
Which shell are you using?
zsh
Log output