JanDeDobbeleer / oh-my-posh

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

themes don't work across mac CPU architectures #2599

Closed masukomi closed 2 years ago

masukomi commented 2 years ago

Code of Conduct

What happened?

Expected Behavior

As a user I expect to be able to sync my oh-my-posh theme between computers that are using the same operating system, shell, and have used the same mechanism to install oh-my-posh

Actual Behavior

I generated an oh-my-posh theme for fish shell on an intel mac. I then synced my theme to my arm mac. The them stopped working because oh-my-posh was not found.

this is because homebrew installs things into different locations depending on a variety of factors. See their documentation for details

Desired change

Rather than hardcoding the path to oh-my-posh the generated theme should utilize the results of calling brew --prefix when brew has been installed with homebrew.

for example. Instead of /user/local/bin/oh-my-posh the path would be $HOMEBREW_PREFIX/bin/oh-my-posh where $HOMEBREW_PREFIX has been previously set to be the result of calling brew --prefix using whatever shell syntax is appropriate for the generated shell's theme.

Theme

a) custom b) not relevant

What OS are you seeing the problem on?

macOS

Which shell are you using?

fish

Log output

❯ oh-my-posh debug

Version: 8.24.0

Segments:

ConsoleTitle(false) -   0 ms -
session(true)  -   0 ms -  masukomi
path(true)     -   0 ms -  ~/workspace/rtest
time(true)     -   0 ms -  ♥ 16:29 
git(true)      -   0 ms -  ➜ (next) 
exit(true)     -   0 ms - ❯

Run duration: 3.455417ms

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

Config path: /Users/masukomi/.config/fish/current_theme.omp.json

Logs:

2022/07/31 16:29:21 debug: Getenv

2022/07/31 16:29:21 Getenv duration: 13.5µs, args: XDG_CACHE_HOME
2022/07/31 16:29:21 CachePath duration: 44.208µs, args:
2022/07/31 16:29:21 debug: Getenv
/Users/masukomi/.config/fish/current_theme.omp.json
2022/07/31 16:29:21 Getenv duration: 3.625µs, args: POSH_THEME
2022/07/31 16:29:21 resolveConfigPath duration: 7.625µs, args:
2022/07/31 16:29:21 Init duration: 181.958µs, args:
2022/07/31 16:29:21 Flags duration: 42ns, args:
2022/07/31 16:29:21 config.loadConfig duration: 434.917µs, args:
2022/07/31 16:29:21 Flags duration: 83ns, args:
2022/07/31 16:29:21 debug: Getenv

2022/07/31 16:29:21 Getenv duration: 1.375µs, args: OMP_CACHE_DISABLED
2022/07/31 16:29:21 Root duration: 1µs, args:
2022/07/31 16:29:21 Shell duration: 71.667µs, args:
2022/07/31 16:29:21 ErrorCode duration: 83ns, args:
2022/07/31 16:29:21 debug: Getenv

2022/07/31 16:29:21 Getenv duration: 1.291µs, args: WSL_DISTRO_NAME
2022/07/31 16:29:21 IsWsl duration: 2.625µs, args:
2022/07/31 16:29:21 debug: Pwd
/Users/masukomi/workspace/rtest
2022/07/31 16:29:21 Pwd duration: 13.667µs, args:
2022/07/31 16:29:21 PathSeparator duration: 583ns, args:
2022/07/31 16:29:21 PathSeparator duration: 41ns, args:
2022/07/31 16:29:21 PathSeparator duration: 42ns, args:
2022/07/31 16:29:21 PathSeparator duration: 41ns, args:
2022/07/31 16:29:21 PathSeparator duration: 41ns, args:
2022/07/31 16:29:21 PathSeparator duration: 41ns, args:
2022/07/31 16:29:21 PathSeparator duration: 83ns, args:
2022/07/31 16:29:21 debug: User
masukomi
2022/07/31 16:29:21 User duration: 917ns, args:
2022/07/31 16:29:21 debug: Host
kays-M1
2022/07/31 16:29:21 Host duration: 7.833µs, args:
2022/07/31 16:29:21 GOOS duration: 83ns, args:
2022/07/31 16:29:21 TemplateCache duration: 150.75µs, args:
2022/07/31 16:29:21 Flags duration: 42ns, args:
2022/07/31 16:29:21 debug: Pwd
/Users/masukomi/workspace/rtest
2022/07/31 16:29:21 Pwd duration: 958ns, args:
2022/07/31 16:29:21 GOOS duration: 41ns, args:
2022/07/31 16:29:21 debug: Getenv

