JanDeDobbeleer / oh-my-posh

The most customisable and low-latency cross platform/shell prompt renderer
https://ohmyposh.dev
MIT License
17.02k stars 2.37k forks source link

Prompt does not update with zle reset-prompt #1825

Closed jacobo-diaz closed 2 years ago

jacobo-diaz commented 2 years ago

Code of Conduct

What happened?

zle reset-prompt does not update the prompt. That's needed to update the Path segment when changing paths with Shift+arrow using the following code:


# Cycle through dirstack
insert-cycledleft () {
  emulate -L zsh
  setopt nopushdminus
  builtin pushd -q +1 &>/dev/null || true
  zle reset-prompt
}

zle -N insert-cycledleft

insert-cycledright () {
  emulate -L zsh
  setopt nopushdminus
  builtin pushd -q -0 &>/dev/null || true
  zle reset-prompt
}

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}
}

Theme

jandedobbeleer.omp

What OS are you seeing the problem on?

macOS

Which shell are you using?

zsh

Log output

Version: 7.26.0

Segments:

ConsoleTitle(true)   -   0 ms -
session(true)        -   0 ms -  jdiaz 
path(true)           -   0 ms -    test
git(false)           -   0 ms -
node(false)          -   0 ms -
go(false)            -   0 ms -
julia(false)         -   0 ms -
python(false)        -   0 ms -
ruby(false)          -   0 ms -
azfunc(false)        -   0 ms -
aws(false)           -   0 ms -
root(false)          -   0 ms -
executiontime(true)  -   0 ms -  ﮫ0ms⠀
exit(true)           -   0 ms -   
shell(true)          -   0 ms -   uni 
ytm(false)           -   0 ms -
battery(true)        -  18 ms -   81
time(true)           -   0 ms -  19:42:43 

Run duration: 23.117835ms

Cache path: /Users/jdiaz/.cache/oh-my-posh

Logs:

2022/02/27 19:42:43 Args duration: 82ns, args:
2022/02/27 19:42:43 Args duration: 42ns, args:
2022/02/27 19:42:43 Args duration: 166ns, args:
2022/02/27 19:42:43 Shell duration: 147ns, args:
2022/02/27 19:42:43 debug: Getenv

2022/02/27 19:42:43 Getenv duration: 4.139µs, args: OMP_CACHE_DISABLED
2022/02/27 19:42:43 Root duration: 1.013µs, args:
2022/02/27 19:42:43 Shell duration: 82ns, args:
2022/02/27 19:42:43 ErrorCode duration: 76ns, args:
2022/02/27 19:42:43 debug: Getenv

2022/02/27 19:42:43 Getenv duration: 1.51µs, args: WSL_DISTRO_NAME
2022/02/27 19:42:43 IsWsl duration: 21.551µs, args:
2022/02/27 19:42:43 debug: Pwd
/Users/jdiaz/test
2022/02/27 19:42:43 Pwd duration: 61.267µs, args:
2022/02/27 19:42:43 PathSeparator duration: 72ns, args:
2022/02/27 19:42:43 PathSeparator duration: 41ns, args:
2022/02/27 19:42:43 PathSeparator duration: 52ns, args:
2022/02/27 19:42:43 PathSeparator duration: 43ns, args:
2022/02/27 19:42:43 PathSeparator duration: 52ns, args:
2022/02/27 19:42:43 PathSeparator duration: 41ns, args:
2022/02/27 19:42:43 User duration: 1.353µs, args:
2022/02/27 19:42:43 Host duration: 8.382µs, args:
2022/02/27 19:42:43 GOOS duration: 71ns, args:
2022/02/27 19:42:43 TemplateCache duration: 194.314µs, args:
2022/02/27 19:42:43 debug: Pwd
/Users/jdiaz/test
2022/02/27 19:42:43 Pwd duration: 1.209µs, args:
2022/02/27 19:42:43 debug: Getenv

2022/02/27 19:42:43 Getenv duration: 1.04µs, args: SSH_CONNECTION
2022/02/27 19:42:43 debug: Getenv

2022/02/27 19:42:43 Getenv duration: 796ns, args: SSH_CLIENT
2022/02/27 19:42:43 TemplateCache duration: 137ns, args:
2022/02/27 19:42:43 debug: Pwd
/Users/jdiaz/test
2022/02/27 19:42:43 Pwd duration: 1.52µs, args:
2022/02/27 19:42:43 debug: Pwd
/Users/jdiaz/test
2022/02/27 19:42:43 Pwd duration: 787ns, args:
2022/02/27 19:42:43 Args duration: 58ns, args:
2022/02/27 19:42:43 debug: Pwd
/Users/jdiaz/test
2022/02/27 19:42:43 Pwd duration: 660ns, args:
2022/02/27 19:42:43 GOOS duration: 55ns, args:
2022/02/27 19:42:43 GOOS duration: 42ns, args:
2022/02/27 19:42:43 PathSeparator duration: 58ns, args:
2022/02/27 19:42:43 PathSeparator duration: 42ns, args:
2022/02/27 19:42:43 PathSeparator duration: 42ns, args:
2022/02/27 19:42:43 PathSeparator duration: 49ns, args:
2022/02/27 19:42:43 PathSeparator duration: 42ns, args:
2022/02/27 19:42:43 PathSeparator duration: 43ns, args:
2022/02/27 19:42:43 PathSeparator duration: 43ns, args:
2022/02/27 19:42:43 GOOS duration: 43ns, args:
2022/02/27 19:42:43 debug: Getenv

2022/02/27 19:42:43 Getenv duration: 924ns, args: WSL_DISTRO_NAME
2022/02/27 19:42:43 IsWsl duration: 2.571µs, args:
2022/02/27 19:42:43 StackCount duration: 95ns, args:
2022/02/27 19:42:43 TemplateCache duration: 115ns, args:
2022/02/27 19:42:43 debug: Pwd
/Users/jdiaz/test
2022/02/27 19:42:43 Pwd duration: 1.292µs, args:
2022/02/27 19:42:43 debug: Getenv

