You are not logged in.

#1 2026-07-18 11:03:00

Lone_Wolf
Administrator
From: Netherlands, Europe
Registered: 2005-10-04
Posts: 15,228

[Solved] How to show longer part of $PWD in bash prompt ?

The bash prompt has w and W to show the current directory in the prompt.
Unfortunately I have multiple folders with the same name but in different locationsfor different purposes..

example :

~/Documents/Games/MM7
~/Downloads/Games/MM7

~/pkgbuilds/llvm-minimal-git
~/git-repos/AUR/llvm-minimal-git

Showing the full path in the prompt is overkill and likely way to long but showing the path relative to $HOME for folders under $HOME would be very handy .


So instead of MM7 it should be Documents/Games/MM7 or Downloads/Games/MM7

Last edited by Lone_Wolf (Yesterday 12:05:31)


Disliking systemd intensely, but not satisfied with alternatives so focusing on taming systemd.

clean chroot building not flexible enough ?
Try clean chroot manager by graysky

Offline

#2 2026-07-18 11:48:12

5hridhyan
Member
From: A fake and corrupt democracy
Registered: 2025-12-25
Posts: 952
Website

Re: [Solved] How to show longer part of $PWD in bash prompt ?

I did this by using a custom function

meow() {
    case "$1" in
        "$HOME")
            printf '~'
            ;;
        "$HOME"/*)
            printf '~/%s' "${1#$HOME/}"
            ;;
        *)
            printf '%s' "$1"
            ;;
    esac
}

and used `PS1='$(meow "$PWD") \$ ' ` in prompt
...

Edit
or 

export PROMPT_DIRTRIM=3
PS1='\u@\h \w \$ '

like if your goal is to always show the full path under your home directory (for ex. always showing ~/Documents/Games/MM7) then PROMPT_DIRTRIM is not the right tool...

Edit2:
changed the function to accept the path as an argument instead of relying on the global $PWD variable

Last edited by 5hridhyan (2026-07-18 12:40:48)

Offline

#3 2026-07-18 12:06:28

Lone_Wolf
Administrator
From: Netherlands, Europe
Registered: 2005-10-04
Posts: 15,228

Re: [Solved] How to show longer part of $PWD in bash prompt ?

Yup, PROMPT_DIRTRIM=3 comes close .

Will test that and the function you posted in the next days to verify which works best for me.


Disliking systemd intensely, but not satisfied with alternatives so focusing on taming systemd.

clean chroot building not flexible enough ?
Try clean chroot manager by graysky

Offline

#4 2026-07-18 16:00:05

seth
Member
From: Won't reply 2 private help req
Registered: 2012-09-03
Posts: 76,896

Re: [Solved] How to show longer part of $PWD in bash prompt ?

Have you ever tried just the basic https://archlinux.org/packages/extra/an … sh-config/ ?
https://archlinux.org/packages/extra/an … hlighting/ (you'll have to source that) is also fun.

(the grml config auto-elides the prompt to 40 chars max)

Offline

#5 2026-07-19 11:35:26

Lone_Wolf
Administrator
From: Netherlands, Europe
Registered: 2005-10-04
Posts: 15,228

Re: [Solved] How to show longer part of $PWD in bash prompt ?

Nope, only times I used zsh was during installing from the iso (atleast I think the iso uses grml zsh) .

Sofar the whole path from ~ to folder is TMI as ~/pkgbuilds/llvm-minimal-git/src/llvm-project starts 4 levels deep and has atleast 4 nested levels itself .
PROMPT_DIRTRIM=2 is not enough info, 3 is usable.

[panoramix@mjoelnir ~/.../oolite/KicheEmergencyShields/Scripts] (master)$ 

The total size of that is ~ 70 chars, how would grml handle that ?

How does grml handle longer prompts then 40 chars ?


Disliking systemd intensely, but not satisfied with alternatives so focusing on taming systemd.

clean chroot building not flexible enough ?
Try clean chroot manager by graysky

Offline

#6 2026-07-19 11:45:52

seth
Member
From: Won't reply 2 private help req
Registered: 2012-09-03
Posts: 76,896

Re: [Solved] How to show longer part of $PWD in bash prompt ?

It left-elides the path, not the rest of the promt - or rather the token '%40<..<%~%<< ' does that in zsh - the grml config provides an abstraction layer to the config.
You can run  "prompt -h grml" to get an oversight how to customize that.

It's a bit like a less annoying OMZ … and maybe a way to covert you to use ze zuperior zhell smile

Offline

#7 Yesterday 12:05:09

Lone_Wolf
Administrator
From: Netherlands, Europe
Registered: 2005-10-04
Posts: 15,228

Re: [Solved] How to show longer part of $PWD in bash prompt ?

Looked at zsh with grml-zsh-config . The completion is better then that used in bash.

Things I'd have to change :

  • Seeing (git)-(master) is too much info as I don't use other VCS then git

  • The truncation of longer paths is annoying for me as I very much prefer path display stopping at a / .

  • ls sort order is case sensitive which I hate for directory output .
    (under bash ls displays clang.ini before CMake.txt)

The question comes down to : Is the extra power the zsh shell gives worth the effort needed to tweak it to my wishes ?
For bash I have done very little tweaking.

I will keep zsh+grml installed for now.

As for the topic of this thread :
PROMPT_DIRTRIM=3 works well, marking as [Solved].


Disliking systemd intensely, but not satisfied with alternatives so focusing on taming systemd.

clean chroot building not flexible enough ?
Try clean chroot manager by graysky

Offline

#8 Yesterday 12:54:32

seth
Member
From: Won't reply 2 private help req
Registered: 2012-09-03
Posts: 76,896

Re: [Solved] How to show longer part of $PWD in bash prompt ?

zstyle ':vcs_info:*'              actionformats "%F{red}%b%f:%F{green}%a%f "  "zsh: %r"
zstyle ':vcs_info:*'              formats       "%F{red}%b%f "  "zsh: %r"

# limit prompt to trailing three segments
zstyle ':prompt:grml:*:items:path' token '%3~'

ls sorts according to LC_COLLATE which is likely set to some C (or unset) in zsh but set to some utf8 locale bash?

Offline

#9 Today 09:35:10

Lone_Wolf
Administrator
From: Netherlands, Europe
Registered: 2005-10-04
Posts: 15,228

Re: [Solved] How to show longer part of $PWD in bash prompt ?

LC_COLLATE is unset on my system.

$ alias | grep ls=
ls='command ls --color=auto -v'

Looks like that comes from /etc/zsh/.zshrc which is owned by grml-zsh-config.
It's the -v that caused it, apparently it does affect more then number sort.

Copying alias ls='ls --color=auto --group-directories-first' for my ~/.bashrc solved the issue

grml-zsh-config comes with a lot of aliases that I don't need (my ~/.bashrc only has 4 aliases)

I just noticed zsh (probably ZLE?) has different ideas then me about what the home-key on keyboard should do.

Not removing it yet, but my feeling sofar is that zsh/grml authors and I have different ideas about how things should work.


Disliking systemd intensely, but not satisfied with alternatives so focusing on taming systemd.

clean chroot building not flexible enough ?
Try clean chroot manager by graysky

Offline

Board footer

Powered by FluxBB