How can I make my shell prompt show the working directory relative to an arbitrary directory?
1
vote
2
answers
91
views
Suppose I do a lot of work under the directory
/home/user/documents/foo
, so the Bash shell prompt could appear as follows:
user@hostname: ~/documents/foo/bar/baz $
My terminal is quite narrow, and the ~/documents/foo
is not a helpful use of space, since I already know I am there.
I would therefore like my shell prompt to show the working directory *relative to* /home/user/documents/foo
:
user@hostname: bar/baz $
The prompt is defined by the PS1
environment variable, and I can find ways of editing this to include the path relative to my user's home directory, or to include only the basename, but I can't seem to get a path relative to a different directory.
Asked by pythonmegapixel
(13 rep)
Mar 4, 2025, 09:14 AM
Last activity: Mar 4, 2025, 03:21 PM
Last activity: Mar 4, 2025, 03:21 PM