Closed ianzhang366 closed 3 years ago
@ianzhang366 this goes beyond oh-my-posh's original use-case and design. Theoretically I could make it work, but that's quite a bit of work and I'm not sure if there are many use-cases. I'll leave this up for grabs, if things slow down I'll gladly have a look but it's definitely not a priority for now.
To do:
@ianzhang366 what does oh-my-posh --print-shell
say when you're inside acme?
Hi @JanDeDobbeleer I got the following inside acme:
$ oh-my-posh --print-shell
bash
@ianzhang366 OK, that's not going to help. Do you configure oh-my-posh specifically for ACME or is it your general bash config? I'm looking for the right way to trigger the rendering, and if it needs to be dynamic, I need a way to know we're running inside of ACME.
@JanDeDobbeleer thanks for explaining. I see what you mean, now.
When acme is running, there's a variable winid
created by acme. Based on this, I have logic in my bashrc
, which will watch the winid
and use different prompt options. I have something like the following,
if [ ! "$winid" = "" ]; then
parse_git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/'
}
export PS1='%2~ %# '
prompt_command () {
PS1='>>> $(basename $(dirname "$PWD"))/$(basename "$PWD") $(parse_git_branch) $ '
}
PROMPT_COMMAND=prompt_command
else
eval "$(oh-my-posh --init --shell bash --config ~/.config/ohmyposh/jandedobbeleer.omp.json)"
fi
I guess I can put the render options in the first logic when we have it.
@ianzhang366 thanks, perfect! I wonder why you're not using oh-my-posh for your regular prompt, but that's a different topic 😅
@ianzhang366 out of curiosity what does the linux command tput colors
print from inside an ACME shell?
It's supposed to print the number of colors supported by your shell. Presumably it should be a single digit from inside ACME. From my Windows Terminal it prints "256".
Hi @darkvertex, here's what I got
$ oh-my-posh --print-shell
bash
$ echo $TERM
dumb
$ tput colors
-1
I believe that the ACME will open a session to a shell then send a string between ACME and the shell.
In my case, the ACME is connected to bash, when I initial the bash connection, bash will start and return the prompt string
to ACME...
The return string, from bash to ACME, includes the normal string and colour text, but ACME won't decode/render the colour part at all(this is by ACME design)... That's why the colour string is displayed at the description of this issue.
PS @JanDeDobbeleer This Go module looks useful if you want to make OMP autodetect if the present shell can handle colors: https://github.com/efekarakus/termcolor
Hi @JanDeDobbeleer
I tried out the no-color
branch and got it to work with ACME
Thanks a lot @JanDeDobbeleer
There's a small bug I have to workaround.
Inside the ~/.bashrc
, per the configuration page, I need the following,
eval "$(~/src/oh-my-posh/src/oh-my-posh --plain --init --shell bash --config ~/.config/ohmyposh/jandedobbeleer.omp.json)"
Note that I have the --plain
flag, however, the --plain
flag is missing from the eval
output.
export POSH_THEME="$HOME/.config/ohmyposh/jandedobbeleer.omp.json"
export POWERLINE_COMMAND="oh-my-posh"
export CONDA_PROMPT_MODIFIER=false
TIMER_START="/tmp/${USER}.start.$$"
# some environments don't have the filesystem we'd expect
if [[ ! -d "/tmp" ]]; then
TIMER_START="${HOME}/.${USER}.start.$$"
fi
PS0='$($HOME/golang/src/oh-my-posh/src/oh-my-posh --millis > "$TIMER_START")'
function _omp_hook() {
local ret=$?
omp_stack_count=$((${#DIRSTACK[@]} - 1))
omp_elapsed=-1
if [[ -f "$TIMER_START" ]]; then
omp_now=$($HOME/golang/src/oh-my-posh/src/oh-my-posh --millis)
omp_start_time=$(cat "$TIMER_START")
omp_elapsed=$((omp_now-omp_start_time))
rm -f "$TIMER_START"
fi
PS1="$($HOME/golang/src/oh-my-posh/src/oh-my-posh --config="$POSH_THEME" --shell=bash --error="$ret" --execution-time="$omp_elapsed" --stack-count="$omp_stack_count" | tr -d '\0')"
return $ret
}
if [ "$TERM" != "linux" ] && [ -x "$(command -v $HOME/golang/src/oh-my-posh/src/oh-my-posh)" ] && ! [[ "$PROMPT_COMMAND" =~ "_omp_hook" ]]; then
PROMPT_COMMAND="_omp_hook; $PROMPT_COMMAND"
fi
function _omp_runonexit() {
[[ -f $TIMER_START ]] && rm -f "$TIMER_START"
}
trap _omp_runonexit EXIT
function export_poshconfig() {
[ $# -eq 0 ] && { echo "Usage: $0 \"filename\""; return; }
format=$2
if [ -z "$format" ]; then
format="json"
fi
$HOME/golang/src/oh-my-posh/src/oh-my-posh --config="$POSH_THEME" --print-config --config-format="$format" > $1
}
After manually adding the --plain
flag to the above and using it in my .bashrc
directly, I got the result of the above image.
I was trying to find how to fix this in the code, but no luck so far...
@ianzhang366 it won't be a straightforward change. I would in this case (as it's an exotic one), stick to using PS1:
if [ ! "$winid" = "" ]; then
PS1="$(::OMP:: --config="my_theme.omp.json" --shell=bash --plain | tr -d '\0')"
else
eval "$(oh-my-posh --init --shell bash --config ~/.config/ohmyposh/jandedobbeleer.omp.json)"
fi
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 would you like to see changed/added?
Thanks for doing this project, it's very nice!
I'm trying to use
oh-my-posh
with acme editor, which doesn't support color at all... so when I have segments like the following,At acme, it would have something like:
As you can see around the
git
segment, the color can't be rendered by the editor and the plain string is printed out.This is the limit of acme editor, I believe, to work around this, I wonder if
oh-my-posh
has a way to turn off color render completely?