oh-my-posh/src/shell/scripts/omp.bash

63 lines
1.7 KiB
Bash
Raw Normal View History

export POSH_THEME=::CONFIG::
export POWERLINE_COMMAND="oh-my-posh"
export POSH_PID=$$
2021-05-20 10:24:58 -07:00
export CONDA_PROMPT_MODIFIER=false
2022-08-09 01:16:33 -07:00
omp_start_time=""
2022-02-20 04:56:28 -08:00
# start timer on command start
2022-08-09 01:16:33 -07:00
PS0='${omp_start_time:0:$((omp_start_time="$(_omp_start_timer)",0))}'
2022-02-20 04:56:28 -08:00
# set secondary prompt
PS2="$(::OMP:: print secondary --config="$POSH_THEME" --shell=bash --shell-version="$BASH_VERSION")"
2021-03-02 11:37:31 -08:00
function _set_posh_cursor_position() {
# not supported in Midnight Commander
# see https://github.com/JanDeDobbeleer/oh-my-posh/issues/3415
if [[ "::CURSOR::" != "true" ]] || [[ -v MC_SID ]]; then
return
fi
local oldstty=$(stty -g)
stty raw -echo min 0
local COL
local ROW
IFS=';' read -sdR -p $'\E[6n' ROW COL
stty $oldstty
export POSH_CURSOR_LINE=${ROW#*[}
export POSH_CURSOR_COLUMN=${COL}
}
function _omp_start_timer() {
2022-08-09 01:16:33 -07:00
::OMP:: get millis
}
# template function for context loading
function set_poshcontext() {
return
}
function _omp_hook() {
local ret=$?
local omp_stack_count=$((${#DIRSTACK[@]} - 1))
local omp_elapsed=-1
2022-08-09 01:16:33 -07:00
if [[ -n "$omp_start_time" ]]; then
2022-09-22 23:39:27 -07:00
local omp_now=$(::OMP:: get millis --shell=bash)
omp_elapsed=$((omp_now-omp_start_time))
2022-08-09 01:16:33 -07:00
omp_start_time=""
2021-03-02 11:37:31 -08:00
fi
set_poshcontext
_set_posh_cursor_position
PS1="$(::OMP:: print primary --config="$POSH_THEME" --shell=bash --shell-version="$BASH_VERSION" --error="$ret" --execution-time="$omp_elapsed" --stack-count="$omp_stack_count" | tr -d '\0')"
return $ret
2020-12-23 04:12:10 -08:00
}
if [ "$TERM" != "linux" ] && [ -x "$(command -v ::OMP::)" ] && ! [[ "$PROMPT_COMMAND" =~ "_omp_hook" ]]; then
PROMPT_COMMAND="_omp_hook; $PROMPT_COMMAND"
2020-12-23 04:12:10 -08:00
fi
2023-03-03 11:21:35 -08:00
if [ "::UPGRADE::" == "true" ]; then
echo "::UPGRADENOTICE::"
fi