5

Suppose I do the following in zsh

cd ~
cd dir1
cd dir2
cd dir3
evince foo.pdf

zsh writes exactly the same in its history file.

Now my question is whether it is possible to have

cd ~
cd ~/dir1
cd ~/dir1/dir2
cd ~/dir1/dir2/dir3
evince ~/dir1/dir2/dir3/foo.pdf

in zsh history instead. I.e. that zsh remembers only full paths.

4

1 Answer 1

1

Not in a general way, because the shell has no way to know whether a given argument is a relative path or not. Of course it could use some heuristics (similar to the ones used for completion), but this might be too error-prone.

2
  • zsh history could log the full path before the command runs. The end user can then figure out what maps to a relative directory and what doesn't.
    – Alok
    Sep 21, 2016 at 22:12
  • You could try arguments in a $(realpath $arg) subshell in a zshaddhistory-hook and if it fails you know its not a path. Add some initial regex validation and you're pretty close imo.
    – dza
    Nov 12, 2022 at 12:08

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .