Merge branch 'next' into execution_time
This commit is contained in:
commit
875dec5dae
6 changed files with 319 additions and 66 deletions
|
@ -537,16 +537,34 @@ prompt_public_ip() {
|
|||
|
||||
# Context: user@hostname (who am I and where am I)
|
||||
# Note that if $DEFAULT_USER is not set, this prompt segment will always print
|
||||
set_default POWERLEVEL9K_ALWAYS_SHOW_CONTEXT false
|
||||
set_default POWERLEVEL9K_ALWAYS_SHOW_USER false
|
||||
set_default POWERLEVEL9K_CONTEXT_HOST_DEPTH "%m"
|
||||
prompt_context() {
|
||||
set_default POWERLEVEL9K_CONTEXT_HOST_DEPTH "%m"
|
||||
if [[ "$USER" != "$DEFAULT_USER" || -n "$SSH_CLIENT" ]]; then
|
||||
if [[ $(print -P "%#") == '#' ]]; then
|
||||
# Shell runs as root
|
||||
"$1_prompt_segment" "$0_ROOT" "$2" "$DEFAULT_COLOR" "yellow" "$USER@$POWERLEVEL9K_CONTEXT_HOST_DEPTH"
|
||||
else
|
||||
"$1_prompt_segment" "$0_DEFAULT" "$2" "$DEFAULT_COLOR" "011" "$USER@$POWERLEVEL9K_CONTEXT_HOST_DEPTH"
|
||||
fi
|
||||
local current_state="DEFAULT"
|
||||
typeset -AH context_states
|
||||
context_states=(
|
||||
"ROOT" "yellow"
|
||||
"DEFAULT" "011"
|
||||
)
|
||||
|
||||
local content=""
|
||||
|
||||
if [[ "$POWERLEVEL9K_ALWAYS_SHOW_CONTEXT" == true ]] || [[ "$USER" != "$DEFAULT_USER" ]] || [[ -n "$SSH_CLIENT" || -n "$SSH_TTY" ]]; then
|
||||
|
||||
if [[ $(print -P "%#") == '#' ]]; then
|
||||
current_state="ROOT"
|
||||
fi
|
||||
|
||||
content="$USER@${POWERLEVEL9K_CONTEXT_HOST_DEPTH}"
|
||||
|
||||
elif [[ "$POWERLEVEL9K_ALWAYS_SHOW_USER" == true ]]; then
|
||||
content="$USER"
|
||||
else
|
||||
return
|
||||
fi
|
||||
|
||||
"$1_prompt_segment" "${0}_${current_state}" "$2" "$DEFAULT_COLOR" "${context_states[$current_state]}" "${content}"
|
||||
}
|
||||
|
||||
# The 'custom` prompt provides a way for users to invoke commands and display
|
||||
|
@ -596,9 +614,8 @@ prompt_command_execution_time() {
|
|||
# Dir: current working directory
|
||||
set_default POWERLEVEL9K_DIR_PATH_SEPARATOR "/"
|
||||
prompt_dir() {
|
||||
local current_path='%~'
|
||||
if [[ -n "$POWERLEVEL9K_SHORTEN_DIR_LENGTH" ]]; then
|
||||
|
||||
local current_path="$(print -P "%~")"
|
||||
if [[ -n "$POWERLEVEL9K_SHORTEN_DIR_LENGTH" || "$POWERLEVEL9K_SHORTEN_STRATEGY" == "truncate_with_folder_marker" ]]; then
|
||||
set_default POWERLEVEL9K_SHORTEN_DELIMITER $'\U2026'
|
||||
|
||||
case "$POWERLEVEL9K_SHORTEN_STRATEGY" in
|
||||
|
@ -625,7 +642,12 @@ prompt_dir() {
|
|||
package_path=${$(pwd)%%/.git*}
|
||||
fi
|
||||
|
||||
zero='%([BSUbfksu]|([FB]|){*})'
|
||||
# Replace the shortest possible match of the marked folder from
|
||||
# the current path. Remove the amount of characters up to the
|
||||
# folder marker from the left. Count only the visible characters
|
||||
# in the path (this is done by the "zero" pattern; see
|
||||
# http://stackoverflow.com/a/40855342/5586433).
|
||||
local zero='%([BSUbfksu]|([FB]|){*})'
|
||||
current_dir=$(pwd)
|
||||
# Then, find the length of the package_path string, and save the
|
||||
# subdirectory path as a substring of the current directory's path from 0
|
||||
|
@ -643,14 +665,44 @@ prompt_dir() {
|
|||
current_path=$(truncatePathFromRight "$(pwd | sed -e "s,^$HOME,~,")" )
|
||||
fi
|
||||
;;
|
||||
truncate_with_folder_marker)
|
||||
local last_marked_folder marked_folder
|
||||
set_default POWERLEVEL9K_SHORTEN_FOLDER_MARKER ".shorten_folder_marker"
|
||||
|
||||
# Search for the folder marker in the parent directories and
|
||||
# buildup a pattern that is removed from the current path
|
||||
# later on.
|
||||
for marked_folder in $(upsearch $POWERLEVEL9K_SHORTEN_FOLDER_MARKER); do
|
||||
if [[ "$marked_folder" == "/" ]]; then
|
||||
# If we reached root folder, stop upsearch.
|
||||
current_path="/"
|
||||
elif [[ "$marked_folder" == "$HOME" ]]; then
|
||||
# If we reached home folder, stop upsearch.
|
||||
current_path="~"
|
||||
elif [[ "${marked_folder%/*}" == $last_marked_folder ]]; then
|
||||
current_path="${current_path%/}/${marked_folder##*/}"
|
||||
else
|
||||
current_path="${current_path%/}/$POWERLEVEL9K_SHORTEN_DELIMITER/${marked_folder##*/}"
|
||||
fi
|
||||
last_marked_folder=$marked_folder
|
||||
done
|
||||
|
||||
# Replace the shortest possible match of the marked folder from
|
||||
# the current path.
|
||||
current_path=$current_path${PWD#${last_marked_folder}*}
|
||||
;;
|
||||
*)
|
||||
current_path="%$((POWERLEVEL9K_SHORTEN_DIR_LENGTH+1))(c:$POWERLEVEL9K_SHORTEN_DELIMITER/:)%${POWERLEVEL9K_SHORTEN_DIR_LENGTH}c"
|
||||
current_path="$(print -P "%$((POWERLEVEL9K_SHORTEN_DIR_LENGTH+1))(c:$POWERLEVEL9K_SHORTEN_DELIMITER/:)%${POWERLEVEL9K_SHORTEN_DIR_LENGTH}c")"
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
|
||||
if [[ "${POWERLEVEL9K_DIR_OMIT_FIRST_CHARACTER}" == "true" ]]; then
|
||||
current_path="${current_path[2,-1]}"
|
||||
fi
|
||||
|
||||
if [[ "${POWERLEVEL9K_DIR_PATH_SEPARATOR}" != "/" ]]; then
|
||||
current_path=$(print -P "${current_path}" | sed "s/\//${POWERLEVEL9K_DIR_PATH_SEPARATOR}/g")
|
||||
current_path="$( echo "${current_path}" | sed "s/\//${POWERLEVEL9K_DIR_PATH_SEPARATOR}/g")"
|
||||
fi
|
||||
|
||||
typeset -AH dir_states
|
||||
|
@ -920,6 +972,12 @@ prompt_rvm() {
|
|||
fi
|
||||
}
|
||||
|
||||
prompt_ssh() {
|
||||
if [[ -n "$SSH_CLIENT" ]] || [[ -n "$SSH_TTY" ]]; then
|
||||
"$1_prompt_segment" "$0" "$2" "$DEFAULT_COLOR" "yellow" "" 'SSH_ICON'
|
||||
fi
|
||||
}
|
||||
|
||||
# Status: return code if verbose, otherwise just an icon if an error occurred
|
||||
set_default POWERLEVEL9K_STATUS_VERBOSE true
|
||||
set_default POWERLEVEL9K_STATUS_OK_IN_NON_VERBOSE false
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue