diff --git a/README.md b/README.md index f06d8e07..225f14e7 100644 --- a/README.md +++ b/README.md @@ -402,7 +402,11 @@ You can also customize the leading tilde character when you are in `$HOME` using # Double quotes are important here! POWERLEVEL9K_HOME_FOLDER_ABBREVIATION="%F{red} $(print_icon 'HOME_ICON') %F{black}" ``` +You can also configure the `dir` segment to show when you are in a directory without write permissions, using the variable below. +| Variable | Default Value | Description | +|----------|---------------|-------------| +|`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`.| ##### disk_usage diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index c2b53374..8c78cb00 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -689,6 +689,7 @@ prompt_command_execution_time() { # Dir: current working directory set_default POWERLEVEL9K_DIR_PATH_SEPARATOR "/" set_default POWERLEVEL9K_HOME_FOLDER_ABBREVIATION "~" +set_default POWERLEVEL9K_DIR_SHOW_WRITABLE false prompt_dir() { local current_path="$(print -P "%~")" if [[ -n "$POWERLEVEL9K_SHORTEN_DIR_LENGTH" || "$POWERLEVEL9K_SHORTEN_STRATEGY" == "truncate_with_folder_marker" ]]; then @@ -802,9 +803,12 @@ prompt_dir() { "DEFAULT" "FOLDER_ICON" "HOME" "HOME_ICON" "HOME_SUBFOLDER" "HOME_SUB_ICON" + "NOT_WRITABLE" "LOCK_ICON" ) local current_state="DEFAULT" - if [[ $(print -P "%~") == '~' ]]; then + if [[ "${POWERLEVEL9K_DIR_SHOW_WRITABLE}" == true && ! -w "$PWD" ]]; then + current_state="NOT_WRITABLE" + elif [[ $(print -P "%~") == '~' ]]; then current_state="HOME" elif [[ $(print -P "%~") == '~'* ]]; then current_state="HOME_SUBFOLDER"