Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Change cd hook in _ssh_hosts
- X-seq: zsh-workers 54254
- From: lemen@xxxxxxxxx
- To: zsh-workers@xxxxxxx
- Subject: Change cd hook in _ssh_hosts
- Date: Thu, 26 Mar 2026 14:59:15 +0100
- Archived-at: <https://zsh.org/workers/54254>
- Autocrypt: addr=lemen@xxxxxxxxx; keydata= xjMEZ9XKORYJKwYBBAHaRw8BAQdA6Uwmo1Ur1JDbcu3cC90MPGGfCsixCnTagWmwrsE3wKbN F2xlbWVuIDxsZW1lbkBsZW1lbi54eXo+wpkEExYKAEEWIQQ73FgZ0auIp1utZeJ1oxorzCn6 tQUCZ9XKOQIbAwUJBaOagAULCQgHAgIiAgYVCgkICwIEFgIDAQIeBwIXgAAKCRB1oxorzCn6 tWMSAP4iifM4RzBh2fA2Jwnt1HZxE8yExvyddGYaya6ze5W8AwD+MuFr+n05D9UsoPkw3XFX Uu3FQ9uI0u82bFIvyM6sJgfOOARn1co5EgorBgEEAZdVAQUBAQdAGy2QgSU1MGgtKnn2RPRE y+xP1r+9BjDqErZEkwQnq14DAQgHwn4EGBYKACYWIQQ73FgZ0auIp1utZeJ1oxorzCn6tQUC Z9XKOQIbDAUJBaOagAAKCRB1oxorzCn6tfnDAP4qWss59ti05oVUtsR+cLG/Rg2km2TVhsf3 p+ye0nDgMgEAtQXYUt14EWkXbJaEjPmJBQMCStwyTKTV9hMTLlK3YAY=
- List-id: <zsh-workers.zsh.org>
Hello,
I was running into a problem when hooking the cd call in zsh.
I'm using the following snippet for remembering the last cd'ed to
directory to spawn a new terminal in the last directory:
# last working directory
# zsh -is lwd
lwd_file="$XDG_CACHE_HOME/zsh/lwd"
function chpwd() { pwd > "$lwd_file" }
function lwd() { cd "$(<$lwd_file)" }
autoload -U add-zsh-hook
add-zsh-hook chpwd chpwd
[ ${1-x} = "lwd" ] && lwd
This works fine but has a strange behavior when a shell completion is
invoked.
When a shell completion uses cd, the hook is also executed and and sets
the directory accordingly.
The completion in question is the _ssh_hosts completion found at
Completion/Unix/Type/_ssh_hosts
As this cds into $HOME/.ssh every time an Include is parsed the lwd is
set to it.
Would it be possible to change this to not use cd and cat the files
directly:
39c39
< lines[idx]=( "${(@f)$(cd $HOME/.ssh; cat ${(Z.C.)~line}
2>/dev/null)}" ) ;;
---
> lines[idx]=( "${(@f)$(cat $HOME/.ssh/${(Z.C.)~line}
2>/dev/null)}" ) ;;
I have tested it and it seems to work.
With regards,
lemen
Messages sorted by:
Reverse Date,
Date,
Thread,
Author