Powerlevel10k: Custom directory shorten strategy

Created on 14 Feb 2020  路  3Comments  路  Source: romkatv/powerlevel10k

I've got used to the path shortening strategy used by prezto, which shortens all directories to first character except for the last segment. Is there a way to add a custom shorten strategy without having to modify p10k code?

Most helpful comment

Please try the following:

  1. Open ~/.p10k.zsh.
  2. Search for anchor_files and set the value of this parameter to ().
local anchor_files=()
  1. Search for POWERLEVEL9K_DIR_MAX_LENGTH and set the value of this parameter to 1.
typeset -g POWERLEVEL9K_DIR_MAX_LENGTH=1
  1. Save changes.
  2. Restart Zsh.

You can also optionally adjust colors. Look for POWERLEVEL9K_DIR_FOREGROUND, POWERLEVEL9K_DIR_SHORTENED_FOREGROUND, POWERLEVEL9K_DIR_ANCHOR_FOREGROUND and POWERLEVEL9K_DIR_ANCHOR_BOLD.

There is one difference compared to what Prezto does. Directory names are truncated to the shortest unique prefix rather than always to a single character. This makes truncation reversible: you can copy-paste the directory from prompt and TAB-expand it to the original.

For details about directory truncation in powerlevel10k, see https://github.com/romkatv/powerlevel10k#current-directory-that-just-works and read comments in ~/.p10k.zsh under [ dir: current directory ] banner.

Let me know if this is sufficient for your needs. If not, there are other options.

All 3 comments

Please try the following:

  1. Open ~/.p10k.zsh.
  2. Search for anchor_files and set the value of this parameter to ().
local anchor_files=()
  1. Search for POWERLEVEL9K_DIR_MAX_LENGTH and set the value of this parameter to 1.
typeset -g POWERLEVEL9K_DIR_MAX_LENGTH=1
  1. Save changes.
  2. Restart Zsh.

You can also optionally adjust colors. Look for POWERLEVEL9K_DIR_FOREGROUND, POWERLEVEL9K_DIR_SHORTENED_FOREGROUND, POWERLEVEL9K_DIR_ANCHOR_FOREGROUND and POWERLEVEL9K_DIR_ANCHOR_BOLD.

There is one difference compared to what Prezto does. Directory names are truncated to the shortest unique prefix rather than always to a single character. This makes truncation reversible: you can copy-paste the directory from prompt and TAB-expand it to the original.

For details about directory truncation in powerlevel10k, see https://github.com/romkatv/powerlevel10k#current-directory-that-just-works and read comments in ~/.p10k.zsh under [ dir: current directory ] banner.

Let me know if this is sufficient for your needs. If not, there are other options.

Yeah, it's not exactly the same but I guess "shorter" enough. Thanks!

Glad it's worked out for you.

If you are feeling adventurous, try restoring anchor_files to its original value. This way important directories such as roots of Git repositories won't be shortened.

  • Full: ~/work/project/src/backend
  • Completely shortened: ~/w/p/s/backend
  • With important directories not shortened: ~/w/project/s/backend
Was this page helpful?
0 / 5 - 0 ratings