JanDeDobbeleer / oh-my-posh

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

OMP breaks bash-preexec #5783

Closed ateijelo closed 2 weeks ago

ateijelo commented 3 weeks ago

Code of Conduct

What happened?

After upgrading from v18 to v23, a bash-preexec hook I had stopped working. The issue can be reproduced by setting up a preexec function just like the one on the quick start:

source ~/.bash-preexec.sh
# Define a couple functions.
preexec() { echo "just typed $1"; }
precmd() { echo "printing the prompt"; }

and sourcing that file.

The output just typed... never shows.

In the bash init code, changing the PROMPT_COMMAND setup like this:

-PROMPT_COMMAND=(_omp_hook "${PROMPT_COMMAND[@]}")
+PROMPT_COMMAND+=(_omp_hook)

seems to fix it.

Theme

disable_notice: true
auto_upgrade: false
console_title_template: "{{ .Shell }} ({{ .Folder }})"
blocks:
  - type: prompt
    alignment: left
    newline: false
    segments:
      - background: "#3a3a3a"
        foreground: "#ffffff"
        powerline_symbol: 
        properties:
          style: full
        style: powerline
        template: " {{ .Path }} "
        type: path
final_space: true
version: 2

What OS are you seeing the problem on?

Linux

Which shell are you using?

bash

Log output

Version: 23.20.2

Shell: bash (5.2.37(1)-release)

Prompt:

 ~/code/bash-eternal-history 

Segments:

ConsoleTitle(true)                        -   0 ms
Path(true)                                -   0 ms

Run duration: 1.472771ms

Cache path: /home/ateijelo/.cache/oh-my-posh

Config path: /home/ateijelo/.config/ohmyposh/basic.omp.yaml

Logs:

