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-25 05:18:28 -07:00
|
|
|
export OSTYPE=$OSTYPE
|
2024-07-07 01:57:03 -07:00
|
|
|
|
2024-08-23 21:18:20 -07:00
|
|
|
if [[ $OSTYPE =~ ^(msys|cygwin) ]]; then
|
|
|
|
export POSH_PID=$(command cat /proc/$$/winpid)
|
|
|
|
fi
|
|
|
|
|
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)'
|
2024-08-23 21:17:04 -07:00
|
|
|
|
2022-02-20 04:56:28 -08:00
|
|
|
# set secondary prompt
|
2024-08-23 21:17:04 -07:00
|
|
|
_omp_secondary_prompt=$("$_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
|
2024-08-23 21:17:14 -07:00
|
|
|
IFS=';' read -rsdR -p $'\E[6n' ROW COL
|
2023-02-02 05:02:46 -08:00
|
|
|
|
2024-07-26 01:28:38 -07:00
|
|
|
stty "$oldstty"
|
2023-02-02 05:02:46 -08:00
|
|
|
|
|
|
|
export POSH_CURSOR_LINE=${ROW#*[}
|
|
|
|
export POSH_CURSOR_COLUMN=${COL}
|
|
|
|
}
|
|
|
|
|
2022-08-07 19:35:53 -07:00
|
|
|
function _omp_start_timer() {
|
2024-07-26 01:28:38 -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-26 01:28:38 -07:00
|
|
|
if [[ $_omp_ftcs_marks == 1 ]]; 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-08-23 21:17:04 -07:00
|
|
|
function _omp_print_primary() {
|
|
|
|
# Avoid unexpected expansions.
|
|
|
|
shopt -u promptvars
|
|
|
|
|
|
|
|
local prompt
|
|
|
|
if shopt -oq posix; then
|
|
|
|
# Disable in POSIX mode.
|
|
|
|
prompt='[NOTICE: Oh My Posh prompt is not supported in POSIX mode]\n\u@\h:\w\$ '
|
|
|
|
else
|
|
|
|
prompt=$("$_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')
|
|
|
|
fi
|
|
|
|
echo "${prompt@P}"
|
|
|
|
|
|
|
|
# Allow command substitution in PS0.
|
|
|
|
shopt -s promptvars
|
|
|
|
}
|
|
|
|
|
|
|
|
function _omp_print_secondary() {
|
|
|
|
# Avoid unexpected expansions.
|
|
|
|
shopt -u promptvars
|
|
|
|
|
|
|
|
if shopt -oq posix; then
|
|
|
|
# Disable in POSIX mode.
|
|
|
|
echo '> '
|
|
|
|
else
|
|
|
|
echo "${_omp_secondary_prompt@P}"
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Allow command substitution in PS0.
|
|
|
|
shopt -s promptvars
|
|
|
|
}
|
|
|
|
|
2021-03-18 10:47:22 -07:00
|
|
|
function _omp_hook() {
|
2024-08-23 21:17:14 -07:00
|
|
|
_omp_status_cache=$? _omp_pipestatus_cache=("${PIPESTATUS[@]}")
|
2024-07-07 01:57:03 -07:00
|
|
|
|
2024-07-26 01:28:38 -07:00
|
|
|
if [[ ${#BP_PIPESTATUS[@]} -ge ${#_omp_pipestatus_cache[@]} ]]; then
|
2024-08-23 21:17:14 -07:00
|
|
|
_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-26 01:28:38 -07:00
|
|
|
if [[ $_omp_start_time ]]; then
|
|
|
|
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-26 01:28:38 -07:00
|
|
|
if [[ ${_omp_pipestatus_cache[-1]} != "$_omp_status_cache" ]]; then
|
2024-07-14 19:59:13 -07:00
|
|
|
_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-08-23 21:17:04 -07:00
|
|
|
PS1='$(_omp_print_primary)'
|
|
|
|
PS2='$(_omp_print_secondary)'
|
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-08-23 21:17:14 -07:00
|
|
|
function _omp_install_hook() {
|
|
|
|
[[ $TERM = linux ]] && return
|
|
|
|
|
|
|
|
local cmd
|
|
|
|
for cmd in "${PROMPT_COMMAND[@]}"; do
|
|
|
|
if [[ $cmd = "_omp_hook" ]]; then
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
PROMPT_COMMAND=(_omp_hook "${PROMPT_COMMAND[@]}")
|
|
|
|
}
|
|
|
|
|
|
|
|
_omp_install_hook
|