2022/02/27 19:42:43 Getenv duration: 980ns, args: WSL_DISTRO_NAME
2022/02/27 19:42:43 IsWsl duration: 2.606µs, args:
2022/02/27 19:42:43 GOOS duration: 59ns, args:
2022/02/27 19:42:43 HasCommand duration: 139.163µs, args: git
2022/02/27 19:42:43 debug: Pwd
/Users/jdiaz/test
2022/02/27 19:42:43 Pwd duration: 894ns, args:
2022/02/27 19:42:43 error: HasParentFilePath
stat /.git: no such file or directory
2022/02/27 19:42:43 HasParentFilePath duration: 31.877µs, args: .git
2022/02/27 19:42:43 debug: Pwd
/Users/jdiaz/test
2022/02/27 19:42:43 Pwd duration: 4.3µs, args:
2022/02/27 19:42:43 debug: Pwd
/Users/jdiaz/test
2022/02/27 19:42:43 Pwd duration: 1.236µs, args:
2022/02/27 19:42:43 debug: Pwd
/Users/jdiaz/test
2022/02/27 19:42:43 Pwd duration: 801ns, args:
2022/02/27 19:42:43 PathSeparator duration: 76ns, args:
2022/02/27 19:42:43 HasFiles duration: 104.463µs, args: *.js
2022/02/27 19:42:43 debug: Pwd
/Users/jdiaz/test
2022/02/27 19:42:43 Pwd duration: 996ns, args:
2022/02/27 19:42:43 PathSeparator duration: 76ns, args:
2022/02/27 19:42:43 HasFiles duration: 43.725µs, args: *.ts
2022/02/27 19:42:43 debug: Pwd
/Users/jdiaz/test
2022/02/27 19:42:43 Pwd duration: 945ns, args:
2022/02/27 19:42:43 PathSeparator duration: 64ns, args:
2022/02/27 19:42:43 HasFiles duration: 10.059µs, args: package.json
2022/02/27 19:42:43 debug: Pwd
/Users/jdiaz/test
2022/02/27 19:42:43 Pwd duration: 698ns, args:
2022/02/27 19:42:43 PathSeparator duration: 45ns, args:
2022/02/27 19:42:43 HasFiles duration: 7.118µs, args: .nvmrc
2022/02/27 19:42:43 debug: Pwd
/Users/jdiaz/test
2022/02/27 19:42:43 Pwd duration: 692ns, args:
2022/02/27 19:42:43 PathSeparator duration: 44ns, args:
2022/02/27 19:42:43 HasFiles duration: 7.455µs, args: pnpm-workspace.yaml
2022/02/27 19:42:43 debug: Pwd
/Users/jdiaz/test
2022/02/27 19:42:43 Pwd duration: 688ns, args:
2022/02/27 19:42:43 PathSeparator duration: 45ns, args:
2022/02/27 19:42:43 HasFiles duration: 6.751µs, args: .pnpmfile.cjs
2022/02/27 19:42:43 debug: Pwd
/Users/jdiaz/test
2022/02/27 19:42:43 Pwd duration: 894ns, args:
2022/02/27 19:42:43 PathSeparator duration: 45ns, args:
2022/02/27 19:42:43 HasFiles duration: 8.079µs, args: .npmrc
2022/02/27 19:42:43 debug: Pwd
/Users/jdiaz/test
2022/02/27 19:42:43 Pwd duration: 687ns, args:
2022/02/27 19:42:43 PathSeparator duration: 46ns, args:
2022/02/27 19:42:43 HasFiles duration: 6.889µs, args: .vue
2022/02/27 19:42:43 debug: Pwd
/Users/jdiaz/test
2022/02/27 19:42:43 Pwd duration: 909ns, args:
2022/02/27 19:42:43 debug: Pwd
/Users/jdiaz/test
2022/02/27 19:42:43 Pwd duration: 732ns, args:
2022/02/27 19:42:43 debug: Pwd
/Users/jdiaz/test
2022/02/27 19:42:43 Pwd duration: 724ns, args:
2022/02/27 19:42:43 PathSeparator duration: 46ns, args:
2022/02/27 19:42:43 HasFiles duration: 42.559µs, args: *.go
2022/02/27 19:42:43 debug: Pwd
/Users/jdiaz/test
2022/02/27 19:42:43 Pwd duration: 805ns, args:
2022/02/27 19:42:43 PathSeparator duration: 63ns, args:
2022/02/27 19:42:43 HasFiles duration: 11.006µs, args: go.mod
2022/02/27 19:42:43 debug: Pwd
/Users/jdiaz/test
2022/02/27 19:42:43 Pwd duration: 865ns, args:
2022/02/27 19:42:43 debug: Pwd
/Users/jdiaz/test
2022/02/27 19:42:43 Pwd duration: 682ns, args:
2022/02/27 19:42:43 debug: Pwd
/Users/jdiaz/test
2022/02/27 19:42:43 Pwd duration: 802ns, args:
2022/02/27 19:42:43 PathSeparator duration: 45ns, args:
2022/02/27 19:42:43 HasFiles duration: 42.968µs, args: *.jl
2022/02/27 19:42:43 debug: Pwd
/Users/jdiaz/test
2022/02/27 19:42:43 Pwd duration: 1.031µs, args:
2022/02/27 19:42:43 debug: Pwd
/Users/jdiaz/test
2022/02/27 19:42:43 Pwd duration: 720ns, args:
2022/02/27 19:42:43 debug: Pwd
/Users/jdiaz/test
2022/02/27 19:42:43 Pwd duration: 698ns, args:
2022/02/27 19:42:43 PathSeparator duration: 53ns, args:
2022/02/27 19:42:43 HasFiles duration: 42.63µs, args: *.py
2022/02/27 19:42:43 debug: Pwd
/Users/jdiaz/test
2022/02/27 19:42:43 Pwd duration: 787ns, args:
2022/02/27 19:42:43 PathSeparator duration: 48ns, args:
2022/02/27 19:42:43 HasFiles duration: 36.2µs, args: *.ipynb
2022/02/27 19:42:43 debug: Pwd
/Users/jdiaz/test
2022/02/27 19:42:43 Pwd duration: 777ns, args:
2022/02/27 19:42:43 PathSeparator duration: 44ns, args:
2022/02/27 19:42:43 HasFiles duration: 9.074µs, args: pyproject.toml
2022/02/27 19:42:43 debug: Pwd
/Users/jdiaz/test
2022/02/27 19:42:43 Pwd duration: 5.238µs, args:
2022/02/27 19:42:43 PathSeparator duration: 46ns, args:
2022/02/27 19:42:43 HasFiles duration: 12.133µs, args: venv.bak
2022/02/27 19:42:43 debug: Pwd
/Users/jdiaz/test
2022/02/27 19:42:43 Pwd duration: 688ns, args:
2022/02/27 19:42:43 PathSeparator duration: 46ns, args:
2022/02/27 19:42:43 HasFiles duration: 6.671µs, args: venv
2022/02/27 19:42:43 debug: Pwd
/Users/jdiaz/test
2022/02/27 19:42:43 Pwd duration: 676ns, args:
2022/02/27 19:42:43 PathSeparator duration: 45ns, args:
2022/02/27 19:42:43 HasFiles duration: 6.757µs, args: .venv
2022/02/27 19:42:43 debug: Pwd
/Users/jdiaz/test
2022/02/27 19:42:43 Pwd duration: 870ns, args:
2022/02/27 19:42:43 debug: Pwd
/Users/jdiaz/test
2022/02/27 19:42:43 Pwd duration: 706ns, args:
2022/02/27 19:42:43 debug: Pwd
/Users/jdiaz/test
2022/02/27 19:42:43 Pwd duration: 676ns, args:
2022/02/27 19:42:43 PathSeparator duration: 46ns, args:
2022/02/27 19:42:43 HasFiles duration: 42.617µs, args: *.rb
2022/02/27 19:42:43 debug: Pwd
/Users/jdiaz/test
2022/02/27 19:42:43 Pwd duration: 3.687µs, args:
2022/02/27 19:42:43 PathSeparator duration: 74ns, args:
2022/02/27 19:42:43 HasFiles duration: 22.14µs, args: Rakefile
2022/02/27 19:42:43 debug: Pwd
/Users/jdiaz/test
2022/02/27 19:42:43 Pwd duration: 910ns, args:
2022/02/27 19:42:43 PathSeparator duration: 47ns, args:
2022/02/27 19:42:43 HasFiles duration: 8.535µs, args: Gemfile
2022/02/27 19:42:43 debug: Pwd
/Users/jdiaz/test
2022/02/27 19:42:43 Pwd duration: 1.112µs, args:
2022/02/27 19:42:43 debug: Pwd
/Users/jdiaz/test
2022/02/27 19:42:43 Pwd duration: 777ns, args:
2022/02/27 19:42:43 debug: Pwd
/Users/jdiaz/test
2022/02/27 19:42:43 Pwd duration: 681ns, args:
2022/02/27 19:42:43 PathSeparator duration: 46ns, args:
2022/02/27 19:42:43 HasFiles duration: 8.824µs, args: host.json
2022/02/27 19:42:43 debug: Pwd
/Users/jdiaz/test
2022/02/27 19:42:43 Pwd duration: 699ns, args:
2022/02/27 19:42:43 PathSeparator duration: 46ns, args:
2022/02/27 19:42:43 HasFiles duration: 7.342µs, args: local.settings.json
2022/02/27 19:42:43 debug: Pwd
/Users/jdiaz/test
2022/02/27 19:42:43 Pwd duration: 689ns, args:
2022/02/27 19:42:43 PathSeparator duration: 44ns, args:
2022/02/27 19:42:43 HasFiles duration: 6.758µs, args: function.json
2022/02/27 19:42:43 debug: Pwd
/Users/jdiaz/test
2022/02/27 19:42:43 Pwd duration: 939ns, args:
2022/02/27 19:42:43 debug: Getenv