[DEBUG] 11:13:10.690 debug.go:49 → debug mode enabled
[DEBUG] 11:13:10.690 debug.go:49 → plain mode enabled
[DEBUG] 11:13:10.690 terminal.go:Getenv:164 → NO DATA
[TRACE] 11:13:10.690 terminal.go:Getenv(LOCALAPPDATA) - 13.74µs
[DEBUG] 11:13:10.690 terminal.go:Getenv:164 → NO DATA
[TRACE] 11:13:10.690 terminal.go:Getenv(OMP_CACHE_DIR) - 2.4µs
[DEBUG] 11:13:10.690 terminal.go:Getenv:164 → NO DATA
[TRACE] 11:13:10.690 terminal.go:Getenv(XDG_CACHE_HOME) - 2.36µs
[TRACE] 11:13:10.690 terminal.go:CachePath() - 40.71µs
[DEBUG] 11:13:10.690 terminal.go:70 → loading cache file: /home/ateijelo/.cache/oh-my-posh/omp.cache
[DEBUG] 11:13:10.690 terminal.go:70 → loading cache key: environment_platform
[DEBUG] 11:13:10.690 terminal.go:70 → loading cache key: is_wsl
[DEBUG] 11:13:10.690 terminal.go:70 → loading cache key: upgrade_check
[TRACE] 11:13:10.690 terminal.go(/home/ateijelo/.cache/oh-my-posh/omp.cache) - 71.441µs
[DEBUG] 11:13:10.690 terminal.go:Getenv:164 → NO DATA
[TRACE] 11:13:10.690 terminal.go:Getenv(LOCALAPPDATA) - 2.46µs
[DEBUG] 11:13:10.690 terminal.go:Getenv:164 → NO DATA
[TRACE] 11:13:10.690 terminal.go:Getenv(OMP_CACHE_DIR) - 2.16µs
[DEBUG] 11:13:10.690 terminal.go:Getenv:164 → NO DATA
[TRACE] 11:13:10.690 terminal.go:Getenv(XDG_CACHE_HOME) - 2.34µs
[TRACE] 11:13:10.690 terminal.go:CachePath() - 22.711µs
[DEBUG] 11:13:10.690 terminal.go:70 → loading cache file: /home/ateijelo/.cache/oh-my-posh/omp.cache.aa6a3b72-b2a6-448b-a3ed-3e966058c361
[DEBUG] 11:13:10.690 terminal.go:70 → loading cache key: prompt_count_cache
[TRACE] 11:13:10.690 terminal.go(/home/ateijelo/.cache/oh-my-posh/omp.cache.aa6a3b72-b2a6-448b-a3ed-3e966058c361) - 20.96µs
[TRACE] 11:13:10.690 terminal.go:setPromptCount() - 390ns
[DEBUG] 11:13:10.690 terminal.go:Getenv:164 → /home/ateijelo/.config/ohmyposh/basic.omp.yaml
[TRACE] 11:13:10.690 terminal.go:Getenv(POSH_THEME) - 2.69µs
[DEBUG] 11:13:10.690 terminal.go:ResolveConfigPath:96 → config set using POSH_THEME: /home/ateijelo/.config/ohmyposh/basic.omp.yaml
[TRACE] 11:13:10.690 terminal.go:ResolveConfigPath() - 8.65µs
[TRACE] 11:13:10.690 terminal.go:Init() - 243.693µs
[TRACE] 11:13:10.690 terminal.go:Flags() - 100ns
[TRACE] 11:13:10.691 load.go:loadConfig() - 274.214µs
[TRACE] 11:13:10.691 terminal.go:Flags() - 50ns
[DEBUG] 11:13:10.691 debug.go:57 → terminal program: WezTerm
[DEBUG] 11:13:10.691 debug.go:57 → terminal shell: shell
[DEBUG] 11:13:10.691 terminal.go:Getenv:164 → NO DATA
[TRACE] 11:13:10.691 terminal.go:Getenv(OMP_CACHE_DISABLED) - 3.29µs
[TRACE] 11:13:10.691 colors.go:SetAccentColor() - 640ns
[TRACE] 11:13:10.691 terminal.go:Shell() - 80ns
[DEBUG] 11:13:10.691 terminal.go:Getenv:164 → 5.2.37(1)-release
[TRACE] 11:13:10.691 terminal.go:Getenv(POSH_SHELL_VERSION) - 2.69µs
[DEBUG] 11:13:10.691 debug.go:PrintDebug:23 → segment: Title
[DEBUG] 11:13:10.691 text.go:Render:80 → rendering template: {{ .Shell }} ({{ .Folder }})
[TRACE] 11:13:10.691 terminal.go:Flags() - 30ns
[TRACE] 11:13:10.691 terminal_unix.go:Root() - 500ns
[TRACE] 11:13:10.691 terminal.go:Shell() - 30ns
[TRACE] 11:13:10.691 terminal.go:StatusCodes() - 60ns
[DEBUG] 11:13:10.691 terminal_unix.go:IsWsl:35 → false
[TRACE] 11:13:10.691 terminal_unix.go:IsWsl() - 3.54µs
[DEBUG] 11:13:10.691 terminal.go:TemplateCache:673 → environment: [SHELL=/bin/bash SESSION_MANAGER=local/emma:@/tmp/.ICE-unix/1247445,unix/emma:/tmp/.ICE-unix/1247445 COLORTERM=truecolor XDG_SESSION_PATH=/org/freedesktop/DisplayManager/Session5 HISTCONTROL=ignoredups: TERM_PROGRAM_VERSION=20240203-110809-5046fc22 GNOME_DESKTOP_SESSION_ID=this-is-deprecated WEZTERM_CONFIG_DIR=/home/ateijelo/.config/wezterm LC_ADDRESS=en_CA.UTF-8 SAM_CLI_TELEMETRY=0 LC_NAME=en_CA.UTF-8 WEZTERM_EXECUTABLE=/usr/bin/wezterm-gui DESKTOP_SESSION=cinnamon LC_MONETARY=en_CA.UTF-8 EDITOR=/usr/local/bin/nvim GTK_MODULES=canberra-gtk-module XDG_SEAT=seat0 PWD=/home/ateijelo/code/bash-eternal-history GSETTINGS_SCHEMA_DIR=/home/ateijelo/data XDG_SESSION_DESKTOP= LOGNAME=ateijelo XDG_SESSION_TYPE=x11 XAUTHORITY=/tmp/xauth_NhrRom MOTD_SHOWN=pam HOME=/home/ateijelo LC_PAPER=en_CA.UTF-8 LANG=en_CA.UTF-8 WEZTERM_UNIX_SOCKET=/run/user/1000/wezterm/gui-sock-1249836 LS_COLORS=rs=0:di=01;34:ln=01;36:mh=00:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:mi=00:su=37;41:sg=30;43:ca=00:tw=30;42:ow=34;42:st=37;44:ex=01;32:*.7z=01;31:*.ace=01;31:*.alz=01;31:*.apk=01;31:*.arc=01;31:*.arj=01;31:*.bz=01;31:*.bz2=01;31:*.cab=01;31:*.cpio=01;31:*.crate=01;31:*.deb=01;31:*.drpm=01;31:*.dwm=01;31:*.dz=01;31:*.ear=01;31:*.egg=01;31:*.esd=01;31:*.gz=01;31:*.jar=01;31:*.lha=01;31:*.lrz=01;31:*.lz=01;31:*.lz4=01;31:*.lzh=01;31:*.lzma=01;31:*.lzo=01;31:*.pyz=01;31:*.rar=01;31:*.rpm=01;31:*.rz=01;31:*.sar=01;31:*.swm=01;31:*.t7z=01;31:*.tar=01;31:*.taz=01;31:*.tbz=01;31:*.tbz2=01;31:*.tgz=01;31:*.tlz=01;31:*.txz=01;31:*.tz=01;31:*.tzo=01;31:*.tzst=01;31:*.udeb=01;31:*.war=01;31:*.whl=01;31:*.wim=01;31:*.xz=01;31:*.z=01;31:*.zip=01;31:*.zoo=01;31:*.zst=01;31:*.avif=01;35:*.jpg=01;35:*.jpeg=01;35:*.mjpg=01;35:*.mjpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.svg=01;35:*.svgz=01;35:*.mng=01;35:*.pcx=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.m2v=01;35:*.mkv=01;35:*.webm=01;35:*.webp=01;35:*.ogm=01;35:*.mp4=01;35:*.m4v=01;35:*.mp4v=01;35:*.vob=01;35:*.qt=01;35:*.nuv=01;35:*.wmv=01;35:*.asf=01;35:*.rm=01;35:*.rmvb=01;35:*.flc=01;35:*.avi=01;35:*.fli=01;35:*.flv=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.yuv=01;35:*.cgm=01;35:*.emf=01;35:*.ogv=01;35:*.ogx=01;35:*.aac=00;36:*.au=00;36:*.flac=00;36:*.m4a=00;36:*.mid=00;36:*.midi=00;36:*.mka=00;36:*.mp3=00;36:*.mpc=00;36:*.ogg=00;36:*.ra=00;36:*.wav=00;36:*.oga=00;36:*.opus=00;36:*.spx=00;36:*.xspf=00;36:*~=00;90:*#=00;90:*.bak=00;90:*.crdownload=00;90:*.dpkg-dist=00;90:*.dpkg-new=00;90:*.dpkg-old=00;90:*.dpkg-tmp=00;90:*.old=00;90:*.orig=00;90:*.part=00;90:*.rej=00;90:*.rpmnew=00;90:*.rpmorig=00;90:*.rpmsave=00;90:*.swp=00;90:*.tmp=00;90:*.ucf-dist=00;90:*.ucf-new=00;90:*.ucf-old=00;90: XDG_CURRENT_DESKTOP=X-Cinnamon POSH_SHELL_VERSION=5.2.37(1)-release POSH_SESSION_ID=aa6a3b72-b2a6-448b-a3ed-3e966058c361 OSTYPE=linux-gnu CONDA_PROMPT_MODIFIER=false XDG_SEAT_PATH=/org/freedesktop/DisplayManager/Seat0 BAO_ADDR=https://vault.rainfrog.net/ XDG_SESSION_CLASS=user TERM=xterm-256color LC_IDENTIFICATION=en_CA.UTF-8 LIBVIRT_DEFAULT_URI=qemu:///system USER=ateijelo PAM_KWALLET5_LOGIN=/run/user/1000/kwallet5.socket VISUAL=/usr/local/bin/nvim DISPLAY=:0 SHLVL=1 LC_TELEPHONE=en_CA.UTF-8 LC_MEASUREMENT=en_CA.UTF-8 XDG_VTNR=2 XDG_SESSION_ID=2934 POSH_THEME=/home/ateijelo/.config/ohmyposh/basic.omp.yaml WEZTERM_CONFIG_FILE=/home/ateijelo/.config/wezterm/wezterm.lua XDG_RUNTIME_DIR=/run/user/1000 JQ_COLORS=1;36:0;36:0;36:0;39:0;32:1;39:1;39 DEBUGINFOD_URLS=https://debuginfod.archlinux.org  LC_TIME=en_CA.UTF-8 QT_AUTO_SCREEN_SCALE_FACTOR=1 GTK3_MODULES=xapp-gtk3-module XDG_DATA_DIRS=/home/ateijelo/.local/share/flatpak/exports/share:/var/lib/flatpak/exports/share:/usr/local/share:/usr/share PATH=/home/ateijelo/.poetry/bin:/home/ateijelo/.krew/bin:/home/ateijelo/.poetry/bin:/home/ateijelo/.poetry/bin:/home/ateijelo/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/bin:/var/lib/flatpak/exports/bin:/usr/lib/jvm/default/bin:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl:/opt/rocm/bin:/usr/lib/rustup/bin:/home/ateijelo/code/go/bin:/home/ateijelo/.local/bin DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1000/bus NEBULA_CA_KEY=/home/ateijelo/.nebula-ca.key MAIL=/var/spool/mail/ateijelo POWERLINE_COMMAND=oh-my-posh NEBULA_CA_CRT=/etc/nebula/ca.crt GIO_LAUNCHED_DESKTOP_FILE_PID=1249836 GIO_LAUNCHED_DESKTOP_FILE=/usr/share/applications/org.wezfurlong.wezterm.desktop LC_NUMERIC=en_CA.UTF-8 WEZTERM_PANE=123 GOPATH=/home/ateijelo/code/go TERM_PROGRAM=WezTerm WEZTERM_EXECUTABLE_DIR=/usr/bin _=/usr/local/bin/oh-my-posh]
[TRACE] 11:13:10.691 terminal.go:GOOS() - 100ns
[TRACE] 11:13:10.691 terminal.go:PathSeparator() - 2.88µs
[TRACE] 11:13:10.691 terminal.go:GOOS() - 20ns
[DEBUG] 11:13:10.691 terminal.go:Pwd:189 → /home/ateijelo/code/bash-eternal-history
[TRACE] 11:13:10.691 terminal.go:Pwd() - 25.47µs
[DEBUG] 11:13:10.691 terminal_unix.go:IsWsl:35 → false
[TRACE] 11:13:10.691 terminal_unix.go:IsWsl() - 2.3µs
[TRACE] 11:13:10.691 terminal.go:GOOS() - 20ns
[TRACE] 11:13:10.691 terminal.go:GOOS() - 20ns
[TRACE] 11:13:10.691 terminal.go:GOOS() - 20ns
[TRACE] 11:13:10.691 terminal.go:GOOS() - 30ns
[TRACE] 11:13:10.691 terminal.go:GOOS() - 20ns
[TRACE] 11:13:10.691 terminal.go:GOOS() - 20ns
[TRACE] 11:13:10.691 terminal.go:GOOS() - 20ns
[TRACE] 11:13:10.691 terminal.go:GOOS() - 30ns
[TRACE] 11:13:10.691 terminal.go:GOOS() - 30ns
[TRACE] 11:13:10.691 terminal.go:GOOS() - 30ns
[TRACE] 11:13:10.691 terminal.go:GOOS() - 30ns
[TRACE] 11:13:10.691 terminal.go:GOOS() - 20ns
[TRACE] 11:13:10.691 terminal.go:GOOS() - 30ns
[TRACE] 11:13:10.691 terminal.go:GOOS() - 20ns
[TRACE] 11:13:10.691 terminal.go:GOOS() - 20ns
[TRACE] 11:13:10.691 terminal.go:GOOS() - 20ns
[TRACE] 11:13:10.691 terminal.go:GOOS() - 30ns
[TRACE] 11:13:10.691 terminal.go:GOOS() - 20ns
[TRACE] 11:13:10.691 terminal.go:GOOS() - 20ns
[TRACE] 11:13:10.691 terminal.go:GOOS() - 20ns
[TRACE] 11:13:10.691 terminal.go:GOOS() - 20ns
[TRACE] 11:13:10.691 terminal.go:GOOS() - 30ns
[DEBUG] 11:13:10.691 terminal.go:User:330 → ateijelo
[TRACE] 11:13:10.691 terminal.go:User() - 2.42µs
[DEBUG] 11:13:10.691 terminal.go:Host:347 → emma
[TRACE] 11:13:10.691 terminal.go:Host() - 3.09µs
[TRACE] 11:13:10.691 terminal.go:GOOS() - 20ns
[DEBUG] 11:13:10.691 terminal_unix.go:Platform:92 → manjaro
[DEBUG] 11:13:10.691 terminal.go:Getenv:164 → 1
[TRACE] 11:13:10.691 terminal.go:Getenv(SHLVL) - 2.13µs
[TRACE] 11:13:10.691 terminal.go:TemplateCache() - 139.722µs
[TRACE] 11:13:10.691 terminal.go:Shell() - 20ns
[DEBUG] 11:13:10.691 terminal.go:Getenv:164 → NO DATA
[TRACE] 11:13:10.691 terminal.go:Getenv(POSH_CURSOR_LINE) - 1.971µs
[DEBUG] 11:13:10.691 terminal.go:Getenv:164 → NO DATA
[TRACE] 11:13:10.691 terminal.go:Getenv(POSH_CURSOR_COLUMN) - 1.75µs
[TRACE] 11:13:10.691 terminal.go:Flags() - 30ns
[TRACE] 11:13:10.691 terminal.go:Flags() - 20ns
[TRACE] 11:13:10.691 terminal.go:Flags() - 40ns
[TRACE] 11:13:10.691 terminal.go:Pwd() - 60ns
[TRACE] 11:13:10.691 terminal.go:GOOS() - 20ns
[DEBUG] 11:13:10.691 segment.go:SetEnabled:115 → segment: Path
[DEBUG] 11:13:10.691 path.go:149 → display_cygpath: false
[TRACE] 11:13:10.691 terminal.go:GOOS() - 20ns
[TRACE] 11:13:10.691 terminal.go:GOOS() - 30ns
[TRACE] 11:13:10.691 terminal.go:PathSeparator() - 1.77µs
[TRACE] 11:13:10.691 terminal.go:Pwd() - 50ns
[TRACE] 11:13:10.691 terminal.go:Shell() - 30ns
[TRACE] 11:13:10.691 terminal.go:Shell() - 20ns
[TRACE] 11:13:10.691 terminal.go:GOOS() - 30ns
[DEBUG] 11:13:10.691 path.go:setMappedLocations:563 → mapped_locations_enabled: true
[DEBUG] 11:13:10.691 path.go:setMappedLocations:564 → 
[DEBUG] 11:13:10.691 path.go:setMappedLocations:565 → 
[TRACE] 11:13:10.691 terminal.go:GOOS() - 20ns
[TRACE] 11:13:10.691 terminal.go:PathSeparator() - 17.58µs
[TRACE] 11:13:10.691 terminal.go:GOOS() - 30ns
[TRACE] 11:13:10.691 terminal.go:GOOS() - 30ns
[TRACE] 11:13:10.691 terminal.go:GOOS() - 30ns
[DEBUG] 11:13:10.691 path.go:setMappedLocations:566 → ~
[DEBUG] 11:13:10.691 path.go:setMappedLocations:571 → mapped_locations: map[]
[TRACE] 11:13:10.691 terminal.go:GOOS() - 20ns
[TRACE] 11:13:10.691 terminal.go:PathSeparator() - 1.87µs
[TRACE] 11:13:10.691 terminal.go:GOOS() - 20ns
[TRACE] 11:13:10.691 terminal.go:GOOS() - 20ns
[TRACE] 11:13:10.691 terminal.go:GOOS() - 20ns
[TRACE] 11:13:10.691 terminal.go:GOOS() - 30ns
[TRACE] 11:13:10.691 terminal.go:PathSeparator() - 1.61µs
[TRACE] 11:13:10.691 terminal.go:GOOS() - 30ns
[TRACE] 11:13:10.691 terminal.go:GOOS() - 20ns
[TRACE] 11:13:10.691 terminal.go:GOOS() - 30ns
[TRACE] 11:13:10.691 terminal.go:GOOS() - 30ns
[TRACE] 11:13:10.691 terminal.go:GOOS() - 20ns
[TRACE] 11:13:10.691 terminal.go:GOOS() - 20ns
[TRACE] 11:13:10.691 terminal.go:GOOS() - 30ns
[TRACE] 11:13:10.691 terminal.go:GOOS() - 20ns
[DEBUG] 11:13:10.691 path.go:makeFolderFormatMap:839 → NO DATA
[TRACE] 11:13:10.691 terminal.go:GOOS() - 20ns
[DEBUG] 11:13:10.691 path.go:setStyle:218 → full
[DEBUG] 11:13:10.691 path.go:colorizePath:740 → cycle: []
[DEBUG] 11:13:10.691 path.go:getFolderSeparator:273 → NO DATA
[DEBUG] 11:13:10.691 path.go:getFolderSeparator:275 → /
[DEBUG] 11:13:10.691 path.go:colorizePath:743 → cycle_folder_separator: false
[DEBUG] 11:13:10.691 path.go:colorizePath:744 → %s
[DEBUG] 11:13:10.691 path.go:colorizePath:746 → %s
[DEBUG] 11:13:10.691 path.go:colorizePath:747 → %s
[DEBUG] 11:13:10.691 path.go:colorizePath:748 → %s
[TRACE] 11:13:10.691 terminal.go:GOOS() - 20ns
[TRACE] 11:13:10.691 terminal.go:Pwd() - 60ns
[TRACE] 11:13:10.691 terminal.go:TemplateCache() - 70ns
[TRACE] 11:13:10.691 terminal.go:GOOS() - 30ns
[TRACE] 11:13:10.691 terminal.go:StackCount() - 40ns
[TRACE] 11:13:10.691 terminal_unix.go:DirIsWritable(/home/ateijelo/code/bash-eternal-history) - 3.4µs
[TRACE] 11:13:10.691 terminal.go:TemplateCache() - 50ns
[DEBUG] 11:13:10.691 text.go:Render:80 → rendering template:  {{ .Path }}
[TRACE] 11:13:10.691 terminal.go:Flags() - 30ns
[TRACE] 11:13:10.691 terminal.go:TemplateCache() - 70ns
[DEBUG] 11:13:10.691 text.go:Render:80 → rendering template: powerline
[TRACE] 11:13:10.691 terminal.go:Flags() - 30ns
[TRACE] 11:13:10.691 terminal.go:Shell() - 60ns
[TRACE] 11:13:10.691 terminal.go:Shell() - 30ns
[TRACE] 11:13:10.691 terminal.go:Flags() - 20ns
[TRACE] 11:13:10.691 terminal.go:Shell() - 30ns
[DEBUG] 11:13:10.691 terminal.go:Getenv:164 → NO DATA
[TRACE] 11:13:10.691 terminal.go:Getenv(LOCALAPPDATA) - 2.13µs
[DEBUG] 11:13:10.691 terminal.go:Getenv:164 → NO DATA
[TRACE] 11:13:10.691 terminal.go:Getenv(OMP_CACHE_DIR) - 1.87µs
[DEBUG] 11:13:10.691 terminal.go:Getenv:164 → NO DATA
[TRACE] 11:13:10.691 terminal.go:Getenv(XDG_CACHE_HOME) - 1.67µs
[TRACE] 11:13:10.691 terminal.go:CachePath() - 19.32µs
[TRACE] 11:13:10.691 terminal.go:Flags() - 20ns
JanDeDobbeleer commented 3 weeks ago

@lewis-yeung you're more at home in these matters, what's your input?

lewis-yeung commented 3 weeks ago

@ateijelo Do you source bash-preexec at the end of your Bash profile? I cannot "fully" reproduce the bug. I mean, if I put the example code before the OMP eval line, neither of the two hook works, but both of them will work if sourced after OMP.

ateijelo commented 3 weeks ago

It fails for me both when I source the bash-preexec example in /etc/bash.bashrc after OMP, and if I source it interactively at the prompt. I copied the OMP init code to a file and sourced it to try to figure out what was happening and this change:

-PROMPT_COMMAND=(_omp_hook "${PROMPT_COMMAND[@]}")
+PROMPT_COMMAND+=(_omp_hook)

fixed the issue.

I'm not sure if eval vs source could be the source of the problem. I'll look at it in more depth tonight.

ateijelo commented 3 weeks ago

@lewis-yeung I tried again on a fresh Debian VM and it behaved as you described. With this /etc/bash.bashrc (and and empty ~/.bashrc):

source /root/.bash-preexec.sh
preexec() { echo "just typed $1"; }
precmd() { echo "printing the prompt"; }

eval "$(oh-my-posh init bash)"

The just typed text only shows after the first command, but not on the following commands:

image

If I eval OMP before pre-exec:

eval "$(oh-my-posh init bash)"

source /root/.bash-preexec.sh
preexec() { echo "just typed $1"; }
precmd() { echo "printing the prompt"; }

then everything works fine:

image

If I change the eval line to this:

eval "$(oh-my-posh init bash | sed '/PROMPT_COMMAND=/c\    PROMPT_COMMAND+=(_omp_hook)')"

Then it almost works perfectly regardless of whether OMP's eval was before or after prexec, except on the very first command:

image

ateijelo commented 3 weeks ago

Oh, and saving the output of oh-my-posh init bash to a file and sourcing it makes no difference.

lewis-yeung commented 2 weeks ago

@ateijelo As the documentation of bash-preexec says:

It must be the last thing imported in your bash profile.

it's recommended to source bash-preexec at the end of the profile to avoid unexpected issues, not just this one.

JanDeDobbeleer commented 2 weeks ago

@ateijelo if the above comment works, can we close this?

ateijelo commented 2 weeks ago

@lewis-yeung @JanDeDobbeleer I'm ok with closing this, since there's a workaround, but Oh-My-Posh documentation also asks to be the last thing in your profile.

In general, it's always tricky when a component asks to be the last or first to be imported. It only works until two components ask the same.

JanDeDobbeleer commented 2 weeks ago

@ateijelo true, but that's due to shell limitations. There's bound to be compatibility issues when we both hijack the same.

ateijelo commented 2 weeks ago

bash-preexec has moved towards working in any order: https://github.com/rcaloras/bash-preexec/pull/110, but perhaps it's not quite working.

I think OMP would benefit from the same.