You are not logged in.

#1 2021-11-30 22:56:14

LIParadise
Member
Registered: 2020-08-03
Posts: 9

[solved] zsh prompt expansion breaks after cd

My ${PS1} is as following (installed ohmyzsh, theme gentoo)

`%(!.%B%F{red}.%B%F{green}%n@)%m %F{blue}%(!.%1~.%~) ${vcs_info_msg_0_}%F{blue}%(!.#.$)%k%b%f`

When login (open gui terminal, tty, ssh, etc) the prompt correctly displays something like this:

liparadise@arch ~ $

Problem is, after doing any "cd", the abbreviation "%~" fails to work, and the prompt becomes like the following:

liparadise@arch /home/liparadise $

Interestingly, if I do "cd ~liparadise", then "%~" somehow works (?) again, and the prompt becomes

liparadise@arch ~liparadise $

Unfortunately, "cd ~" don't change prompt style, i.e. remain fully expanded or remain the "~user_name" style.

Problem remains either change $PS1 to plain '%~' or change to other themes in ohmyzsh.

My WSL2 debian machine have exactly the same .zshrc and ohmyzsh config, but "%~" works as expected, i.e. always abbreviating the ${HOME} portion of path to "~". Both machines are using latest version of ohmyzsh.

# pacman -Q --info zsh # arch machine on which ps1 seems problematic
Version         : 5.8-1
# apt-show-versions zsh # WSL2 debian machine
zsh:amd64/bullseye 5.8-6+b2 uptodate

Last edited by LIParadise (2021-12-01 08:10:09)

Offline

#2 2021-11-30 23:15:12

Slithery
Administrator
From: Norfolk, UK
Registered: 2013-12-01
Posts: 5,776

Re: [solved] zsh prompt expansion breaks after cd

LIParadise wrote:

...installed ohmyzsh

That's most likely your problem. It's well known to break systems and there's nothing it does that can't be achieved by writing your own configs.


No, it didn't "fix" anything. It just shifted the brokeness one space to the right. - jasonwryan
Closing -- for deletion; Banning -- for muppetry. - jasonwryan

aur - dotfiles

Offline

#3 2021-11-30 23:21:49

LIParadise
Member
Registered: 2020-08-03
Posts: 9

Re: [solved] zsh prompt expansion breaks after cd

Slithery wrote:
LIParadise wrote:

...installed ohmyzsh

That's most likely your problem. It's well known to break systems and there's nothing it does that can't be achieved by writing your own configs.

Valid point, so I tried disabling zshrc and hence ohmyzsh and all zsh plugins (probably should do it in the first place) just now, and the problem persists, even with $PS1 being simply "%~'.

Last edited by LIParadise (2021-11-30 23:24:52)

Offline

#4 2021-12-01 05:35:10

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

Re: [solved] zsh prompt expansion breaks after cd

"~liparadise" isn't "~"
Does something maybe unset $HOME ?

Edit: or your $UID?
Edit #2:

after doing any "cd"

It *is* "cd", not anything that triggers a new prompt?

type cd

- do the contents of "/home/liparadise" change?

Last edited by seth (2021-12-01 05:37:23)

Offline

#5 2021-12-01 06:40:20

LIParadise
Member
Registered: 2020-08-03
Posts: 9

Re: [solved] zsh prompt expansion breaks after cd

seth wrote:

"~liparadise" isn't "~"
Does something maybe unset $HOME ?

Edit: or your $UID?
Edit #2:

after doing any "cd"

It *is* "cd", not anything that triggers a new prompt?

type cd

- do the contents of "/home/liparadise" change?

Pardon but I don't really understand you.

Just to be clear:
I now only have "extra/zsh" installed; ohmyzsh is previously installed via git clone and setting its location in my zshrc, however ohmyzsh should not matter now since I removed zshrc from my home directory ("/home/liparadise/.zshrc")

Here's an experiment around $UID and $HOME (ssh), but again since unfortunately I don't quite get what you mean, so this might not be what you want:

Last login: Wed Dec  1 14:34:12 2021 from 140.112.238.126
arch% export PS1='%~: '
~: echo ${HOME} ${UID}
/home/liparadise/ 1000
~: cd
/home/liparadise: cd ~liparadise
~liparadise: cd
~liparadise: cd /home/liparadise
~liparadise: echo ${HOME} ${UID}
/home/liparadise/ 1000
~liparadise: type cd
cd is a shell builtin

Another experiment:

Last login: Wed Dec  1 14:34:21 2021 from 140.112.238.98
arch% export PS1='%~: '
~: unset HOME
/home/liparadise/: cd ~liparadise
~liparadise: cd /home/liparadise
~liparadise: cd ~
~liparadise:

Offline

#6 2021-12-01 08:09:38

LIParadise
Member
Registered: 2020-08-03
Posts: 9

Re: [solved] zsh prompt expansion breaks after cd

Update:
Now I have an opportunity to access another arch box, and I discover that I can't reproduce the bug mentioned. Since they use exactly the same "extra/zsh" package version, it's probably indeed some config wrong on my original machine.

I'll just mark the title solved for now, since it should just be that some of my config is messed up, rather than there be problem in "extra/zsh" in arch repo. I'll update my solution when I figure out why it behaves weird.

Offline

#7 2021-12-01 11:42:16

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

Re: [solved] zsh prompt expansion breaks after cd

It's not technically "solved"  - the idea behind my first questions was that the comparism between the $HOME for $UID and the $PWD fails.
If you'd "useradd -m dummy" and then "cd ~dummy" you'd end up in /home/dummy and zsh shows "~dummy"

id
stat ~
realpath ~
grep liparadise /etc/passwd # despite the name this won't expose your password

Offline

#8 2021-12-01 14:44:59

LIParadise
Member
Registered: 2020-08-03
Posts: 9

Re: [solved] zsh prompt expansion breaks after cd

seth wrote:

It's not technically "solved"  - the idea behind my first questions was that the comparism between the $HOME for $UID and the $PWD fails.
If you'd "useradd -m dummy" and then "cd ~dummy" you'd end up in /home/dummy and zsh shows "~dummy"

id
stat ~
realpath ~
grep liparadise /etc/passwd # despite the name this won't expose your password

Thanks for the hints, now problem is indeed solved!

Turns out my /etc/passwd is faulty somehow (possibly because a typo when I created a user for myself), the home directory part is "/home/liparadise/", causing it to mismatch $PWD, which doesn't have trailing "/", e.g. for my home directory $PWD shows "/home/liparadise". This can be seen even without peeking /etc/passwd via echo $HOME: on the faulty machine it's "/home/liparadise/" and on correctly configured machine it's "/home/liparadise", without the trailing "/".

I just blatantly directly edited "/etc/passwd", and now zsh behaves as expected. (I guess a safer way should be log out all my sessions and then do "usermod -d /home/liparadise liparadise" instead of recklessly manually modifying the file)

Thanks again since I've been pulling my hairs out for hours because all the zsh related config were basically the same across the board, never thought that the fault is due to faulty $HOME and that to solve the problem I should look into how $HOME is set in the first place.

Offline

Board footer

Powered by FluxBB