diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 861f5c318..93a293f81 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -99,134 +99,129 @@ typeset -AH deprecated_variables deprecated_variables=( # General icons # Due to the changes to `p9k::register_icon`, these now require the '_ICON' suffix to work. - 'P9K_MULTILINE_FIRST_PROMPT_PREFIX' 'P9K_MULTILINE_FIRST_PROMPT_PREFIX_ICON' - 'P9K_MULTILINE_LAST_PROMPT_PREFIX' 'P9K_MULTILINE_LAST_PROMPT_PREFIX_ICON' - 'P9K_LEFT_SEGMENT_SEPARATOR' 'P9K_LEFT_SEGMENT_SEPARATOR_ICON' - 'P9K_LEFT_SUBSEGMENT_SEPARATOR' 'P9K_LEFT_SUBSEGMENT_SEPARATOR_ICON' - 'P9K_RIGHT_SEGMENT_SEPARATOR' 'P9K_RIGHT_SEGMENT_SEPARATOR_ICON' - 'P9K_RIGHT_SUBSEGMENT_SEPARATOR' 'P9K_RIGHT_SUBSEGMENT_SEPARATOR_ICON' - # status icons - 'P9K_OK_ICON' 'P9K_STATUS_OK_ICON' - 'P9K_FAIL_ICON' 'P9K_STATUS_ERROR_ICON' - 'P9K_CARRIAGE_RETURN_ICON' 'P9K_STATUS_ERROR_CR_ICON' - # aws segment - 'AWS_DEFAULT_PROFILE' 'P9K_AWS_DEFAULT_PROFILE' - # aws_eb_env segment - 'P9K_AWS_EB_ICON' 'P9K_AWS_EB_ENV_ICON' - # command_execution_time segment - 'P9K_EXECUTION_TIME_ICON' 'P9K_COMMAND_EXECUTION_TIME_ICON' - # context segment - 'P9K_ALWAYS_SHOW_CONTEXT' 'P9K_CONTEXT_ALWAYS_SHOW' - 'P9K_ALWAYS_SHOW_USER' 'P9K_CONTEXT_ALWAYS_SHOW_USER' - # dir segment - 'P9K_HOME_ICON' 'P9K_DIR_HOME_ICON' - 'P9K_HOME_SUB_ICON' 'P9K_DIR_HOME_SUBFOLDER_ICON' - 'P9K_FOLDER_ICON' 'P9K_DIR_DEFAULT_ICON' - 'P9K_LOCK_ICON' 'P9K_DIR_NOT_WRITABLE_ICON' - 'P9K_ETC_ICON' 'P9K_DIR_ETC_ICON' - 'P9K_SHORTEN_DIR_LENGTH' 'P9K_DIR_SHORTEN_LENGTH' - 'P9K_SHORTEN_STRATEGY' 'P9K_DIR_SHORTEN_STRATEGY' - 'P9K_SHORTEN_DELIMITER' 'P9K_DIR_SHORTEN_DELIMITER' - 'P9K_SHORTEN_FOLDER_MARKER' 'P9K_DIR_SHORTEN_FOLDER_MARKER' - 'P9K_HOME_FOLDER_ABBREVIATION' 'P9K_DIR_HOME_FOLDER_ABBREVIATION' - # disk_usage segment - 'P9K_DISK_ICON' 'P9K_DISK_USAGE_NORMAL_ICON,P9K_DISK_USAGE_WARNING_ICON,P9K_DISK_USAGE_CRITICAL_ICON' - # docker_machine segment - 'P9K_SERVER_ICON' 'P9K_DOCKER_MACHINE_ICON' - # host segment - 'P9K_HOST_ICON' 'P9K_HOST_LOCAL_ICON,P9K_HOST_REMOTE_ICON' - # ip segment - 'P9K_NETWORK_ICON' 'P9K_IP_ICON' - # go_version segment - 'P9K_GO_ICON' 'P9K_GO_VERSION_ICON' - # kubecontext segment - 'P9K_KUBERNETES_ICON' 'P9K_KUBECONTEXT_ICON' - # load segment - 'P9K_LOAD_ICON' 'P9K_LOAD_NORMAL_ICON,P9K_LOAD_WARNING_ICON,P9K_LOAD_CRITICAL_ICON' - # node_env and node_version segments - 'P9K_NODE_ICON' 'P9K_NODE_ENV_ICON,P9K_NODE_VERSION_ICON' - # pyenv segment - 'P9K_PYTHON_ICON' 'P9K_PYENV_ICON' - # rbenv segment - 'P9K_RUBY_ICON' 'P9K_RBENV_ICON' - # rust segment - 'P9K_RUST_ICON' 'P9K_RUST_VERSION_ICON' - # swift_version segment - 'P9K_SWIFT_ICON' 'P9K_SWIFT_VERSION_ICON' - # user segment - 'P9K_USER_ICON' 'P9K_USER_DEFAULT_ICON' - 'P9K_ROOT_ICON' 'P9K_USER_ROOT_ICON' - 'P9K_SUDO_ICON' 'P9K_USER_SUDO_ICON' - # vcs segment - 'P9K_HIDE_BRANCH_ICON' 'P9K_VCS_HIDE_BRANCH_ICON' - 'P9K_SHOW_CHANGESET' 'P9K_VCS_SHOW_CHANGESET' - 'P9K_CHANGESET_HASH_LENGTH' 'P9K_VCS_CHANGESET_HASH_LENGTH' - # vi_mode segment - 'P9K_VI_INSERT_MODE_STRING' 'P9K_VI_MODE_INSERT_STRING' - 'P9K_VI_COMMAND_MODE_STRING' 'P9K_VI_MODE_NORMAL_STRING' - 'P9K_VI_VISUAL_MODE_STRING' 'P9K_VI_MODE_VISUAL_STRING' - 'P9K_VI_SEARCH_MODE_STRING' 'P9K_VI_MODE_SEARCH_STRING' -) -__p9k_print_deprecation_var_warning deprecated_variables +???LIGNES MANQUANTES +???LIGNES MANQUANTES +???LIGNES MANQUANTES +???LIGNES MANQUANTES +???LIGNES MANQUANTES +???LIGNES MANQUANTES +???LIGNES MANQUANTES +???LIGNES MANQUANTES +???LIGNES MANQUANTES + RPROMPT="${RPROMPT_PREFIX}"'%f%b%k$(build_right_prompt)%{$reset_color%}'"${RPROMPT_SUFFIX}" + fi -################################################################ -# Choose the generator -################################################################ +local NEWLINE=' +' -case "${(L)P9K_GENERATOR}" in - "zsh-async") - source "${__P9K_DIRECTORY}/generator/zsh-async.p9k" - ;; - *) - source "${__P9K_DIRECTORY}/generator/default.p9k" - ;; -esac + if [[ $POWERLEVEL9K_PROMPT_ADD_NEWLINE == true ]]; then + NEWLINES="" + repeat ${POWERLEVEL9K_PROMPT_ADD_NEWLINE_COUNT:-1} { NEWLINES+=$NEWLINE } + PROMPT="$NEWLINES$PROMPT" + fi -################################################################ -# Set default prompt segments -################################################################ + # Allow iTerm integration to work + [[ $ITERM_SHELL_INTEGRATION_INSTALLED == "Yes" ]] && PROMPT="%{$(iterm2_prompt_mark)%}$PROMPT" +} -p9k::defined P9K_LEFT_PROMPT_ELEMENTS || P9K_LEFT_PROMPT_ELEMENTS=(context dir vcs) -p9k::defined P9K_RIGHT_PROMPT_ELEMENTS || P9K_RIGHT_PROMPT_ELEMENTS=(status root_indicator background_jobs history time) +zle-keymap-select () { + zle reset-prompt + zle -R +} -################################################################ -# Load Prompt Segment Definitions -################################################################ +set_default POWERLEVEL9K_IGNORE_TERM_COLORS false +set_default POWERLEVEL9K_IGNORE_TERM_LANG false + +prompt_powerlevel9k_setup() { + # The value below was set to better support 32-bit CPUs. + # It's the maximum _signed_ integer value on 32-bit CPUs. + # Please don't change it until 19 January of 2038. ;) + + # Disable false display of command execution time + _P9K_TIMER_START=0x7FFFFFFF + + # The prompt function will set these prompt_* options after the setup function + # returns. We need prompt_subst so we can safely run commands in the prompt + # without them being double expanded and we need prompt_percent to expand the + # common percent escape sequences. + prompt_opts=(cr percent sp subst) + + # Borrowed from promptinit, sets the prompt options in case the theme was + # not initialized via promptinit. + setopt noprompt{bang,cr,percent,sp,subst} "prompt${^prompt_opts[@]}" + + # Display a warning if the terminal does not support 256 colors + termColors + + # If the terminal `LANG` is set to `C`, this theme will not work at all. + if [[ $POWERLEVEL9K_IGNORE_TERM_LANG == false ]]; then + local term_lang + term_lang=$(echo $LANG) + if [[ $term_lang == 'C' ]]; then + print -P "\t%F{red}WARNING!%f Your terminal's 'LANG' is set to 'C', which breaks this theme!" + print -P "\t%F{red}WARNING!%f Please set your 'LANG' to a UTF-8 language, like 'en_US.UTF-8'" + print -P "\t%F{red}WARNING!%f _before_ loading this theme in your \~\.zshrc. Putting" + print -P "\t%F{red}WARNING!%f %F{blue}export LANG=\"en_US.UTF-8\"%f at the top of your \~\/.zshrc is sufficient." + fi + fi -p9k::set_default P9K_CUSTOM_SEGMENT_LOCATION "$HOME/.config/powerlevel9k/segments" -# load only the segments that are being used! -function __p9k_load_segments() { - local segment - for segment in ${P9K_LEFT_PROMPT_ELEMENTS} ${P9K_RIGHT_PROMPT_ELEMENTS}; do - # Remove joined information - segment=${segment%_joined} - - # Custom segments must be loaded by user - if [[ $segment[0,7] =~ "custom_" ]]; then - continue - fi - # check if the file exists as a core segment - if [[ -f ${__P9K_DIRECTORY}/segments/${segment}/${segment}.p9k ]]; then - source "${__P9K_DIRECTORY}/segments/${segment}/${segment}.p9k" 2>&1 + defined POWERLEVEL9K_LEFT_PROMPT_ELEMENTS || POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(context dir vcs) + defined POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS || POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=(status root_indicator background_jobs history time) + + # Display a warning if deprecated segments are in use. + typeset -AH deprecated_segments + # old => new + deprecated_segments=( + 'longstatus' 'status' + ) + print_deprecation_warning deprecated_segments + + # initialize colors + autoload -U colors && colors + + if segment_in_use "vcs"; then + powerlevel9k_vcs_init + fi + + # initialize timing functions + zmodload zsh/datetime + + # Initialize math functions + zmodload zsh/mathfunc + + # initialize hooks + autoload -Uz add-zsh-hook + + # prepare prompts + add-zsh-hook precmd powerlevel9k_prepare_prompts + add-zsh-hook preexec powerlevel9k_preexec + + zle -N zle-keymap-select +} + +prompt_powerlevel9k_teardown() { + add-zsh-hook -D precmd powerlevel9k_\* + add-zsh-hook -D preexec powerlevel9k_\* + PROMPT='%m%# ' + RPROMPT= +} + +>>>>>>> Stashed changes +prompt_powerlevel9k_setup "$@" + + +################################################################ +# Virtualenv: current working virtualenv +# More information on virtualenv (Python): +# https://virtualenv.pypa.io/en/latest/ +prompt_virtualenv() { + if [[ -n "$VIRTUAL_ENV" ]]; then + if [[ "$POWERLEVEL9K_VIRTUALENV_SHOW_VERSION" == true ]]; then + local python_version=$(python -V | awk '{print $2}') + "$1_prompt_segment" "$0" "$2" "blue" "$DEFAULT_COLOR" "${python_version} ${${VIRTUAL_ENV:t}//\%/%%}" 'PYTHON_ICON' else - # check if the file exists as a custom segment - if [[ -f "${P9K_CUSTOM_SEGMENT_LOCATION}/${segment}/${segment}.p9k" ]]; then - # This is not muted, as we want to show if there are issues with - # his custom segments. - source "${P9K_CUSTOM_SEGMENT_LOCATION}/${segment}/${segment}.p9k" - else - # file not found! - # If this happens, we remove the segment from the configured elements, - # so that we avoid printing errors over and over. - print -P "%F{yellow}Warning!%f The '%F{cyan}${segment}%f' segment was not found. Removing it from the prompt." - P9K_LEFT_PROMPT_ELEMENTS=("${(@)P9K_LEFT_PROMPT_ELEMENTS:#${segment}}") - P9K_RIGHT_PROMPT_ELEMENTS=("${(@)P9K_RIGHT_PROMPT_ELEMENTS:#${segment}}") - P9K_PROMPT_ELEMENTS=("${(@)P9K_PROMPT_ELEMENTS:#${segment}}") - fi + "$1_prompt_segment" "$0" "$2" "blue" "$DEFAULT_COLOR" "${${VIRTUAL_ENV:t}//\%/%%}" 'PYTHON_ICON' fi - done + fi } -__p9k_load_segments -# lauch the generator (prompt) -prompt_powerlevel9k_setup "$@" diff --git a/segments/virtualenv/README.md b/segments/virtualenv/README.md index a62908452..02804695e 100644 --- a/segments/virtualenv/README.md +++ b/segments/virtualenv/README.md @@ -10,6 +10,13 @@ where you want to show this segment. ## Configuration +### Option to read python of virtualenv version + +You can read just in front of the virtual environment name, the python version for this environment by setting +``` +POWERLEVEL9K_VIRTUALENV_SHOW_VERSION=true +``` + ### Color Customization You can change the foreground and background color of this segment by setting @@ -21,4 +28,4 @@ P9K_VIRTUALENV_BACKGROUND='blue' ### Customize Icon The main Icon can be changed by setting `P9K_VIRTUALENV_ICON="my_icon"`. To change the -icon color only, set `P9K_VIRTUALENV_ICON_COLOR="red"`. \ No newline at end of file +icon color only, set `P9K_VIRTUALENV_ICON_COLOR="red"`.