[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: bash 2.05 programmable completion question

From: Aaron Crane
Subject: Re: bash 2.05 programmable completion question
Date: 13 Apr 2001 23:48:53 +0100
User-agent: Gnus/5.0803 (Gnus v5.8.3) XEmacs/21.1 (Capitol Reef)

In article <address@hidden>,
address@hidden (Michael F Gordon) writes:
> function ps_complete {
>   COMPREPLY=(`compgen -G "${COMP_WORDS[$COMP_CWORD]}*.@(ps|PS|eps|EPS)"`);
> }
> complete -o filenames -A directory -F ps_complete gs
> This works, but I need a separate function for each suffix I want to
> complete on - img_complete for *.@(gif|jpeg|tiff), fig_complete for *.fig
> etc.  Is there a way of doing this that doesn't require large numbers
> of functions?

There's a trick I like that does still require large numbers of functions,
but you don't have to write them all.  Using the same "complete" command as
you have:

  function pattern_completion {
    [ $# -ge 2 ] || {
      echo "Usage: pattern_completion PATTERN PROGRAM..."
      return 1
    local pat="$1" firstprog="$2"
    eval function "${firstprog}_complete" "{" \
      "COMPREPLY=(\$(compgen -G \"\${COMP_WORDS[\$COMP_CWORD]}$pat\"))" ";" \
    complete -o filenames -A directory -F "${firstprog}_complete" "$@"

  pattern_completion "*.@(ps|PS|eps|EPS)" gs gv ghostview

Aaron Crane

reply via email to

[Prev in Thread] Current Thread [Next in Thread]