      # function to generate list of completions from .apparixrc
      function _apparix_aliases ()
      {   cur=$2
          dir=$3
          COMPREPLY=()
          if [ "$1" == "$3" ]
          then
              COMPREPLY=( $( cat $HOME/.apparix{rc,expand} | \
                             grep "j,.*$cur.*," | cut -f2 -d, ) )
          else
              dir=`apparix -favour lro $dir 2>/dev/null` || return 0
              eval_compreply="COMPREPLY=( $(
                  cd "$dir"
                  \ls -d *$cur* | while read r
                  do
                      [[ -d "$r" ]] &&
                      [[ $r == *$cur* ]] &&
                          echo \"${r// /\\ }\"
                  done
                  ) )"
              eval $eval_compreply
          fi
          return 0
      }
      # command to register the above to expand when the 'to' command's args are
      # being expanded
      complete -F _apparix_aliases to
