lib/utils: move and refactor "safe_append_prompt_command => _omb_util_append_prompt_command"

This commit is contained in:
Koichi Murase
2021-12-28 09:19:44 +09:00
parent 50d024358a
commit a3b8e5fdbf
61 changed files with 84 additions and 86 deletions

View File

@@ -239,3 +239,27 @@ pushover () {
-F "message=${MESSAGE}" \
"${PUSHOVERURL}" > /dev/null 2>&1
}
_omb_util_add_prompt_command() {
# Set OS dependent exact match regular expression
local prompt_re
if [[ $OSTYPE == darwin* ]]; then
# macOS
prompt_re='[[:<:]]'$1'[[:>:]]'
else
# Linux, FreeBSD, etc.
prompt_re='\<'$1'\>'
fi
# See if we need to use the overriden version
if _omb_util_function_exists append_prompt_command_override; then
append_prompt_command_override "$1"
return
fi
if [[ $PROMPT_COMMAND =~ $prompt_re ]]; then
return
else
PROMPT_COMMAND="$1${PROMPT_COMMAND:+;$PROMPT_COMMAND}"
fi
}

View File

@@ -14,4 +14,4 @@ function prompt_command(){
export PS1="\n${bold_black}[${blue}\@${bold_black}]-${bold_black}[${green}\u${yellow}@${green}\h${bold_black}]-${bold_black}[${purple}\w${bold_black}]-$(scm_prompt_info)\n${reset_color}\$ "
}
safe_append_prompt_command prompt_command
_omb_util_add_prompt_command prompt_command

View File

