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

Re: which completion function are used for aliases?



> if [[ $aliases[$words[1]] = *" --dir "* ]]; then
>    dir=${aliases[$words[1]]##*--dir }
> fi

This only works if there is no other option after "--dir /foo/bla".

I'm doing it like this now, but it sub-optimal I'm afraid  :-)

------------
if [[ -z $dir ]]; then
  # try to read directory from the alias
  # e.g. alias gigaset2='gigaset --dir /movies/gigaset/PVR --nowarnings'
  if [[ -n $aliases[$words[1]] ]]; then
    aliasstring=aliases[$words[1]]
    aliaswords=${(z)aliasstring}
    local dir=${aliaswords[(r)--dir=*]##--dir=}
    if [[ -z $dir ]]; then
      integer dirind=${aliaswords[(i)--dir]}
      if (( dirind )); then
        dir=$aliaswords[dirind+1]
      fi
    fi
  else
    # default directory
    dir="/data/movies/gigaset/PVR/"
  fi
fi
------------

Especially this should be easier, right?
  aliasstring=aliases[$words[1]]
  aliaswords=${(z)aliasstring}


Thanks,
 Andy.

-- 
 Plug-and-Play is really nice, unfortunately it only works 50% of the time.
 To be specific the "Plug" almost always works.            --unknown source



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