'Need to display previous folder in the modified zshrc file, how do I do it?
This is my current configuration of the zshrc file for showing git branch which results in showing the current folder with the git branch (if present)
function parse_git_branch() {
git branch 2> /dev/null | sed -n -e 's/^\* \(.*\)/[\1]/p'
}
setopt PROMPT_SUBST
export PROMPT='%F{cyan}%.%f %F{blue}$(parse_git_branch)%f%F{normal}$%f '
Instead of . in the PROMPT, I tried ~ but then it will show the complete path of the directory, but I wish to only see the current directory and the previous one. How should I proceed?
export PROMPT='%F{cyan}%.%f %F{blue}$(parse_git_branch)%f%F{normal}$%f '
If I am currently in Documents/gitRepos/project1, terminal would show me project1 [master], what I want is gitRepos/project1 [master]
Solution 1:[1]
Zsh has this built in:
%c %. %CTrailing component of the current working directory. An integer may folow the
'%'to get more than one component. Unless'%C'is used, tilde contraction is performed first. These are deprecated as%cand%Care equivalent to%1~and%1/., respectively, while explicit positive integers have the same effect as for the latter two sequences.
So, simply replace %. with %2. or %2~ or whatever you prefer here.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | torek |