2022/02/27 19:42:43 Getenv duration: 1.068µs, args: AWS_VAULT
2022/02/27 19:42:43 debug: Getenv

2022/02/27 19:42:43 Getenv duration: 942ns, args: AWS_PROFILE
2022/02/27 19:42:43 debug: Getenv

2022/02/27 19:42:43 Getenv duration: 826ns, args: AWS_REGION
2022/02/27 19:42:43 debug: Getenv

2022/02/27 19:42:43 Getenv duration: 851ns, args: AWS_DEFAULT_REGION
2022/02/27 19:42:43 debug: Getenv

2022/02/27 19:42:43 Getenv duration: 847ns, args: AWS_CONFIG_FILE
2022/02/27 19:42:43 error: FileContent
open /Users/jdiaz/.aws/config: no such file or directory
2022/02/27 19:42:43 FileContent duration: 35.212µs, args: /Users/jdiaz/.aws/config
2022/02/27 19:42:43 debug: Pwd
/Users/jdiaz/test
2022/02/27 19:42:43 Pwd duration: 875ns, args:
2022/02/27 19:42:43 Root duration: 834ns, args:
2022/02/27 19:42:43 debug: Pwd
/Users/jdiaz/test
2022/02/27 19:42:43 Pwd duration: 804ns, args:
2022/02/27 19:42:43 ExecutionTime duration: 127ns, args:
2022/02/27 19:42:43 TemplateCache duration: 88ns, args:
2022/02/27 19:42:43 debug: Pwd
/Users/jdiaz/test
2022/02/27 19:42:43 Pwd duration: 1.294µs, args:
2022/02/27 19:42:43 ErrorCode duration: 69ns, args:
2022/02/27 19:42:43 TemplateCache duration: 89ns, args:
2022/02/27 19:42:43 TemplateCache duration: 106ns, args:
2022/02/27 19:42:43 debug: Pwd
/Users/jdiaz/test
2022/02/27 19:42:43 Pwd duration: 1.412µs, args:
2022/02/27 19:42:43 Shell duration: 118ns, args:
2022/02/27 19:42:43 TemplateCache duration: 96ns, args:
2022/02/27 19:42:43 debug: Pwd
/Users/jdiaz/test
2022/02/27 19:42:43 Pwd duration: 1.217µs, args:
2022/02/27 19:42:43 error: HTTPRequest
Get "http://127.0.0.1:9863/query": dial tcp 127.0.0.1:9863: connect: connection refused
2022/02/27 19:42:43 HTTPRequest duration: 381.095µs, args: http://127.0.0.1:9863/query
2022/02/27 19:42:43 debug: Pwd
/Users/jdiaz/test
2022/02/27 19:42:43 Pwd duration: 1.243µs, args:
2022/02/27 19:42:43 debug: Getenv