2022/07/31 16:29:21 Getenv duration: 917ns, args: SSH_CONNECTION
2022/07/31 16:29:21 debug: Getenv

2022/07/31 16:29:21 Getenv duration: 917ns, args: SSH_CLIENT
2022/07/31 16:29:21 TemplateCache duration: 42ns, args:
2022/07/31 16:29:21 TemplateCache duration: 83ns, args:
2022/07/31 16:29:21 Shell duration: 125ns, args:
2022/07/31 16:29:21 debug: Pwd
/Users/masukomi/workspace/rtest
2022/07/31 16:29:21 Pwd duration: 1.041µs, args:
2022/07/31 16:29:21 GOOS duration: 42ns, args:
2022/07/31 16:29:21 debug: Pwd
/Users/masukomi/workspace/rtest
2022/07/31 16:29:21 Pwd duration: 792ns, args:
2022/07/31 16:29:21 Flags duration: 84ns, args:
2022/07/31 16:29:21 debug: Pwd
/Users/masukomi/workspace/rtest
2022/07/31 16:29:21 Pwd duration: 750ns, args:
2022/07/31 16:29:21 GOOS duration: 41ns, args:
2022/07/31 16:29:21 GOOS duration: 83ns, args:
2022/07/31 16:29:21 PathSeparator duration: 42ns, args:
2022/07/31 16:29:21 PathSeparator duration: 42ns, args:
2022/07/31 16:29:21 GOOS duration: 42ns, args:
2022/07/31 16:29:21 debug: Getenv

2022/07/31 16:29:21 Getenv duration: 917ns, args: WSL_DISTRO_NAME
2022/07/31 16:29:21 IsWsl duration: 2.208µs, args:
2022/07/31 16:29:21 StackCount duration: 583ns, args:
2022/07/31 16:29:21 DirIsWritable duration: 7.125µs, args:
2022/07/31 16:29:21 TemplateCache duration: 41ns, args:
2022/07/31 16:29:21 TemplateCache duration: 42ns, args:
2022/07/31 16:29:21 Shell duration: 84ns, args:
2022/07/31 16:29:21 debug: Pwd
/Users/masukomi/workspace/rtest
2022/07/31 16:29:21 Pwd duration: 1µs, args:
2022/07/31 16:29:21 GOOS duration: 42ns, args:
2022/07/31 16:29:21 TemplateCache duration: 41ns, args:
2022/07/31 16:29:21 TemplateCache duration: 83ns, args:
2022/07/31 16:29:21 Shell duration: 41ns, args:
2022/07/31 16:29:21 Flags duration: 42ns, args:
2022/07/31 16:29:21 debug: Pwd
/Users/masukomi/workspace/rtest
2022/07/31 16:29:21 Pwd duration: 875ns, args:
2022/07/31 16:29:21 GOOS duration: 84ns, args:
2022/07/31 16:29:21 debug: Getenv

2022/07/31 16:29:21 Getenv duration: 959ns, args: WSL_DISTRO_NAME
2022/07/31 16:29:21 IsWsl duration: 7.125µs, args:
2022/07/31 16:29:21 GOOS duration: 83ns, args:
2022/07/31 16:29:21 debug: CommandPath
/usr/bin/git
2022/07/31 16:29:21 CommandPath duration: 144.167µs, args: git
2022/07/31 16:29:21 HasCommand duration: 145.875µs, args: git
2022/07/31 16:29:21 debug: Pwd
/Users/masukomi/workspace/rtest
2022/07/31 16:29:21 Pwd duration: 625ns, args:
2022/07/31 16:29:21 HasParentFilePath duration: 11.291µs, args: .git
2022/07/31 16:29:21 PathSeparator duration: 41ns, args:
2022/07/31 16:29:21 PathSeparator duration: 42ns, args:
2022/07/31 16:29:21 PathSeparator duration: 83ns, args:
2022/07/31 16:29:21 PathSeparator duration: 42ns, args:
2022/07/31 16:29:21 PathSeparator duration: 83ns, args:
2022/07/31 16:29:21 PathSeparator duration: 42ns, args:
2022/07/31 16:29:21 PathSeparator duration: 84ns, args:
2022/07/31 16:29:21 PathSeparator duration: 84ns, args:
2022/07/31 16:29:21 debug: FileContent
ref: refs/heads/next

