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

Re: Why doesn't tab expand .



On Oct 11,  9:13am, zzapper wrote:
}
} zzapper <david@xxxxxxxxxx> wrote in news:Xns9857CE0FC8AA4zzappergmailcom@
} 80.91.229.5:
} 
} > cp /tmp/fred.txt .<Tab>
} expanding to:-
} > cp /tmp/fred.txt fred.txt
} 
} Which I could then arbitrarily choose to modify.
} 
} Someone has pointed out that . means current directory, so I guess it
} would be imoral

Well, not immoral, just ambiguous.  You have to assert via zstyles or
compdef that "." should not be considered a valid completion by itself,
and then assert by an entry in the matcher-list zstyle that it's OK to
complete both sides around a dot without having any other clues.

Although ... it looks like specifically what you want is not for "."
to complete, but for "cp" completion to insert the tail of the source
path argument as the default target argument?

  _mycp () {
    if [[ $CURRENT -ge $#words && $words[CURRENT-1] = */* ]]
    then
      compadd $words[CURRENT-1]:t
    fi
    _cp
  }
  compdef _mycp cp

This could be refined in several ways, e.g., you might prefer

  if [[ $CURRENT -ge $#words && $words[CURRENT-1] = */* &&
        $words[CURRENT] != */* ]]



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