Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(zsh): display named directories #5749

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

LunarLambda
Copy link

Pass Zsh's %~ prompt specifier to --logical-path in PROMPT/RPROMPT

Description

Display the current directory using zsh's %~ specifier, which shortens paths if they refer to a named directory.

Motivation and Context

Named directories are a great feature of zsh and most common zsh prompts use the %~ specifier to display the current directory in shortened form when possible.

Screenshots (if appropriate):

Before (With directory.truncate_to_repo = false for emphasis)
image
After (named directory set with hash -d nvim=~/cfg/nvim)
image

How Has This Been Tested?

  • I have tested using MacOS
  • I have tested using Linux
  • I have tested using Windows

Checklist:

  • I have updated the documentation accordingly.
  • I have updated the tests accordingly.

Unsure what testing/documentation this needs, since it's just passing an existing flag to starship prompt. I would be happy to make any necessary adjustments.

However, I did notice that passing --logical-path overrides directory.truncate_to_repo completely, I'm not sure if that's intentional/desired.

@LunarLambda
Copy link
Author

LunarLambda commented Feb 5, 2024

Alternatively, here's a hack-ish way to do it with starship init zsh:

source <(starship init zsh | sed "/^R\?PROMPT=/s/)'$/ --logical-path \"\${(%):-%~}\"&/")

Displays the current directory using zsh's `%~` specifier, which shortens paths if they refer to a named directory:
https://man.archlinux.org/man/zshexpn.1#Static_named_directories
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant