Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Change cd hook in _ssh_hosts



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