aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristo Kotze <onaforeignshore@hotmail.co.uk>2018-02-10 13:46:56 +0300
committerChristo Kotze <onaforeignshore@hotmail.co.uk>2018-02-10 13:46:56 +0300
commitccba1cc8233143f7e360a3ab3ff61b7175327acf (patch)
treea5970ad540d39c54875e96d1a3095e1690c00baa
parent6d25e18779f33cd3339ecd491b3a195a714519ae (diff)
PROMPT_DIR color/bold on last dir & color for sep.
You can now set the last dir to have a custom color with `POWERLEVEL9K_DIR_PATH_HIGHLIGHT_FOREGROUND` and whether it will be bold with `POWERLEVEL9K_DIR_PATH_HIGHLIGHT_BOLD=true`. You can also set a custom separator color with `POWERLEVEL9K_DIR_PATH_SEPARATOR_FOREGROUND`.
-rw-r--r--README.md4
-rwxr-xr-xpowerlevel9k.zsh-theme38
2 files changed, 34 insertions, 8 deletions
diff --git a/README.md b/README.md
index 74edc446..7f9ee9ca 100644
--- a/README.md
+++ b/README.md
@@ -421,6 +421,10 @@ You can also configure the `dir` segment to show when you are in a directory wit
|----------|---------------|-------------|
|`POWERLEVEL9K_DIR_SHOW_WRITABLE`|`false`|If set to `true` and you are in a directory that you do not have write permissions for, this segment will display a lock icon and enter the `NOT_WRITABLE` state (which can be customized per [our usual process](https://github.com/bhilburn/powerlevel9k/wiki/Stylizing-Your-Prompt#segment-color-customization)). Note that this functionality is also available in a separate segment, `dir_writable`.|
+If you want to customize the last directory of the path, you can now set `POWERLEVEL9K_DIR_PATH_HIGHLIGHT_FOREGROUND` to a custom color and/or `POWERLEVEL9K_DIR_PATH_HIGHLIGHT_BOLD=true` to display that part in bold.
+
+You can also color the separator separately by setting the color using `POWERLEVEL9K_DIR_PATH_SEPARATOR_FOREGROUND`.
+
##### disk_usage
The `disk_usage` segment will show the usage level of the partition that your current working directory resides in. It can be configured with the following variables.
diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme
index 87b453a4..faaa32ec 100755
--- a/powerlevel9k.zsh-theme
+++ b/powerlevel9k.zsh-theme
@@ -838,18 +838,12 @@ prompt_dir() {
esac
fi
+ local path_opt=$current_path # save state of path for highlighting and bold options
+
if [[ "${POWERLEVEL9K_DIR_OMIT_FIRST_CHARACTER}" == "true" ]]; then
current_path="${current_path[2,-1]}"
fi
- if [[ "${POWERLEVEL9K_DIR_PATH_SEPARATOR}" != "/" ]]; then
- current_path="$( echo "${current_path}" | sed "s/\//${POWERLEVEL9K_DIR_PATH_SEPARATOR}/g")"
- fi
-
- if [[ "${POWERLEVEL9K_HOME_FOLDER_ABBREVIATION}" != "~" ]]; then
- current_path="$( echo "${current_path}" | sed "s/^~/${POWERLEVEL9K_HOME_FOLDER_ABBREVIATION}/")"
- fi
-
typeset -AH dir_states
dir_states=(
"DEFAULT" "FOLDER_ICON"
@@ -865,6 +859,34 @@ prompt_dir() {
elif [[ $(print -P "%~") == '~'* ]]; then
current_state="HOME_SUBFOLDER"
fi
+
+ local bd dir_state_foreground dir_state_user_foreground
+ [[ -n "${POWERLEVEL9K_DIR_PATH_HIGHLIGHT_BOLD}" ]] && bd="%B" || bd=""
+
+ local dir_state_user_foreground="POWERLEVEL9K_DIR_${current_state}_FOREGROUND"
+ local dir_state_foreground="${(P)dir_state_user_foreground}"
+ [[ -z "${dir_state_foreground}" ]] && dir_state_foreground="${DEFAULT_COLOR}"
+
+ if [[ -n "${POWERLEVEL9K_DIR_PATH_HIGHLIGHT_FOREGROUND}" ]]; then
+ if [[ $path_opt == "/" || $path_opt == "~" || $(dirname $path_opt) == "/" || ${POWERLEVEL9K_DIR_OMIT_FIRST_CHARACTER} ]]; then
+ current_path="$bd%F{$POWERLEVEL9K_DIR_PATH_HIGHLIGHT_FOREGROUND}$current_path%F{$dir_state_foreground}"
+ else
+ current_path="$(dirname $current_path)/$bd%F{$POWERLEVEL9K_DIR_PATH_HIGHLIGHT_FOREGROUND}$(basename $current_path)%F{$dir_state_foreground}"
+ fi
+ fi
+
+ if [[ -n "${POWERLEVEL9K_DIR_PATH_SEPARATOR_FOREGROUND}" && $path_opt != "/" ]]; then
+ current_path="$( echo "${current_path}" | sed "s/\//%F{$POWERLEVEL9K_DIR_PATH_SEPARATOR_FOREGROUND}\/%F{$dir_state_foreground}/g")"
+ fi
+
+ if [[ "${POWERLEVEL9K_DIR_PATH_SEPARATOR}" != "/" && $path_opt != "/" ]]; then
+ current_path="$( echo "${current_path}" | sed "s/\//${POWERLEVEL9K_DIR_PATH_SEPARATOR}/g")"
+ fi
+
+ if [[ "${POWERLEVEL9K_HOME_FOLDER_ABBREVIATION}" != "~" && ! ${POWERLEVEL9K_DIR_OMIT_FIRST_CHARACTER} ]]; then
+ current_path="$( echo "${current_path}" | sed "s/~/${POWERLEVEL9K_HOME_FOLDER_ABBREVIATION}/1")"
+ fi
+
"$1_prompt_segment" "$0_${current_state}" "$2" "blue" "$DEFAULT_COLOR" "${current_path}" "${dir_states[$current_state]}"
}