From 7a776dc68c3cdf05b7124317088d6c2a5ce7751f Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Tue, 29 Nov 2016 22:35:50 +0100 Subject: [PATCH 1/6] Modify dir segment to use proper states --- powerlevel9k.zsh-theme | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index da3639e1..65b88199 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -501,17 +501,21 @@ prompt_dir() { current_path="%$((POWERLEVEL9K_SHORTEN_DIR_LENGTH+1))(c:$POWERLEVEL9K_SHORTEN_DELIMITER/:)%${POWERLEVEL9K_SHORTEN_DIR_LENGTH}c" ;; esac - 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 From a1b4d44755024972af02a7cecbc291fa8684b7ae Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Tue, 29 Nov 2016 22:58:19 +0100 Subject: [PATCH 2/6] Make path separator configurable for dir prompt Now the path separator can be configured by setting `POWERLEVEL9K_DIR_PATH_SEPARATOR` --- powerlevel9k.zsh-theme | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 65b88199..9bf09c6f 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -456,6 +456,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,6 +504,10 @@ prompt_dir() { esac fi + if [[ "${POWERLEVEL9K_DIR_PATH_SEPARATOR}" != "/" ]]; then + current_path=$(echo "${current_path}" | sed "s/\//${POWERLEVEL9K_DIR_PATH_SEPARATOR}/g") + fi + typeset -AH dir_states dir_states=( "DEFAULT" "FOLDER_ICON" From 159938f00ec58635a494426cdcd7c770ae333d51 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Tue, 29 Nov 2016 23:05:10 +0100 Subject: [PATCH 3/6] Add changelog entry for dir path separator --- CHANGELOG.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7a3f7444..91a897ee 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,11 @@ +## next + +### `dir` changes + +Added an option to configure the path separator. If you want something +else than an ordinary slash, you could set +`POWERLEVEL9K_DIR_PATH_SEPARATOR` to whatever you want. + ## v0.4.0 ### Development changes From 51e1aa1b16e6048939bb2b9946abce16323a890b Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Tue, 29 Nov 2016 23:19:35 +0100 Subject: [PATCH 4/6] Add documenatation for dir path separator --- README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.md b/README.md index 8cdf7be2..5f86dd3d 100644 --- a/README.md +++ b/README.md @@ -288,6 +288,12 @@ The `truncate_with_package_name` strategy gives your directory path relative to the path shown would be `my-cool-project`. If you navigate to `$HOME/projects/my-project/src`, then the path shown would be `my-cool-project/src`. Please note that this currently looks for `.git` directory to determine the root of the project. +If you want to customize the directory separator, you could set: +```zsh +# You'll need patched awesome-terminal fonts for that example +POWERLEVEL9K_DIR_PATH_SEPARATOR="%f "$'\uE0B1'" %F" +``` + ##### ip This segment tries to examine all currently used network interfaces and prints From 11b8545fe283fd7c5b51ef2eef411057d9f3cfe2 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Tue, 29 Nov 2016 23:24:15 +0100 Subject: [PATCH 5/6] Add syntax highlighting to examples in README --- README.md | 78 +++++++++++++++++++++++++++---------------------------- 1 file changed, 39 insertions(+), 39 deletions(-) diff --git a/README.md b/README.md index 5f86dd3d..dc98b7d8 100644 --- a/README.md +++ b/README.md @@ -76,10 +76,10 @@ variables to your `~/.zshrc`. So if you wanted to set these variables manually, you would put the following in your `~/.zshrc`: - - POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(context dir rbenv vcs) - POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=(status history time) - +```zsh +POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(context dir rbenv vcs) +POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=(status history time) +``` #### Available Prompt Segments The segments that are currently available are: @@ -198,28 +198,28 @@ The `custom_...` segment allows you to turn the output of a custom command into a prompt segment. As an example, if you wanted to create a custom segment to display your WiFi signal strength, you might define a custom segment called `custom_wifi_signal` like this: - - POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(context time battery dir vcs virtualenv custom_wifi_signal) - POWERLEVEL9K_CUSTOM_WIFI_SIGNAL="echo signal: \$(nmcli device wifi | grep yes | awk '{print \$8}')" - POWERLEVEL9K_CUSTOM_WIFI_SIGNAL_BACKGROUND="blue" - POWERLEVEL9K_CUSTOM_WIFI_SIGNAL_FOREGROUND="yellow" - +```zsh +POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(context time battery dir vcs virtualenv custom_wifi_signal) +POWERLEVEL9K_CUSTOM_WIFI_SIGNAL="echo signal: \$(nmcli device wifi | grep yes | awk '{print \$8}')" +POWERLEVEL9K_CUSTOM_WIFI_SIGNAL_BACKGROUND="blue" +POWERLEVEL9K_CUSTOM_WIFI_SIGNAL_FOREGROUND="yellow" +``` If you prefer, you can also define the function in your `.zshrc` rather than putting it in-line with the variable export, as shown above. Just don't forget to invoke your function from your segment! Example code that achieves the same result as the above: +```zsh +zsh_wifi_signal(){ + local signal=$(nmcli device wifi | grep yes | awk '{print $8}') + local color='%F{yellow}' + [[ $signal -gt 75 ]] && color='%F{green}' + [[ $signal -lt 50 ]] && color='%F{red}' + echo -n "%{$color%}\uf230 $signal%{%f%}" # \uf230 is  +} - zsh_wifi_signal(){ - local signal=$(nmcli device wifi | grep yes | awk '{print $8}') - local color='%F{yellow}' - [[ $signal -gt 75 ]] && color='%F{green}' - [[ $signal -lt 50 ]] && color='%F{red}' - echo -n "%{$color%}\uf230 $signal%{%f%}" # \uf230 is  - } - - POWERLEVEL9K_CUSTOM_WIFI_SIGNAL="zsh_wifi_signal" - POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(context time battery dir vcs virtualenv custom_wifi_signal) - +POWERLEVEL9K_CUSTOM_WIFI_SIGNAL="zsh_wifi_signal" +POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(context time battery dir vcs virtualenv custom_wifi_signal) +``` The command, above, gives you the wireless signal segment shown below: ![signal](http://i.imgur.com/hviMATC.png) @@ -253,11 +253,11 @@ Powerline" fonts, there are additional glyphs, as well: | None | None | ![](https://cloud.githubusercontent.com/assets/1544760/12183452/40f79286-b58f-11e5-9b8c-ed1343a07b08.png) | Outside of your home folder | To turn off these icons you could set these variables to an empty string. - - POWERLEVEL9K_HOME_ICON='' - POWERLEVEL9K_HOME_SUB_ICON='' - POWERLEVEL9K_FOLDER_ICON='' - +```zsh +POWERLEVEL9K_HOME_ICON='' +POWERLEVEL9K_HOME_SUB_ICON='' +POWERLEVEL9K_FOLDER_ICON='' +``` You can limit the output to a certain length by truncating long paths. Customizations available are: @@ -269,11 +269,11 @@ Customizations available are: For example, if you wanted the truncation behavior of the `fish` shell, which truncates `/usr/share/plasma` to `/u/s/plasma`, you would use the following: - - POWERLEVEL9K_SHORTEN_DIR_LENGTH=1 - POWERLEVEL9K_SHORTEN_DELIMITER="" - POWERLEVEL9K_SHORTEN_STRATEGY="truncate_from_right" - +```zsh +POWERLEVEL9K_SHORTEN_DIR_LENGTH=1 +POWERLEVEL9K_SHORTEN_DELIMITER="" +POWERLEVEL9K_SHORTEN_STRATEGY="truncate_from_right" +``` In each case you have to specify the length you want to shorten the directory to. So in some cases `POWERLEVEL9K_SHORTEN_DIR_LENGTH` means characters, in others whole directories. @@ -343,16 +343,16 @@ See [Unit Test Ratios](#unit-test-ratios), below. |`POWERLEVEL9K_TIME_FORMAT`|`'H:M:S'`|ZSH time format to use in this segment.| As an example, if you wanted a reversed time format, you would use this: - - # Reversed time format - POWERLEVEL9K_TIME_FORMAT='%D{%S:%M:%H}' - +```zsh +# Reversed time format +POWERLEVEL9K_TIME_FORMAT='%D{%S:%M:%H}' +``` If you are using an "Awesome Powerline Font", you can add a time symbol to this segment, as well: - - # Output time, date, and a symbol from the "Awesome Powerline Font" set - POWERLEVEL9K_TIME_FORMAT="%D{%H:%M:%S \uE868 %d.%m.%y}" - +```zsh +# Output time, date, and a symbol from the "Awesome Powerline Font" set +POWERLEVEL9K_TIME_FORMAT="%D{%H:%M:%S \uE868 %d.%m.%y}" +``` ##### vcs By default, the `vcs` segment will provide quite a bit of information. Further From 202ab1500727e4f37545eaff849d4f9a52b823c4 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Sun, 4 Dec 2016 18:43:47 +0100 Subject: [PATCH 6/6] Fix display of custom dir path separator on linux --- powerlevel9k.zsh-theme | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 9bf09c6f..c4b24b55 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -505,7 +505,7 @@ prompt_dir() { fi if [[ "${POWERLEVEL9K_DIR_PATH_SEPARATOR}" != "/" ]]; then - current_path=$(echo "${current_path}" | sed "s/\//${POWERLEVEL9K_DIR_PATH_SEPARATOR}/g") + current_path=$(print -P "${current_path}" | sed "s/\//${POWERLEVEL9K_DIR_PATH_SEPARATOR}/g") fi typeset -AH dir_states @@ -520,7 +520,7 @@ prompt_dir() { elif [[ $(print -P "%~") == '~'* ]]; then current_state="HOME_SUBFOLDER" fi - "$1_prompt_segment" "$0_${current_state}" "$2" "blue" "$DEFAULT_COLOR" "$current_path" "${dir_states[$current_state]}" + "$1_prompt_segment" "$0_${current_state}" "$2" "blue" "$DEFAULT_COLOR" "${current_path}" "${dir_states[$current_state]}" } # Docker machine