From 291bcddd103a91c52e8464781c2a07e8a512b028 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Sun, 7 Jun 2015 01:06:26 +0200 Subject: [PATCH 1/3] Shorten dir path, if POWERLEVEL9K_SHORTEN_PWD_LENGTH is set. --- powerlevel9k.zsh-theme | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index df0319c7..1cd6a870 100644 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -318,7 +318,13 @@ prompt_context() { # Dir: current working directory prompt_dir() { - $1_prompt_segment $0 blue $DEFAULT_COLOR '%~' + local current_path='%~' + if [[ -n "$POWERLEVEL9K_SHORTEN_PWD_LENGTH" ]]; then + # shorten path to $POWERLEVEL9K_SHORTEN_PWD_LENGTH characters + local current_path="%${POWERLEVEL9K_SHORTEN_PWD_LENGTH}<..<%~%<<" + fi + + $1_prompt_segment $0 blue $DEFAULT_COLOR $current_path } # Command number (in local history) From fea1d7ec5e21be22f7bd58480a323f4509ff656e Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Sun, 7 Jun 2015 01:11:06 +0200 Subject: [PATCH 2/3] Added documentation. --- README.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/README.md b/README.md index dc8798fe..e3a382fa 100644 --- a/README.md +++ b/README.md @@ -110,6 +110,14 @@ elements (it is by default), and define a `DEFAULT_USER` in your `~/.zshrc`: export DEFAULT_USER= +#### The `dir` segment + +The `dir` segment shows the current working directory. You can limit the output +to a certain length: + + # Limit to 20 characters + POWERLEVEL9K_SHORTEN_PWD_LENGTH=20 + #### The 'time' segment By default the time is show in 'H:M:S' format. If you want to change it, From 891f5567fd198220cd2b7b4e471a465ac736579e Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Sun, 7 Jun 2015 01:48:02 +0200 Subject: [PATCH 3/3] Limit to whole folders, not just characters. --- README.md | 4 ++-- powerlevel9k.zsh-theme | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index e3a382fa..10610c3f 100644 --- a/README.md +++ b/README.md @@ -115,8 +115,8 @@ elements (it is by default), and define a `DEFAULT_USER` in your `~/.zshrc`: The `dir` segment shows the current working directory. You can limit the output to a certain length: - # Limit to 20 characters - POWERLEVEL9K_SHORTEN_PWD_LENGTH=20 + # Limit to the last two folders + POWERLEVEL9K_SHORTEN_DIR_LENGTH=2 #### The 'time' segment diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 1cd6a870..a049f863 100644 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -319,9 +319,9 @@ prompt_context() { # Dir: current working directory prompt_dir() { local current_path='%~' - if [[ -n "$POWERLEVEL9K_SHORTEN_PWD_LENGTH" ]]; then - # shorten path to $POWERLEVEL9K_SHORTEN_PWD_LENGTH characters - local current_path="%${POWERLEVEL9K_SHORTEN_PWD_LENGTH}<..<%~%<<" + if [[ -n "$POWERLEVEL9K_SHORTEN_DIR_LENGTH" ]]; then + # shorten path to $POWERLEVEL9K_SHORTEN_DIR_LENGTH + current_path="%$((POWERLEVEL9K_SHORTEN_DIR_LENGTH+1))(c:.../:)%${POWERLEVEL9K_SHORTEN_DIR_LENGTH}c" fi $1_prompt_segment $0 blue $DEFAULT_COLOR $current_path