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

How can I show the last (1 or 2) path instead of full directory? #77

Closed
dsoegijono opened this issue Jun 6, 2018 · 3 comments
Closed

Comments

@dsoegijono
Copy link

dsoegijono commented Jun 6, 2018

Instead of ~/User/Documents/folder1/folder2, I'd like to be able to just show /folder2 or maybe /folder1/folder2 so it doesn't take too much space. Is there a way for me to do this?

I'm looking at this section:

prompt_dir() {
  prompt_segment blue black '%~'
}

but I don't really understand what it means.

@dsoegijono dsoegijono changed the title How can I show the last (1 or 2) path? How can I show the last (1 or 2) path instead of full directory? Jun 6, 2018
@apjanke
Copy link
Collaborator

apjanke commented Jun 6, 2018

See the "Shell State" section of the Prompt Expansion page in the Zsh reference manual.

You can stick a number between the % and ~ to limit the number of trailing path elements that are displayed. So, you could do:

  prompt_segment blue black '%2~'

to get the last two elements of the current directory.

See also the prompt-pwd function in Prezto. It does more advanced prompt "compaction", abbreviating all but the last path element with a single letter, so you still have more context about where you are.

@dsoegijono
Copy link
Author

Thanks for the explanation @apjanke!

@ahmed-hdeawy
Copy link

step 1. open your .zshrc file by vim .zshrc

step 2. go to the end of your file.

Paste this code:

prompt_dir() {
  prompt_segment blue $CURRENT_FG '%c'
}

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

No branches or pull requests

3 participants