zsh-users
 help / color / mirror / code / Atom feed
* possibly useful zsh_directory_name implementation
@ 2011-03-11  1:06 Mikael Magnusson
  2011-03-11  1:15 ` Mikael Magnusson
                   ` (2 more replies)
  0 siblings, 3 replies; 11+ messages in thread
From: Mikael Magnusson @ 2011-03-11  1:06 UTC (permalink / raw)
  To: Zsh Users

function zsh_directory_name () {
  case $1 in
    n)
      case $2 in
        /*)
          reply=( /${(j:/:)${(s:/:)PWD}[1,(er)${2[2,-1]}]} )
        ;;
        .*)
          reply=( (../)##${2[2,-1]}([1]) )
        ;;
      esac
    ;;
    c)
      local types vals description
      types=( '.:children of parent directories' '/:pwd segment' )
      case $PREFIX in
        '')
          vals=( $types )
          _describe 'dynamic dir type' vals -V dynamic-dirs -o -S ''
        ;;
        .*)
          vals=( (../)##*~(../)##$PWD:t(/:t) )
        ;|
        /*)
          vals=( "${(@)${(s:/:)PWD}[1,-2]}" )
        ;|
        *)
          _wanted -V dynamic-dirs expl
${${types[(r)$PREFIX[1]*]}[3,-1]} compadd -P $PREFIX[1] -qQS / -d vals
${(q)^vals}\]
      esac
    ;;
  esac
}

With this, /home/mikachu/some/directory/somewhere% cd ~[/some], will
take you to /home/mikachu/some/, and cd ~[.foo] will take you to foo/
in whatever parent directory has a subdirectory foo, for example it
could be /home/foo/.

-- 
Mikael Magnusson

footnotes:
reply=( $PWD[1,(r)$2] ) of course is the more obvious solution, but it
doesn't work on directories called "[foo] something".
the fiddling with (q)^\] and -Q is because i want only / to be a
removable suffix, not the ].


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

end of thread, other threads:[~2011-03-11 18:24 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-03-11  1:06 possibly useful zsh_directory_name implementation Mikael Magnusson
2011-03-11  1:15 ` Mikael Magnusson
2011-03-11 10:44 ` Peter Stephenson
2011-03-11 12:06   ` Mikael Magnusson
2011-03-11 12:17     ` Peter Stephenson
2011-03-11 12:32       ` Mikael Magnusson
2011-03-11 16:25   ` Peter Stephenson
2011-03-11 16:33     ` Peter Stephenson
2011-03-11 17:09       ` Mikael Magnusson
2011-03-11 18:24         ` Peter Stephenson
2011-03-11 17:44 ` Jérémie Roquet

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