2022/07/31 16:29:21 FileContent duration: 25.792µs, args: /Users/masukomi/workspace/rtest/.git/HEAD
2022/07/31 16:29:21 error: FileContent
open /Users/masukomi/workspace/rtest/.git/logs/refs/stash: no such file or directory
2022/07/31 16:29:21 FileContent duration: 12.375µs, args: /Users/masukomi/workspace/rtest/.git/logs/refs/stash
2022/07/31 16:29:21 TemplateCache duration: 42ns, args:
2022/07/31 16:29:21 TemplateCache duration: 167ns, args:
2022/07/31 16:29:21 Shell duration: 125ns, args:
2022/07/31 16:29:21 Flags duration: 41ns, args:
2022/07/31 16:29:21 debug: Pwd
/Users/masukomi/workspace/rtest
2022/07/31 16:29:21 Pwd duration: 1.208µs, args:
2022/07/31 16:29:21 GOOS duration: 42ns, args:
2022/07/31 16:29:21 ErrorCode duration: 42ns, args:
2022/07/31 16:29:21 TemplateCache duration: 42ns, args:
2022/07/31 16:29:21 TemplateCache duration: 83ns, args:
2022/07/31 16:29:21 Shell duration: 42ns, args:
2022/07/31 16:29:21 TemplateCache duration: 84ns, args:
2022/07/31 16:29:21 debug: Getenv

2022/07/31 16:29:21 Getenv duration: 1.25µs, args: XDG_CACHE_HOME
2022/07/31 16:29:21 CachePath duration: 13.666µs, args:
2022/07/31 16:29:21 Flags duration: 83ns, args:
JanDeDobbeleer commented 2 years ago

@masukomi I don't see how this has something to do with oh-my-posh? The theme/config has nothing to do with the executable, that's up to the user to install on every device. And the theme/config works cross platform (unless it contains platform specific segments/scripts) when the executable is present. Otherwise there's nothing to initialize the shell anyways, the logic is coming from the executable, not the config/theme.

But maybe I'm missing the point, I've read this 4 times now going back and forth. In case you're syncing the init script, that's not the way to use oh-my-posh. The only line in your config has to be oh-my-posh init fish | source and the path to oh-my-posh is NOT hardcoded, it comes from the actual executable's location on your system. So for system A that line can output a completely different path to oh-my-posh than B as it's generated on shell start based on the oh-my-posh executable running the init functionality.

masukomi commented 2 years ago

sorry about the delay:

I don't see how this has something to do with oh-my-posh?

it has something to do with oh-my-posh because oh-my-posh is the codebase responsible for generating the theme with the unnecessarily hardcoded path that causes problems when an oh-my-posh generated theme is synced between macos devices with different architectures (even when they have the same os version).

And the theme/config works cross platform

that's my point. even within the same platform (macOS), generated themes do not work across architecture. BUT it's an easily solvable problem.

The problem is that oh-my-posh init fish --config path/to/theme.omp.json generates a them with a hardcoded path /user/local/bin/oh-my-posh . It should not, at least not if it's been installed with homebrew. The problem is that that the homebrew install location of oh-my-posh, and everything else, differs depending on which architecture you're running (intel or arm).

the solution, as i noted above, is

  1. ask homebrew where it's installing things: brew --prefix
  2. store the result in a variable
  3. instead of generating a hardcoded path to oh-my-posh generate a path that starts with the variable you stored the results of brew -prefix in.

