bug-bash
[Top][All Lists]
Advanced

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

complete options not working with read -e


From: Bill Duncan, 416-697-9315
Subject: complete options not working with read -e
Date: Fri, 17 Dec 2010 12:24:51 -0500 (EST)

I'm writing a script with a command line interpreter and I can most things
working (eg. history etc.) except for one thing.  The filename completion
works well for some of the commands, but I'd like to use other completion
options for others.  Works well from the "real" command line, but I can't
get it to work properly in my "read -e, eval" loop..

For example, in trying to set up arguments for debug, verbose, trace etc..
In the example below I indicate where I tab with [TAB] and I have editing-mode
set to vi.


marion:~/tmp$ ls
./  ../  file1  file2  file3  file4  file5  file6  file7  file8  file9
marion:~/tmp$ complete -W 'on off true false' debug trace errexit verbose
marion:~/tmp$ debug [TAB]
false  off    on     true   
marion:~/tmp$ read -e -p 'FUBAR->' fubar
FUBAR->debug [TAB]file[TAB]
file1  file2  file3  file4  file5  file6  file7  file8  file9  
FUBAR->



Is there any way to modify the behaviour of "read -e" so that it does
what I want (and not filenames)?

I did do one neat trick for most of the commands and use fake filenames
to give me the expansions I need.  While this works for most, it doesn't
work for all of the commands I want..  This is at the top of my read/eval
loop where I cd into a directory with fake files set up specifically to
give me the arguments I need for most of the commands.



  if [ -t 0 -a -t 1 ] ; then
    interactivemode=true
    dobanner
    [ -r  "$historyfile" ] && history -r "$historyfile"
    touch "$historyfile"    # make sure that we can save it when done
    realpwd="$PWD"
    cd "${tabcomplete}" > /dev/null && {
      echo "$SEARCH_HOST $SEARCH_TYPE" | tr '|' '\012' | xargs touch ;
      cd - > /dev/null
    }
    complete -W 'clean'        history
    complete -W 'on off'       debug trace errexit verbose
    complete -W 'view clear'   results
  fi

  while : ; do
    $interactive && cd "$tabcomplete" > /dev/null    # get ready for tab 
complete
    $debug && prompt="[$PROGNAME debug]->" || prompt="$PROMPT"
    if read -e -p "$prompt" action hostgroup; then
      if [ -n "$action" ] ; then
        history -s $action "$hostgroup"
        $interactive && cd "$realpwd" > /dev/null    # restore the real pwd 
where we are
        if doactions $action $hostgroup ; then
          : continue
        else
          echo "usage:  action host-or-group"
        fi
      else
        : continue
      fi
    else
      break
    fi
  done


Any suggestions?

Thanks!!
-- 
Bill Duncan,             | http://www.servermetrix.com/
address@hidden | - linux/unix/network security
+1 416 697-9315          | - web and application hosting



reply via email to

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