2022-08-07 19:35:53 -07:00
|
|
|
export POSH_THEME=::CONFIG::
|
2023-03-26 08:26:39 -07:00
|
|
|
export POSH_SHELL_VERSION=$BASH_VERSION
|
2021-05-16 10:13:15 -07:00
|
|
|
export POWERLINE_COMMAND="oh-my-posh"
|
2022-11-19 13:35:13 -08:00
|
|
|
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=""
|
2021-06-12 12:39:52 -07:00
|
|
|
|
2022-02-20 04:56:28 -08:00
|
|
|
# start timer on command start
|
2023-05-17 14:27:21 -07:00
|
|
|
PS0='${omp_start_time:0:$((omp_start_time="$(_omp_start_timer)",0))}$(_omp_ftcs_command_start)'
|
2022-02-20 04:56:28 -08:00
|
|
|
# set secondary prompt
|
2022-04-20 10:16:02 -07:00
|
|
|
PS2="$(::OMP:: print secondary --config="$POSH_THEME" --shell=bash --shell-version="$BASH_VERSION")"
|
2021-03-02 11:37:31 -08:00
|
|
|
|
2023-02-02 05:02:46 -08:00
|
|
|
function _set_posh_cursor_position() {
|
2023-07-23 00:29:54 -07:00
|
|
|
# not supported in Midnight Commander
|
2023-02-02 05:02:46 -08:00
|
|
|
# see https://github.com/JanDeDobbeleer/oh-my-posh/issues/3415
|
2023-02-04 02:17:10 -08:00
|
|
|
if [[ "::CURSOR::" != "true" ]] || [[ -v MC_SID ]]; then
|
2023-02-02 05:02:46 -08:00
|
|
|
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}
|
|
|
|
}
|
|
|
|
|
2022-08-07 19:35:53 -07:00
|
|
|
function _omp_start_timer() {
|
2022-08-09 01:16:33 -07:00
|
|
|
::OMP:: get millis
|
2022-08-07 19:35:53 -07:00
|
|
|
}
|
|
|
|
|
2023-05-17 14:27:21 -07:00
|
|
|
function _omp_ftcs_command_start() {
|
2024-06-20 02:57:17 -07:00
|
|
|
if [[ "::FTCS_MARKS::" == "true" ]]; then
|
2023-05-17 14:27:21 -07:00
|
|
|
printf "\e]133;C\a"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2022-09-23 11:44:53 -07:00
|
|
|
# template function for context loading
|
|
|
|
function set_poshcontext() {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-03-18 10:47:22 -07:00
|
|
|
function _omp_hook() {
|
2023-07-23 00:29:54 -07:00
|
|
|
local ret=$? pipeStatus=(${PIPESTATUS[@]})
|
2024-01-09 23:00:48 -08:00
|
|
|
if [[ "${#BP_PIPESTATUS[@]}" -ge "${#pipeStatus[@]}" ]]; then
|
2023-07-23 00:29:54 -07:00
|
|
|
pipeStatus=(${BP_PIPESTATUS[@]})
|
|
|
|
fi
|
|
|
|
|
2022-08-07 19:35:53 -07:00
|
|
|
local omp_stack_count=$((${#DIRSTACK[@]} - 1))
|
|
|
|
local omp_elapsed=-1
|
2023-05-17 14:27:21 -07:00
|
|
|
local no_exit_code="true"
|
2023-07-23 00:29:54 -07:00
|
|
|
|
2024-06-20 02:57:17 -07:00
|
|
|
if [[ "$omp_start_time" ]]; then
|
2022-09-22 23:39:27 -07:00
|
|
|
local omp_now=$(::OMP:: get millis --shell=bash)
|
2024-06-20 02:57:17 -07:00
|
|
|
omp_elapsed=$((omp_now - omp_start_time))
|
2022-08-09 01:16:33 -07:00
|
|
|
omp_start_time=""
|
2023-05-17 14:27:21 -07:00
|
|
|
no_exit_code="false"
|
2021-03-02 11:37:31 -08:00
|
|
|
fi
|
2024-06-20 02:57:17 -07:00
|
|
|
if [[ "${pipeStatus[-1]}" != "$ret" ]]; then
|
|
|
|
pipeStatus=("$ret")
|
|
|
|
fi
|
2023-07-23 00:29:54 -07:00
|
|
|
|
2022-09-23 11:44:53 -07:00
|
|
|
set_poshcontext
|
2023-02-02 05:02:46 -08:00
|
|
|
_set_posh_cursor_position
|
2023-07-23 00:29:54 -07:00
|
|
|
|
2024-06-17 05:22:50 -07:00
|
|
|
PS1="$(::OMP:: print primary --config="$POSH_THEME" --shell=bash --shell-version="$BASH_VERSION" --status="$ret" --pipestatus="${pipeStatus[*]}" --execution-time="$omp_elapsed" --stack-count="$omp_stack_count" --no-status="$no_exit_code" --terminal-width="${COLUMNS-0}" | tr -d '\0')"
|
2021-03-18 10:47:22 -07:00
|
|
|
return $ret
|
2020-12-23 04:12:10 -08:00
|
|
|
}
|
|
|
|
|
2024-06-20 02:57:17 -07:00
|
|
|
if [[ "$TERM" != "linux" ]] && [[ -x "$(command -v ::OMP::)" ]] && ! [[ "$PROMPT_COMMAND" =~ "_omp_hook" ]]; then
|
2021-03-18 10:47:22 -07:00
|
|
|
PROMPT_COMMAND="_omp_hook; $PROMPT_COMMAND"
|
2020-12-23 04:12:10 -08:00
|
|
|
fi
|
2023-03-03 11:21:35 -08:00
|
|
|
|
2024-06-20 02:57:17 -07:00
|
|
|
if [[ "::UPGRADE::" == "true" ]]; then
|
2023-03-03 11:21:35 -08:00
|
|
|
echo "::UPGRADENOTICE::"
|
|
|
|
fi
|
2024-06-03 02:26:05 -07:00
|
|
|
|
|
|
|
if [[ "::AUTOUPGRADE::" == "true" ]]; then
|
|
|
|
::OMP:: upgrade
|
|
|
|
fi
|