zsh-users
 help / color / mirror / code / Atom feed
* '...' in path names?
@ 2000-06-13 15:54 Dominik Vogt
  2000-06-15  0:25 ` Bart Schaefer
  0 siblings, 1 reply; 2+ messages in thread
From: Dominik Vogt @ 2000-06-13 15:54 UTC (permalink / raw)
  To: zsh-users

I really like to abbreviate something like '../../..' with '....'
(you get the idea).  (The last time I tried to get it working was
zsh-3.0.5).  I didn't get any farther than this:

  alias '...'='cd ../..'
  alias '....'='cd ../../..'
  alias '.....'='cd ../../../..'
  ...

which works for '...' in the command position, but not in 'cd ...'.
Or altenratively I can get it working in positional parameters:

  alias -g '...'='../..'
  alias -g '....'='../../..'
  alias -g '.....'='../../../..'
  ...

Then I can use 'cd ...'.  Any ideas how to improve this situation?
It would be cool if it were possible to expand strings of dots
in every path without having to .  I guess most of the stuff in the
list below is not possible yet, so you can consider individual item
to be enhancement requests.

  1) '.....................' becomes 'cd ../../../<and so on>'.
     It should be possible to configure this without dozens of alias
     lines
  2) 'cd .....' becomes 'cd ../../../..' (also without many aliases)
     Already possible if you don't mind the many aliases you need.
     You can't have (1) and (2) at the same time
  3) '.../bin/zsh' becomes '../../bin/zsh'
     could be implemented as an enhancement to global aliases
  4) '/usr/local/bin/.../bin' becomes '/usr/local/bin/../../bin'
     could be implemented as an enhancement to global aliases too

Furthermore it would be nice if you didn't have to type a slash
before and after the dots in a path (on a german keyboard you
have to press shift-7 to get a slash which is a bit unwiedly).

  5) '..bin' becomed '../bin' and 'bin..man' becomes 'bin/../man'
     of course you'd need some form of escaping for file names that
     contain '..'.

All of this could be done with new options of the alias command
and some changes in alias expansion I think:

  -p: ('p' stands for 'parameter alias'; e.g. 'alias -p foo=bar')
      Defines an alias that is only expanded in positional parameters,
      but not if it occurs in command position.

  -R: ('R' stands for 'REGEXP'; e.g. alias '(.*)\.\.\.(.*)'='\1../..\2')
      Allow (extended) regular expression syntax in alias definitions

With these two, all of the above could be implemented:


     # recursively translates ... to ../.. anywhere in a string
     alias -g -R '(.*)\.\.\.(.*)'='\1../..\2'

     # these two add a / before and after the .. if necessary
     alias -g -R '(.*[^/.])..'='\1/..'
     alias -g -R '..(.*[^/.])'='../\1'

     # and finally prepend 'cd'
     alias -R '\.\.(.*)'='cd ..\1'

Please reply to me directly, I'm not subscribed to the list.

Bye

Dominik ^_^

--
Dominik Vogt, dominik.vogt@gmx.de
Reply-To: dominik.vogt@gmx.de


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: '...' in path names?
  2000-06-13 15:54 '...' in path names? Dominik Vogt
@ 2000-06-15  0:25 ` Bart Schaefer
  0 siblings, 0 replies; 2+ messages in thread
From: Bart Schaefer @ 2000-06-15  0:25 UTC (permalink / raw)
  To: Dominik Vogt; +Cc: zsh-users

On Tue, 13 Jun 2000, Dominik Vogt wrote:

> I really like to abbreviate something like '../../..' with '....'
> (you get the idea).  (The last time I tried to get it working was
> zsh-3.0.5).  I didn't get any farther than this:
> 
>   alias '...'='cd ../..'
>   alias '....'='cd ../../..'
>   alias '.....'='cd ../../../..'
>   ...

I posted a partial solution for this in

    http://www.zsh.org/cgi-bin/mla/redirect?USERNUMBER=3022

> which works for '...' in the command position, but not in 'cd ...'.

Same for what I previously posted.

> Any ideas how to improve this situation?
> It would be cool if it were possible to expand strings of dots
> in every path without having to .

Without having to what?

Would you be happy enough doing this with completion, i.e. you type TAB
to expand the dots and then hit return?

------------------------------------------------------------------------
#autoload
# Put this in a file named _expand_dots in your $FPATH, then
# add _expand_dots to the front of the "completer" style, e.g:
#   zstyle ':completion:*' completer _expand_dots _complete
# Requires 3.1.9.

local word sub
local patl='(#b)([^\/])..' patr='(#b)..([^\/])'
local repl='/..' repr='../'

# This first part borrowed from _expand

[[ _matcher_num -gt 1 ]] && return 1

if [[ "$funcstack[2]" = _prefix ]]; then
  word="$IPREFIX$PREFIX$SUFFIX"
else
  word="$IPREFIX$PREFIX$SUFFIX$ISUFFIX"
fi

# The real stuff

setopt localoptions extendedglob

sub="$word"

while [[ "$sub" = *...* ]]; do
  sub="${sub/.../../..}"       # Looks odd because the 3rd / isn't magic
done
sub="${sub//$~patl/$match[1]$repl}"
sub="${sub//$~patr/$repr$match[1]}"

[[ "$sub" != "$word" ]] && compadd -QU -S '' "$sub"
------------------------------------------------------------------------

If you prefer not to have it expand the dots unless there's a real file or
directory to match, you can change that last line to something like

[[ "$sub" != "$word" && -r "$sub" ]] && compadd -QU -S '' "$sub"

but that may cause undesired effects e.g. for completion along $cdpath.


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2000-06-15  0:25 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-06-13 15:54 '...' in path names? Dominik Vogt
2000-06-15  0:25 ` Bart Schaefer

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).