If that change is made (to oh-my-posh) then users of it who, like me, have a work machine on a different architecture than their personal machine, can simply sync their themes (along with other dot files) between machines.

While I see how oh-my-posh ended up generating hardcoded paths (who would have expected apple to do something so silly), it's a simple fix that makes lives easier for folks with more than one computer.

As it currently stands I have to regenerate it every time i sync configuration files between computers.

Currently i have to run this script to compensate whenever i want to tweak my theme

oh-my-posh init fish --config ~/.config/fish/current_theme.omp.json \
    | sed -e "s/'.*\/bin\/oh-my-posh'/PREFIX=\(brew --prefix\) \"\$PREFIX\/bin\/oh-my-posh\"/" \
        -e "s/$USER/\$USER/" \
        -e "s/POSH_THEME '\(.*\)'/POSH_THEME \"\1\"/" \
    > ~/.config/fish/current_theme.fish

here's the difference between what oh-my-posh generates and the genericised cross-architecture version

1c1
< set --export POSH_THEME '/Users/masukomi/.config/fish/current_theme.omp.json'
---
> set --export POSH_THEME "/Users/$USER/.config/fish/current_theme.omp.json"
14c14
<       '/opt/homebrew/bin/oh-my-posh' print transient --config $POSH_THEME --shell fish --error $omp_status_cache --execution-time $omp_duration --stack-count $omp_stack_count --shell-version $FISH_VERSION
---
>       PREFIX=(brew --prefix) "$PREFIX/bin/oh-my-posh" print transient --config $POSH_THEME --shell fish --error $omp_status_cache --execution-time $omp_duration --stack-count $omp_stack_count --shell-version $FISH_VERSION
32c32
<     '/opt/homebrew/bin/oh-my-posh' print primary --config $POSH_THEME --shell fish --error $omp_status_cache --execution-time $omp_duration --stack-count $omp_stack_count --shell-version $FISH_VERSION
---
>     PREFIX=(brew --prefix) "$PREFIX/bin/oh-my-posh" print primary --config $POSH_THEME --shell fish --error $omp_status_cache --execution-time $omp_duration --stack-count $omp_stack_count --shell-version $FISH_VERSION
42c42
<       set omp_tooltip_prompt ('/opt/homebrew/bin/oh-my-posh' print tooltip --config $POSH_THEME --shell fish --error $omp_status_cache --shell-version $FISH_VERSION --command $omp_tooltip_command)
---
>       set omp_tooltip_prompt (PREFIX=(brew --prefix) "$PREFIX/bin/oh-my-posh" print tooltip --config $POSH_THEME --shell fish --error $omp_status_cache --shell-version $FISH_VERSION --command $omp_tooltip_command)
49c49
<     '/opt/homebrew/bin/oh-my-posh' print right --config $POSH_THEME --shell fish --error $omp_status_cache --execution-time $omp_duration --stack-count $omp_stack_count --shell-version $FISH_VERSION
---
>     PREFIX=(brew --prefix) "$PREFIX/bin/oh-my-posh" print right --config $POSH_THEME --shell fish --error $omp_status_cache --execution-time $omp_duration --stack-count $omp_stack_count --shell-version $FISH_VERSION

obviously recalculating PREFIX every time is silly, but it was a quick hack that i'm using for now until, hopefully, omp can start generating things without the hardcoding.

masukomi commented 2 years ago

forgot to address this comment

The only line in your config has to be oh-my-posh init fish | source and the path to oh-my-posh is NOT hardcoded, it comes from the actual executable's location on your system. So for system A that line can output a completely different path to oh-my-posh than B as it's generated on shell start based on the oh-my-posh executable running the init functionality.

as you can see in the diff i posted above it's very much hardcoded in the generated theme as '/opt/homebrew/bin/oh-my-posh' and not determined at shell start.

JanDeDobbeleer commented 2 years ago

@masukomi all you need to do is change this line oh-my-posh init fish | source to this oh-my-posh init fish --strict | source.

That said, the generated script should not be synced. Because yes, it's always device specific.

github-actions[bot] commented 10 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.