diff options
Diffstat (limited to 'powerlevel9k.zsh-theme')
-rwxr-xr-x | powerlevel9k.zsh-theme | 64 |
1 files changed, 51 insertions, 13 deletions
diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index d56e46f4..40fdf897 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -411,7 +411,7 @@ prompt_battery() { local time_remaining=$(acpi | awk '{ print $5 }') if [[ $time_remaining =~ rate ]]; then local tstring="..." - elif [[ $time_remaining =~ "[:digit:]+" ]]; then + elif [[ $time_remaining =~ "[[:digit:]]+" ]]; then local tstring=${(f)$(date -u -d "$(echo $time_remaining)" +%k:%M 2> /dev/null)} fi fi @@ -458,6 +458,7 @@ prompt_custom() { } # Dir: current working directory +set_default POWERLEVEL9K_DIR_PATH_SEPARATOR "/" prompt_dir() { local current_path='%~' if [[ -n "$POWERLEVEL9K_SHORTEN_DIR_LENGTH" ]]; then @@ -503,17 +504,25 @@ prompt_dir() { current_path="%$((POWERLEVEL9K_SHORTEN_DIR_LENGTH+1))(c:$POWERLEVEL9K_SHORTEN_DELIMITER/:)%${POWERLEVEL9K_SHORTEN_DIR_LENGTH}c" ;; esac + fi + if [[ "${POWERLEVEL9K_DIR_PATH_SEPARATOR}" != "/" ]]; then + current_path=$(print -P "${current_path}" | sed "s/\//${POWERLEVEL9K_DIR_PATH_SEPARATOR}/g") fi - local current_icon='' + typeset -AH dir_states + dir_states=( + "DEFAULT" "FOLDER_ICON" + "HOME" "HOME_ICON" + "HOME_SUBFOLDER" "HOME_SUB_ICON" + ) + local current_state="DEFAULT" if [[ $(print -P "%~") == '~' ]]; then - "$1_prompt_segment" "$0_HOME" "$2" "blue" "$DEFAULT_COLOR" "$current_path" 'HOME_ICON' + current_state="HOME" elif [[ $(print -P "%~") == '~'* ]]; then - "$1_prompt_segment" "$0_HOME_SUBFOLDER" "$2" "blue" "$DEFAULT_COLOR" "$current_path" 'HOME_SUB_ICON' - else - "$1_prompt_segment" "$0_DEFAULT" "$2" "blue" "$DEFAULT_COLOR" "$current_path" 'FOLDER_ICON' + current_state="HOME_SUBFOLDER" fi + "$1_prompt_segment" "$0_${current_state}" "$2" "blue" "$DEFAULT_COLOR" "${current_path}" "${dir_states[$current_state]}" } # Docker machine @@ -540,6 +549,26 @@ prompt_history() { "$1_prompt_segment" "$0" "$2" "244" "$DEFAULT_COLOR" '%h' } +# Detection for virtualization (systemd based systems only) +prompt_detect_virt() { + if ! command -v systemd-detect-virt;then + return + fi + local virt=$(systemd-detect-virt) + local color="yellow" + if [[ "$virt" == "none" ]]; then + if [[ "$(ls -di / | grep -o 2)" != "2" ]]; then + virt="chroot" + "$1_prompt_segment" "$0" "$2" "$color" "$DEFAULT_COLOR" "$virt" + else + ; + fi + else + "$1_prompt_segment" "$0" "$2" "$color" "$DEFAULT_COLOR" "$virt" + fi +} + + prompt_icons_test() { for key in ${(@k)icons}; do # The lower color spectrum in ZSH makes big steps. Choosing @@ -750,17 +779,16 @@ prompt_rvm() { # 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 prompt_status() { - if [[ "$POWERLEVEL9K_STATUS_VERBOSE" == true ]]; then - if [[ "$RETVAL" -ne 0 ]]; then + if [[ "$RETVAL" -ne 0 ]]; then + if [[ "$POWERLEVEL9K_STATUS_VERBOSE" == true ]]; then "$1_prompt_segment" "$0_ERROR" "$2" "red" "226" "$RETVAL" 'CARRIAGE_RETURN_ICON' else - "$1_prompt_segment" "$0_OK" "$2" "$DEFAULT_COLOR" "046" "" 'OK_ICON' - fi - else - if [[ "$RETVAL" -ne 0 ]]; then "$1_prompt_segment" "$0_ERROR" "$2" "$DEFAULT_COLOR" "red" "" 'FAIL_ICON' fi + elif [[ "$POWERLEVEL9K_STATUS_VERBOSE" == true || "$POWERLEVEL9K_STATUS_OK_IN_NON_VERBOSE" == true ]]; then + "$1_prompt_segment" "$0_OK" "$2" "$DEFAULT_COLOR" "046" "" 'OK_ICON' fi } @@ -967,6 +995,17 @@ prompt_pyenv() { fi } +# Swift version +prompt_swift_version() { + local swift_version=($(swift --version 2>/dev/null)) + [[ -z "${swift_version}" ]] && return + + # Extract semantic version + swift_version=$(echo ${swift_version} | sed -e 's/[^0-9.]*\([0-9.]*\).*/\1/') + + "$1_prompt_segment" "$0" "$2" "magenta" "white" "${swift_version}" 'SWIFT_ICON' +} + ################################################################ # Prompt processing and drawing ################################################################ @@ -1093,4 +1132,3 @@ powerlevel9k_init() { } powerlevel9k_init "$@" - |