Closed masukomi closed 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.
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
brew --prefix
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.
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.
@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.
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?
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 callingbrew --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 callingbrew --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