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

'...' in path names?



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@xxxxxx
Reply-To: dominik.vogt@xxxxxx



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