aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGELOG.md21
-rw-r--r--README.md11
-rw-r--r--functions/utilities.zsh6
-rwxr-xr-xpowerlevel9k.zsh-theme42
4 files changed, 76 insertions, 4 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 557f977b..064f5283 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -10,6 +10,11 @@ POWERLEVEL9K_VCS_CLEAN_FOREGROUND='cyan'
POWERLEVEL9K_VCS_CLEAN_BACKGROUND='white'
```
+The foreground color of actionformat is now configurable via:
+```zsh
+POWERLEVEL9K_VCS_ACTIONFORMAT_FOREGROUND='green'
+```
+
### `aws_eb_env` added
This segment displays the current Elastic Beanstalk environment.
@@ -19,6 +24,22 @@ This segment displays the current Elastic Beanstalk environment.
The `ram` segment was split up into `ram` and `swap`. The `POWERLEVEL9K_RAM_ELEMENTS`
variable is void.
+### `dir` Shortening Strategies
+
+There is now a path shortening strategy that will use the `package.json` file to shorten your directory path. See the documentation for the `dir` segment for more details.
+
+### `chruby` Segment
+
+Added new `chruby` segment to support this version manager.
+
+### `node`, `nvm` Segments
+
+Improvements to speed / reliability.
+
+### `docker` Segment
+
+Added new `docker` segment that will show your Docker machine.
+
## v0.3.2
### `vcs` changes
diff --git a/README.md b/README.md
index f5a689cf..9e9ff64c 100644
--- a/README.md
+++ b/README.md
@@ -243,7 +243,7 @@ Customizations available are:
| Variable | Default Value | Description |
|----------|---------------|-------------|
|`POWERLEVEL9K_SHORTEN_DIR_LENGTH`|`2`|If your shorten strategy, below, is entire directories, this field determines how many directories to leave at the end. If your shorten strategy is by character count, this field determines how many characters to allow per directory string.|
-|`POWERLEVEL9K_SHORTEN_STRATEGY`|None|How the directory strings should be truncated. By default, it will truncate whole directories. Other options are `truncate_middle`, which leaves the start and end of the directory strings, and `truncate_from_right`, which cuts starting from the end of the string.|
+|`POWERLEVEL9K_SHORTEN_STRATEGY`|None|How the directory strings should be truncated. By default, it will truncate whole directories. Other options are `truncate_middle`, which leaves the start and end of the directory strings, and `truncate_from_right`, which cuts starting from the end of the string. You can also use `truncate_with_package_name` to use the `package.json` `name` field to abbreviate the directory path.|
|`POWERLEVEL9K_SHORTEN_DELIMITER`|`..`|Delimiter to use in truncated strings. This can be any string you choose, including an empty string if you wish to have no delimiter.|
For example, if you wanted the truncation behavior of the `fish` shell, which
@@ -257,6 +257,15 @@ 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.
+The `truncate_with_package_name` strategy gives your directory path relative to the root of your project. For example, if you have a project inside `$HOME/projects/my-project` with a `package.json` that looks like:
+
+```json
+{
+ "name": "my-cool-project"
+}
+```
+
+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.
##### ip
diff --git a/functions/utilities.zsh b/functions/utilities.zsh
index 5ca5b431..eed6ccc5 100644
--- a/functions/utilities.zsh
+++ b/functions/utilities.zsh
@@ -186,3 +186,9 @@ function segmentShouldBeJoined() {
return 1
fi
}
+
+# Given a directory path, truncate it according to the settings for
+# `truncate_from_right`
+function truncatePathFromRight() {
+ echo $1 | sed $SED_EXTENDED_REGEX_PARAMETER "s/([^/]{$POWERLEVEL9K_SHORTEN_DIR_LENGTH})[^/]+\//\1$POWERLEVEL9K_SHORTEN_DELIMITER\//g"
+}
diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme
index bba5a6f6..7da17f99 100755
--- a/powerlevel9k.zsh-theme
+++ b/powerlevel9k.zsh-theme
@@ -444,7 +444,43 @@ prompt_dir() {
current_path=$(pwd | sed -e "s,^$HOME,~," | sed $SED_EXTENDED_REGEX_PARAMETER "s/([^/]{$POWERLEVEL9K_SHORTEN_DIR_LENGTH})[^/]+([^/]{$POWERLEVEL9K_SHORTEN_DIR_LENGTH})\//\1$POWERLEVEL9K_SHORTEN_DELIMITER\2\//g")
;;
truncate_from_right)
- current_path=$(pwd | sed -e "s,^$HOME,~," | sed $SED_EXTENDED_REGEX_PARAMETER "s/([^/]{$POWERLEVEL9K_SHORTEN_DIR_LENGTH})[^/]+\//\1$POWERLEVEL9K_SHORTEN_DELIMITER\//g")
+ current_path=$(truncatePathFromRight $(pwd | sed -e "s,^$HOME,~,") )
+ ;;
+ truncate_with_package_name)
+ local name repo_path package_path current_dir zero
+
+ # Get the path of the Git repo, which should have the package.json file
+ if repo_path=$(git rev-parse --git-dir 2>/dev/null); then
+ if [[ "$repo_path" == ".git" ]]; then
+ # If the current path is the root of the project, then the package path is
+ # the current directory and we don't want to append anything to represent
+ # the path to a subdirectory
+ package_path="."
+ subdirectory_path=""
+ else
+ # If the current path is something else, get the path to the package.json
+ # file by finding the repo path and removing the '.git` from the path
+ package_path=${repo_path:0:-4}
+ zero='%([BSUbfksu]|([FB]|){*})'
+ current_dir=$(pwd)
+ # Then, find the length of the package_path string, and save the
+ # subdirectory path as a substring of the current directory's path from 0
+ # to the length of the package path's string
+ subdirectory_path=$(truncatePathFromRight "/${current_dir:${#${(S%%)package_path//$~zero/}}}")
+ fi
+ fi
+
+ # Parse the 'name' from the package.json; if there are any problems, just
+ # print the file path
+ if name=$( cat "$package_path/package.json" 2> /dev/null | grep "\"name\""); then
+ name=$(echo $name | awk -F ':' '{print $2}' | awk -F '"' '{print $2}')
+
+ # Instead of printing out the full path, print out the name of the package
+ # from the package.json and append the current subdirectory
+ current_path="`echo $name | tr -d '"'`$subdirectory_path"
+ else
+ current_path=$(truncatePathFromRight $(pwd | sed -e "s,^$HOME,~,") )
+ fi
;;
*)
current_path="%$((POWERLEVEL9K_SHORTEN_DIR_LENGTH+1))(c:$POWERLEVEL9K_SHORTEN_DELIMITER/:)%${POWERLEVEL9K_SHORTEN_DIR_LENGTH}c"
@@ -778,6 +814,7 @@ prompt_todo() {
# VCS segment: shows the state of your repository, if you are in a folder under
# version control
+set_default POWERLEVEL9K_VCS_ACTIONFORMAT_FOREGROUND "red"
prompt_vcs() {
autoload -Uz vcs_info
@@ -791,7 +828,6 @@ prompt_vcs() {
'clean' 'green'
'modified' 'yellow'
'untracked' 'green'
- 'actionformat' 'red'
)
VCS_CHANGESET_PREFIX=''
@@ -811,7 +847,7 @@ prompt_vcs() {
VCS_DEFAULT_FORMAT="$VCS_CHANGESET_PREFIX%b%c%u%m"
zstyle ':vcs_info:*' formats "$VCS_DEFAULT_FORMAT"
- zstyle ':vcs_info:*' actionformats "%b %F{${vcs_states[actionformat]}}| %a%f"
+ zstyle ':vcs_info:*' actionformats "%b %F{${POWERLEVEL9K_VCS_ACTIONFORMAT_FOREGROUND}}| %a%f"
zstyle ':vcs_info:*' stagedstr " $(print_icon 'VCS_STAGED_ICON')"
zstyle ':vcs_info:*' unstagedstr " $(print_icon 'VCS_UNSTAGED_ICON')"