Remove command_duration specific code, this will be a plugin

pull/1683/head
BarbUk 2020-11-07 07:34:43 +01:00
parent 02eff64749
commit 4fa93836e1
No known key found for this signature in database
GPG Key ID: DB301C759539E9FE
1 changed files with 5 additions and 49 deletions

View File

@ -11,16 +11,12 @@ SCM_HG_CHAR=${BARBUK_HG_CHAR:='☿ '}
SCM_SVN_CHAR=${BARBUK_SVN_CHAR:='⑆ '}
EXIT_CODE_ICON=${BARBUK_EXIT_CODE_ICON:=' '}
PYTHON_VENV_CHAR=${BARBUK_PYTHON_VENV_CHAR:=' '}
COMMAND_DURATION_ICON=${BARBUK_COMMAND_DURATION_ICON:='  '}
COMMAND_DURATION_COLOR="$bold_blue"
# Ssh user and hostname display
SSH_INFO=${BARBUK_SSH_INFO:=true}
HOST_INFO=${BARBUK_HOST_INFO:=long}
# Command duration
COMMAND_DURATION=${BARBUK_COMMAND_DURATION:=true}
COMMAND_DURATION_FILE="/tmp/bashit_theme_execution_$$"
# Bash-it default glyphs customization
SCM_NONE_CHAR=
SCM_THEME_PROMPT_DIRTY=" ${bold_red}"
@ -71,50 +67,10 @@ function _exit-code {
fi
}
function _command_duration {
local command_duration command_start current_time="$1"
if [ "$COMMAND_DURATION" != true ]; then
return
fi
if [[ -f "$COMMAND_DURATION_FILE" ]]; then
command_start=$(< "$COMMAND_DURATION_FILE")
command_duration=$(( current_time - command_start ))
command rm "$COMMAND_DURATION_FILE"
else
command_duration=0
fi
if [[ "$command_duration" -gt 0 ]]; then
timer_m=$(( command_duration / 60 ))
timer_s=$(( command_duration % 60 ))
fi
if [[ "$timer_m" -gt 0 ]]; then
echo "${bold_blue}$COMMAND_DURATION_ICON${normal}${timer_m}m ${timer_s}s"
elif [[ "$timer_s" -gt 0 ]]; then
echo "${bold_blue}$COMMAND_DURATION_ICON${normal}${timer_s}s"
fi
}
function delete_temp_file() {
if [[ -f "$COMMAND_DURATION_FILE" ]]; then
rm -f "$COMMAND_DURATION_FILE"
fi
}
function _pre_exec {
date +%s > "$COMMAND_DURATION_FILE"
}
PS0="\[\$(_pre_exec)\]"
function _prompt {
local exit_code="$?" wrap_char=' ' dir_color=$green ssh_info='' python_venv='' host current_time
current_time=$(date +%s)
local exit_code="$?" wrap_char=' ' dir_color=$green ssh_info='' python_venv='' host command_duration
trap delete_temp_file EXIT HUP INT TRAP TERM
command_duration=$(_command_duration)
_exit-code exit_code
_git-uptream-remote-logo
@ -143,7 +99,7 @@ function _prompt {
python_venv="$PYTHON_VENV_CHAR$(basename "${VIRTUAL_ENV}") "
fi
PS1="\\n${ssh_info} ${purple}$(scm_char)${python_venv}${dir_color}\\w${normal}$(scm_prompt_info)$(_command_duration "$current_time")${exit_code}"
PS1="\\n${ssh_info} ${purple}$(scm_char)${python_venv}${dir_color}\\w${normal}$(scm_prompt_info)${command_duration}${exit_code}"
[[ ${#PS1} -gt $((COLUMNS*3)) ]] && wrap_char="\\n"
PS1="${PS1}${wrap_char}${normal} "