zsh-workers
 help / color / mirror / code / Atom feed
From: "Bart Schaefer" <schaefer@brasslantern.com>
To: zsh-workers@math.gatech.edu
Subject: Re: bug 3.1.5 symlinks & cd
Date: Wed, 18 Nov 1998 11:25:59 -0800	[thread overview]
Message-ID: <981118112559.ZM12272@candle.brasslantern.com> (raw)
In-Reply-To: <199811180909.KAA14049@beta.informatik.hu-berlin.de>

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


  parent reply	other threads:[~1998-11-18 19:28 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1998-11-18  9:09 Sven Wischnowsky
1998-11-18 13:06 ` Peter Stephenson
1998-11-18 19:25 ` Bart Schaefer [this message]
1998-11-18 22:41 ` Phil Pennock
  -- strict thread matches above, loose matches on Subject: below --
1998-11-18 13:41 Sven Wischnowsky
1998-11-16  9:28 Sven Wischnowsky
1998-11-13 21:19 Phil Pennock
1998-11-14  5:48 ` Bart Schaefer
1998-11-15  3:01   ` Phil Pennock

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=981118112559.ZM12272@candle.brasslantern.com \
    --to=schaefer@brasslantern.com \
    --cc=zsh-workers@math.gatech.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).