@@ -39,4 +39,4 @@ function prompt_command() {
THEME_CLOCK_COLOR=${THEME_CLOCK_COLOR:-"${white}"}
safe_append_prompt_command prompt_command
_omb_util_add_prompt_command prompt_command

View File

@@ -19,4 +19,4 @@ function prompt_command() {
PS1="\n${cyan}\h: ${reset_color} ${yellow}\w ${green}$(scm_prompt_info)\n${reset_color}"
}
safe_append_prompt_command prompt_command
_omb_util_add_prompt_command prompt_command

View File

@@ -584,30 +584,4 @@ function aws_profile {
# Returns true if $1 is a shell function.
_omb_util_defun_deprecate 20000 fn_exists _omb_util_function_exists
function safe_append_prompt_command {
local prompt_re
# Set OS dependent exact match regular expression
if [[ ${OSTYPE} == darwin* ]]; then
# macOS
prompt_re="[[:<:]]${1}[[:>:]]"
else
# Linux, FreeBSD, etc.
prompt_re="\<${1}\>"
fi
# See if we need to use the overriden version
if _omb_util_function_exists append_prompt_command_override; then
append_prompt_command_override "$1"
return
fi
if [[ ${PROMPT_COMMAND} =~ ${prompt_re} ]]; then
return
elif [[ -z ${PROMPT_COMMAND} ]]; then
PROMPT_COMMAND="${1}"
else
PROMPT_COMMAND="${1};${PROMPT_COMMAND}"
fi
}
_omb_util_defun_deprecate 20000 safe_append_prompt_command _omb_util_add_prompt_command

View File

@@ -98,4 +98,4 @@ SCM_GIT_CHAR="${green}±${light_grey}"
SCM_SVN_CHAR="${bold_cyan}${light_grey}"
SCM_HG_CHAR="${bold_red}${light_grey}"
safe_append_prompt_command prompt_command
_omb_util_add_prompt_command prompt_command

View File

@@ -16,4 +16,4 @@ function prompt_command() {
PS1="\n${yellow}$(python_version_prompt) ${purple}\h ${reset_color}in ${green}\w\n${bold_cyan}$(scm_char)${green}$(scm_prompt_info) ${green}${reset_color} "
}
safe_append_prompt_command prompt_command
_omb_util_add_prompt_command prompt_command

View File

@@ -31,4 +31,4 @@ THEME_CLOCK_CHAR_COLOR=${THEME_CLOCK_CHAR_COLOR:-"$red"}
THEME_CLOCK_COLOR=${THEME_CLOCK_COLOR:-"$bold_cyan"}
THEME_CLOCK_FORMAT=${THEME_CLOCK_FORMAT:-"%Y-%m-%d %H:%M:%S"}
safe_append_prompt_command prompt_command
_omb_util_add_prompt_command prompt_command

View File

@@ -292,4 +292,4 @@ _brainy_prompt() {
PS2="$(__brainy_ps2)"
}
safe_append_prompt_command _brainy_prompt
_omb_util_add_prompt_command _brainy_prompt

View File

@@ -33,4 +33,4 @@ prompt() {
THEME_CLOCK_COLOR=${THEME_CLOCK_COLOR:-"$blue$background_white"}
THEME_CLOCK_FORMAT=${THEME_CLOCK_FORMAT:-" %H:%M:%S"}
safe_append_prompt_command prompt
_omb_util_add_prompt_command prompt

View File

@@ -7,4 +7,4 @@ function prompt_command() {
THEME_CLOCK_COLOR=${THEME_CLOCK_COLOR:-"$blue"}
THEME_CLOCK_FORMAT=${THEME_CLOCK_FORMAT:-"%I:%M:%S"}
safe_append_prompt_command prompt_command
_omb_util_add_prompt_command prompt_command

View File

@@ -17,4 +17,4 @@ function prompt_command() {
RPROMPT='[\t]'
}
safe_append_prompt_command prompt_command
_omb_util_add_prompt_command prompt_command

View File

@@ -27,4 +27,4 @@ function prompt() {
PS1="\n${user_host}${prompt_symbol}${ruby} ${git_branch} ${return_status}\n${prompt_char}"
}
safe_append_prompt_command prompt
_omb_util_add_prompt_command prompt

View File

@@ -68,4 +68,4 @@ function prompt_command() {
}
# Runs prompt (this bypasses oh-my-bash $PROMPT setting)
safe_append_prompt_command prompt_command
_omb_util_add_prompt_command prompt_command

View File

@@ -126,4 +126,4 @@ ${D_INTERMEDIATE_COLOR}$ ${D_DEFAULT_COLOR}"
}
# Runs prompt (this bypasses oh-my-bash $PROMPT setting)
safe_append_prompt_command prompt
_omb_util_add_prompt_command prompt

View File

@@ -51,7 +51,7 @@ $(doubletime_scm_prompt)$reset_color $ "
PS4='+ '
}
safe_append_prompt_command prompt_setter
_omb_util_add_prompt_command prompt_setter
git_prompt_status() {
local git_status_output

View File

@@ -15,4 +15,4 @@ $(doubletime_scm_prompt)$reset_color $ "
PS4='+ '
}
safe_append_prompt_command prompt_setter
_omb_util_add_prompt_command prompt_setter

View File

@@ -15,4 +15,4 @@ $(doubletime_scm_prompt)$reset_color $ "
PS4='+ '
}
safe_append_prompt_command prompt_setter
_omb_util_add_prompt_command prompt_setter

View File

@@ -95,4 +95,4 @@ dulcie_prompt() {
PS1="${PS1}${DULCIE_PROMPTCHAR} "
}
safe_append_prompt_command dulcie_prompt
_omb_util_add_prompt_command dulcie_prompt

View File

@@ -21,4 +21,4 @@ prompt() {
PS1="${yellow}# ${reset_color}$(last_two_dirs)$(scm_prompt_info)${reset_color}$(venv)${reset_color} ${cyan}\n> ${reset_color}"
}
safe_append_prompt_command prompt
_omb_util_add_prompt_command prompt

View File

@@ -39,4 +39,4 @@ function prompt_command() {
THEME_CLOCK_FORMAT=${THEME_CLOCK_FORMAT:-"%H "}
safe_append_prompt_command prompt_command
_omb_util_add_prompt_command prompt_command

View File

@@ -13,4 +13,4 @@ function prompt_command() {
PS1="\n${yellow}$(_omb_prompt_print_ruby_env) ${purple}\h ${reset_color}in ${green}\w\n${bold_cyan}$(scm_char)${green}$(scm_prompt_info) ${green}${reset_color} "
}
safe_append_prompt_command prompt_command
_omb_util_add_prompt_command prompt_command

View File

@@ -58,4 +58,4 @@ function prompt_command() {
PS1="$(clock_prompt)$python_venv${hostname} ${bold_cyan}\W $(scm_prompt_char_info)${ret_status}${normal}"
}
safe_append_prompt_command prompt_command
_omb_util_add_prompt_command prompt_command

View File

@@ -38,4 +38,4 @@ pure_prompt() {
esac
}
safe_append_prompt_command pure_prompt
_omb_util_add_prompt_command pure_prompt

View File

@@ -52,4 +52,4 @@ function prompt_command() {
PS1="$python_venv${hostname} ${bold_cyan}\w $(scm_prompt_char_info)${ret_status}${normal}"
}
safe_append_prompt_command prompt_command
_omb_util_add_prompt_command prompt_command

View File

@@ -194,4 +194,4 @@ function prompt() {
PS4='+ '
}
safe_append_prompt_command prompt
_omb_util_add_prompt_command prompt

View File

@@ -48,4 +48,4 @@ function prompt_command() {
PS1="${new_PS1}${green}${wrap_char}${reset_color} "
}
safe_append_prompt_command prompt_command
_omb_util_add_prompt_command prompt_command

View File

@@ -35,4 +35,4 @@ SCM_THEME_PROMPT_PREFIX="${bold_cyan}("
SCM_THEME_PROMPT_SUFFIX="${bold_cyan})${reset_color}"
safe_append_prompt_command prompt_command
_omb_util_add_prompt_command prompt_command

View File

@@ -30,4 +30,4 @@ function prompt_command() {
THEME_CLOCK_COLOR=${THEME_CLOCK_COLOR:-"$yellow"}
THEME_CLOCK_FORMAT=${THEME_TIME_FORMAT:-"%I:%M:%S "}
safe_append_prompt_command prompt_command
_omb_util_add_prompt_command prompt_command

View File

@@ -127,4 +127,4 @@ PS2="└─▪ "
safe_append_prompt_command prompt
_omb_util_add_prompt_command prompt

View File

@@ -31,4 +31,4 @@ function prompt() {
PS1="\n${n_commands} ${user_host} ${prompt_symbol} ${ruby} ${open}${current_path}${git_branch}${close}${return_status}\n${prompt_char}"
}
safe_append_prompt_command prompt
_omb_util_add_prompt_command prompt

View File

@@ -9,4 +9,4 @@ prompt() {
PS1="$(scm_prompt_info)${reset_color} ${cyan}\W${reset_color} "
}
safe_append_prompt_command prompt
_omb_util_add_prompt_command prompt

View File

@@ -53,4 +53,4 @@ PS2="└─▪ "
safe_append_prompt_command prompt
_omb_util_add_prompt_command prompt

View File

@@ -53,4 +53,4 @@ PS2="└─▪ "
safe_append_prompt_command prompt
_omb_util_add_prompt_command prompt

View File

@@ -25,4 +25,4 @@ SCM_THEME_PROMPT_PREFIX="${green}("
SCM_THEME_PROMPT_SUFFIX="${green})${reset_color}"
safe_append_prompt_command prompt_command
_omb_util_add_prompt_command prompt_command

View File

@@ -9,7 +9,7 @@ function prompt_command() {
PS1="${bold_blue}[$(hostname)]${normal} \w${normal} ${bold_white}[$(git_prompt_info)]${normal}» "
}
safe_append_prompt_command prompt_command
_omb_util_add_prompt_command prompt_command
## git-theme
# feel free to change git chars.

View File

@@ -37,7 +37,7 @@ prompt_setter() {
PS4='+ '
}
safe_append_prompt_command prompt_setter
_omb_util_add_prompt_command prompt_setter
SCM_THEME_PROMPT_DIRTY=" ${bold_red}${normal}"
SCM_THEME_PROMPT_CLEAN=" ${bold_green}${normal}"

View File

@@ -104,7 +104,7 @@ prompt_setter() {
PS4='+ '
}
safe_append_prompt_command prompt_setter
_omb_util_add_prompt_command prompt_setter
SCM_THEME_PROMPT_DIRTY=" ${bold_red}${normal}"
SCM_THEME_PROMPT_CLEAN=" ${bold_green}${normal}"

View File

@@ -10,7 +10,7 @@ prompt_setter() {
PS4='+ '
}
safe_append_prompt_command prompt_setter
_omb_util_add_prompt_command prompt_setter
SCM_THEME_PROMPT_DIRTY=" ✗"
SCM_THEME_PROMPT_CLEAN=" ✓"

View File

@@ -50,4 +50,4 @@ IN_VIM_THEME_PROMPT_TEXT="vim"
POWERLINE_LEFT_PROMPT=${POWERLINE_LEFT_PROMPT:="scm python_venv ruby cwd"}
POWERLINE_RIGHT_PROMPT=${POWERLINE_RIGHT_PROMPT:="in_vim clock battery user_info"}
safe_append_prompt_command __powerline_prompt_command
_omb_util_add_prompt_command __powerline_prompt_command

View File

@@ -49,4 +49,4 @@ IN_VIM_THEME_PROMPT_TEXT="vim"
POWERLINE_PROMPT=${POWERLINE_PROMPT:="user_info scm python_venv ruby cwd"}
safe_append_prompt_command __powerline_prompt_command
_omb_util_add_prompt_command __powerline_prompt_command

View File

@@ -45,4 +45,4 @@ IN_VIM_THEME_PROMPT_TEXT="vim"
POWERLINE_PROMPT=${POWERLINE_PROMPT:="user_info scm python_venv ruby cwd"}
safe_append_prompt_command __powerline_prompt_command
_omb_util_add_prompt_command __powerline_prompt_command

View File

@@ -48,4 +48,4 @@ IN_VIM_THEME_PROMPT_TEXT="vim"
POWERLINE_PROMPT=${POWERLINE_PROMPT:="user_info scm python_venv ruby cwd"}
safe_append_prompt_command __powerline_prompt_command
_omb_util_add_prompt_command __powerline_prompt_command

View File

@@ -8,4 +8,4 @@ function prompt_command() {
THEME_CLOCK_COLOR=${THEME_CLOCK_COLOR:-"$blue"}
THEME_CLOCK_FORMAT=${THEME_CLOCK_FORMAT:-"%I:%M:%S"}
safe_append_prompt_command prompt_command
_omb_util_add_prompt_command prompt_command

View File

@@ -19,4 +19,4 @@ function prompt() {
PS1="\h: \W $(scm_prompt_info)${reset_color} $ "
}
safe_append_prompt_command prompt
_omb_util_add_prompt_command prompt

View File

@@ -40,4 +40,4 @@ pure_prompt() {
esac
}
safe_append_prompt_command pure_prompt
_omb_util_add_prompt_command pure_prompt

View File

@@ -18,4 +18,4 @@ function prompt_command() {
PS1="\n${blue}\w $(scm_prompt_info)\n${ret_status} "
}
safe_append_prompt_command prompt_command
_omb_util_add_prompt_command prompt_command

View File

@@ -18,7 +18,7 @@ prompt_setter() {
PS4='+ '
}
safe_append_prompt_command prompt_setter
_omb_util_add_prompt_command prompt_setter
SCM_NONE_CHAR='·'
SCM_THEME_PROMPT_DIRTY=" ${red}"

View File

@@ -211,4 +211,4 @@ ${D_INTERMEDIATE_COLOR}$ ${D_DEFAULT_COLOR}"
}
# Runs prompt (this bypasses oh-my-bash $PROMPT setting)
safe_append_prompt_command prompt
_omb_util_add_prompt_command prompt

View File

@@ -97,4 +97,4 @@ PS2="└─$(my_prompt_char)"
safe_append_prompt_command prompt
_omb_util_add_prompt_command prompt

View File

@@ -14,4 +14,4 @@ function prompt_command() {
fi
}
safe_append_prompt_command prompt_command
_omb_util_add_prompt_command prompt_command

View File

@@ -43,4 +43,4 @@ function prompt_command() {
PS1="\[${BOLD}${MAGENTA}\]\u \[$WHITE\]at \[$ORANGE\]\h \[$WHITE\]in \[$GREEN\]\w\[$WHITE\]\$([[ -n \$(git branch 2> /dev/null) ]] && echo \" on \")\[$PURPLE\]\$(parse_git_branch)\[$WHITE\]\n\$ \[$RESET\]"
}
safe_append_prompt_command prompt_command
_omb_util_add_prompt_command prompt_command

View File

@@ -22,4 +22,4 @@ SCM_THEME_PROMPT_CLEAN=" ✓"
SCM_THEME_PROMPT_PREFIX="("
SCM_THEME_PROMPT_SUFFIX=")"
safe_append_prompt_command prompt_command
_omb_util_add_prompt_command prompt_command

View File

@@ -17,4 +17,4 @@ function prompt_command {
PS1="$blue\W/$bold_blue$(_omb_theme_sirup_rubygem)$bold_green$(__git_ps1 " (%s)") ${normal}$ "
}
safe_append_prompt_command prompt_command
_omb_util_add_prompt_command prompt_command

View File

@@ -83,4 +83,4 @@ PS2="> "
safe_append_prompt_command prompt
_omb_util_add_prompt_command prompt

View File

@@ -21,4 +21,4 @@ function prompt_command() {
PROMPT='${green}\u${normal}@${green}\h${normal}:${blue}\w${normal}${red}$(prompt_char)$(git_prompt_info)${normal}\$ '
}
safe_append_prompt_command prompt_command
_omb_util_add_prompt_command prompt_command

View File

@@ -49,7 +49,7 @@ PS2="$LIGHT_BLUE-$YELLOW-$YELLOW-$NO_COLOUR "
}
safe_append_prompt_command prompt_setter
_omb_util_add_prompt_command prompt_setter
THEME_SHOW_CLOCK=${THEME_SHOW_CLOCK:-"true"}
THEME_CLOCK_COLOR=${THEME_CLOCK_COLOR:-"\[\033[1;33m\]"}

View File

@@ -10,4 +10,4 @@ function prompt_command() {
PS1="${yellow}\u${normal}${cyan}@\h${normal}${purple} ${normal}${green}\w${normal}$(scm_prompt_info)> "
}
safe_append_prompt_command prompt_command
_omb_util_add_prompt_command prompt_command

View File

@@ -17,4 +17,4 @@ function prompt_command() {
PS1="\n${green}$(_omb_prompt_print_python_venv)${red}$(_omb_prompt_print_ruby_env) ${reset_color}\h ${orange}in ${reset_color}\w\n${yellow}$(scm_char)$(scm_prompt_info) ${yellow}${white} "
}
safe_append_prompt_command prompt_command
_omb_util_add_prompt_command prompt_command

View File

@@ -21,4 +21,4 @@ function prompt_command() {
PS1="${no_color}\u:$(hostname)${normal}:${bold_yellow}\W/${normal} $(git_prompt_info)${reset_color}$ "
}
safe_append_prompt_command prompt_command
_omb_util_add_prompt_command prompt_command

View File

@@ -94,4 +94,4 @@ PS2="└─▪ "
safe_append_prompt_command prompt
_omb_util_add_prompt_command prompt