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

Re: bug 3.1.5 symlinks & cd



On Nov 18, 10:09am, Sven Wischnowsky wrote:
} Subject: Re: bug 3.1.5 symlinks & cd
}
} > [...] different parts of the shell are taking differing approaches to
} > symbolic-links pointing to directories.  Completion ignores the symbolic
} > aspect of PWD, such that a ../ always uses the underlying 'true' layout,
} > whilst cd handles the symbolic links.  This is a conflict that's
} > entirely due to two parts of zsh doing things very differently.
} 
} A (partial) solution is to use a shell function, like this:
} 
}   compctl -K cdcomp -S/ -q cd pushd
} 
}   cdcomp() {
}         local d r
}         if [[ "$1" == */* ]]
}         then
}                 d="${1%%/*}"
}                 r="${1#*/}"
}                 cd "$d" >& /dev/null
}                 reply=( ${r}*${2}(N-/) )
}                 reply=( $d/$reply )

Should be:        reply=( $d/$^reply )

}                 cd - >& /dev/null
}         else
}                 reply=( ${1}*${2}(N-/) )
}         fi
}   }

That's an unpleasant solution because it silently changes the value of
$OLDPWD, messing up the use of ~- in filename expansions.  One possible
workaround:

	cdcomp() {
	    local d r
	    if [[ "$1" == */* ]]
	    then
		    d="${1%%/*}"
		    r="${1#*/}"
		    reply=( "${(@f)$(
				cd "$d" >& /dev/null
				print -l ${r}*${2}(N-/)
			    )}" )
		    reply=( $d/$^reply )
	    else
		    reply=( ${1}*${2}(N-/) )
	    fi
	}

"${(@f)$(print -l ...)}" in case some of the directory names have spaces.

On Nov 18, 2:06pm, Peter Stephenson wrote:
} Presumably it will one day become possible to replace the (../)# with
} a truncated version of $PWD, then reapply -/ using the -W option to
} compctl to generate the completions you want.  Then the script
} solution ought to become pretty painless.

Hmm.

    compctl -/ -x 'S[../]' -S/ -q -K cdcomp -- cd
    cdcomp() {
        local h t p d			# No, not Apache :-)
	h="${(M)1##*../}"		# Extract leading (../)#
	t="${1##*../}"			# Delete leading (../)#
	p="${h:gs@../@/*@}"		# Convert $h to a pattern
	eval 'd="${PWD%'"$p"'}"'	# Remove matching tail of $PWD
	reply=( $d/$t*$2(N-/) )		# Generate list of directories
	eval 'reply=( ${reply'":s@$d/$t@$1@"'} )'	# Fix up prefixes
    }

The last line fails on directories with "@" in their names, and the first
two fail on things like ../foo/bar/../baz/.  Oh, well.

-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com



Messages sorted by: Reverse Date, Date, Thread, Author