2022/02/27 19:42:43 Getenv duration: 1.047µs, args: WSL_DISTRO_NAME
2022/02/27 19:42:43 IsWsl duration: 2.581µs, args:
2022/02/27 19:42:43 BatteryInfo duration: 17.11458ms, args:
2022/02/27 19:42:43 TemplateCache duration: 242ns, args:
2022/02/27 19:42:43 TemplateCache duration: 113ns, args:
2022/02/27 19:42:43 debug: Pwd
/Users/jdiaz/test
2022/02/27 19:42:43 Pwd duration: 1.931µs, args:
2022/02/27 19:42:43 TemplateCache duration: 109ns, args:
2022/02/27 19:42:43 debug: Getenv

2022/02/27 19:42:43 Getenv duration: 1.671µs, args: XDG_CACHE_HOME
2022/02/27 19:42:43 CachePath duration: 38.064µs, args:
JanDeDobbeleer commented 2 years ago

@jacobo-diaz we actually use this ourselves but it's zle .reset-prompt for us.

jacobo-diaz commented 2 years ago

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.

JanDeDobbeleer commented 2 years ago

@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.

JanDeDobbeleer commented 2 years ago

@jacobo-diaz I tried your script but it doesn't even change the dir for me. Same setup, nothing works.

jacobo-diaz commented 2 years ago

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.

JanDeDobbeleer commented 2 years ago

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.

jacobo-diaz commented 2 years ago

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.

JanDeDobbeleer commented 2 years ago

@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.

jacobo-diaz commented 2 years ago

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.

JanDeDobbeleer commented 2 years ago

@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?

jacobo-diaz commented 2 years ago

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.

JanDeDobbeleer commented 2 years ago

@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.

JanDeDobbeleer commented 2 years ago

@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}
}
jacobo-diaz commented 2 years ago

It works. Thanks a lot @JanDeDobbeleer! I was confused because it worked with the default (and some other) prompts. Cheers!

github-actions[bot] commented 7 months ago

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.