2022-08-07 19:35:53 -07:00
|
|
|
export POSH_THEME=::CONFIG::
|
2021-05-16 10:13:15 -07:00
|
|
|
export POWERLINE_COMMAND="oh-my-posh"
|
2021-05-20 10:24:58 -07:00
|
|
|
export CONDA_PROMPT_MODIFIER=false
|
2020-12-23 04:12:10 -08:00
|
|
|
|
2021-03-02 11:37:31 -08:00
|
|
|
TIMER_START="/tmp/${USER}.start.$$"
|
|
|
|
|
2021-06-12 12:39:52 -07:00
|
|
|
# some environments don't have the filesystem we'd expect
|
|
|
|
if [[ ! -d "/tmp" ]]; then
|
|
|
|
TIMER_START="${HOME}/.${USER}.start.$$"
|
|
|
|
fi
|
|
|
|
|
2022-02-20 04:56:28 -08:00
|
|
|
# start timer on command start
|
2022-08-07 19:35:53 -07:00
|
|
|
PS0='$(_omp_start_timer)'
|
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
|
|
|
|
2022-08-07 19:35:53 -07:00
|
|
|
function _omp_start_timer() {
|
|
|
|
::OMP:: get millis > "$TIMER_START"
|
|
|
|
}
|
|
|
|
|
2021-03-18 10:47:22 -07:00
|
|
|
function _omp_hook() {
|
|
|
|
local ret=$?
|
2022-08-07 19:35:53 -07:00
|
|
|
local omp_stack_count=$((${#DIRSTACK[@]} - 1))
|
|
|
|
local omp_elapsed=-1
|
2021-06-12 12:39:52 -07:00
|
|
|
if [[ -f "$TIMER_START" ]]; then
|
2022-03-19 11:32:40 -07:00
|
|
|
omp_now=$(::OMP:: get millis)
|
2021-03-02 11:37:31 -08:00
|
|
|
omp_start_time=$(cat "$TIMER_START")
|
2021-03-18 10:47:22 -07:00
|
|
|
omp_elapsed=$((omp_now-omp_start_time))
|
2021-04-10 00:07:04 -07:00
|
|
|
rm -f "$TIMER_START"
|
2021-03-02 11:37:31 -08:00
|
|
|
fi
|
2022-04-20 10:16:02 -07:00
|
|
|
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')"
|
2021-03-18 10:47:22 -07:00
|
|
|
|
|
|
|
return $ret
|
2020-12-23 04:12:10 -08:00
|
|
|
}
|
|
|
|
|
2021-03-18 10:47:22 -07: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
|
2021-03-02 11:37:31 -08:00
|
|
|
|
2021-03-18 10:47:22 -07:00
|
|
|
function _omp_runonexit() {
|
2021-04-10 00:07:04 -07:00
|
|
|
[[ -f $TIMER_START ]] && rm -f "$TIMER_START"
|
2021-03-02 11:37:31 -08:00
|
|
|
}
|
|
|
|
|
2021-03-18 10:47:22 -07:00
|
|
|
trap _omp_runonexit EXIT
|