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
|
2024-07-07 01:57:03 -07:00
|
|
|
|
2024-07-24 04:16:03 -07:00
|
|
|
# global variables
|
2024-07-14 19:59:13 -07:00
|
|
|
_omp_start_time=""
|
|
|
|
_omp_stack_count=0
|
|
|
|
_omp_elapsed=-1
|
|
|
|
_omp_no_exit_code="true"
|
|
|
|
_omp_status_cache=0
|
|
|
|
_omp_pipestatus_cache=0
|
2024-07-24 04:16:03 -07:00
|
|
|
_omp_executable=::OMP::
|
|
|
|
|
|
|
|
# switches to enable/disable features
|
|
|
|
_omp_cursor_positioning=0
|
|
|
|
_omp_ftcs_marks=0
|
2021-06-12 12:39:52 -07:00
|
|
|
|
2022-02-20 04:56:28 -08:00
|
|
|
# start timer on command start
|
2024-07-14 19:59:13 -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
|
2024-07-24 21:48:40 -07:00
|
|
|
PS2="$(${_omp_executable} print secondary --shell=bash --shell-version="$BASH_VERSION")"
|
2021-03-02 11:37:31 -08:00
|
|
|
|
2024-07-14 19:59:13 -07:00
|
|
|
function _omp_set_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
|
2024-07-24 04:16:03 -07:00
|
|
|
if [[ $_omp_cursor_positioning == 0 ]] || [[ -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() {
|
2024-07-24 04:16:03 -07:00
|
|
|
$_omp_executable get millis
|
2022-08-07 19:35:53 -07:00
|
|
|
}
|
|
|
|
|
2023-05-17 14:27:21 -07:00
|
|
|
function _omp_ftcs_command_start() {
|
2024-07-24 04:16:03 -07:00
|
|
|
if [[ $_omp_ftcs_marks == 0 ]]; 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
|
|
|
|
}
|
|
|
|
|
2024-07-07 01:57:03 -07:00
|
|
|
# regular prompt
|
2021-03-18 10:47:22 -07:00
|
|
|
function _omp_hook() {
|
2024-07-14 19:59:13 -07:00
|
|
|
_omp_status_cache=$? _omp_pipestatus_cache=(${PIPESTATUS[@]})
|
2024-07-07 01:57:03 -07:00
|
|
|
|
2024-07-14 19:59:13 -07:00
|
|
|
if [[ "${#BP_PIPESTATUS[@]}" -ge "${#_omp_pipestatus_cache[@]}" ]]; then
|
|
|
|
_omp_pipestatus_cache=(${BP_PIPESTATUS[@]})
|
2023-07-23 00:29:54 -07:00
|
|
|
fi
|
|
|
|
|
2024-07-14 19:59:13 -07:00
|
|
|
_omp_stack_count=$((${#DIRSTACK[@]} - 1))
|
2023-07-23 00:29:54 -07:00
|
|
|
|
2024-07-14 19:59:13 -07:00
|
|
|
if [[ "$_omp_start_time" ]]; then
|
2024-07-24 04:16:03 -07:00
|
|
|
local omp_now=$(${_omp_executable} get millis --shell=bash)
|
2024-07-14 19:59:13 -07:00
|
|
|
_omp_elapsed=$((omp_now - _omp_start_time))
|
|
|
|
_omp_start_time=""
|
|
|
|
_omp_no_exit_code="false"
|
2021-03-02 11:37:31 -08:00
|
|
|
fi
|
2024-07-07 01:57:03 -07:00
|
|
|
|
2024-07-14 19:59:13 -07:00
|
|
|
if [[ "${_omp_pipestatus_cache[-1]}" != "$_omp_status_cache" ]]; then
|
|
|
|
_omp_pipestatus_cache=("$_omp_status_cache")
|
2024-06-20 02:57:17 -07:00
|
|
|
fi
|
2023-07-23 00:29:54 -07:00
|
|
|
|
2022-09-23 11:44:53 -07:00
|
|
|
set_poshcontext
|
2024-07-14 19:59:13 -07:00
|
|
|
_omp_set_cursor_position
|
2023-07-23 00:29:54 -07:00
|
|
|
|
2024-07-24 21:48:40 -07:00
|
|
|
PS1="$(${_omp_executable} print primary --shell=bash --shell-version="$BASH_VERSION" --status="$_omp_status_cache" --pipestatus="${_omp_pipestatus_cache[*]}" --execution-time="$_omp_elapsed" --stack-count="$_omp_stack_count" --no-status="$_omp_no_exit_code" --terminal-width="${COLUMNS-0}" | tr -d '\0')"
|
2020-12-23 04:12:10 -08:00
|
|
|
|
2024-07-14 19:59:13 -07:00
|
|
|
return $_omp_status_cache
|
2024-07-07 01:57:03 -07:00
|
|
|
}
|
|
|
|
|
2024-07-24 04:16:03 -07:00
|
|
|
if [[ "$TERM" != "linux" ]] && [[ -x "$(command -v $_omp_executable)" ]] && ! [[ "$PROMPT_COMMAND" =~ "_omp_hook" ]]; then
|
2024-07-21 06:00:33 -07:00
|
|
|
PROMPT_COMMAND="_omp_hook; $PROMPT_COMMAND"
|
2020-12-23 04:12:10 -08:00
|
|
|
fi
|