Menu

ALTERNATIVE_COMPLETION_TYPE in plain Bash?

Ace_NoOne
2009-07-30
2013-04-09
  • Ace_NoOne

    Ace_NoOne - 2009-07-30

    (This is sort of an off-topic question, I hope that's okay.)

    I love the ALTERNATIVE_COMPLETION_TYPE option.
    Is this special to bashrun, or is there a simple way to get similar behavior in regular Bash - i.e. switching from cycling options (menu-complete) to listing them (complete) if there are more than n options?
    (I'd need this for some remote servers.)

     
    • hbekel

      hbekel - 2009-07-30

      This is a bashrun-specific feature. Note that the type of completion is switched if the number of lines of the terminal exceeds the COMPLETION_THRESHOLD, so switching to ALTERNATIVE_COMPLETION_TYPE is rather side-effect of changing the terminal size. Afaik there's no way of switching completion types "on the fly", based on how many options a current completion attempt yields (this is what your question seems to imply).

      For bash, how about using something like this:

      bind '"\t": menu-complete'
      bind '"\ew": complete'

      So that tab uses menu-complete, and Alt+w (or whatever you like) uses complete.

      If you want to switch the type that the tab key uses, you'll have to use something like this:

      COMPLETION_TYPE=complete
      switch_type () {
        if [[ "$COMPLETION_TYPE" == "complete" ]]; then
           bind '"\t": menu-complete'
           COMPLETION_TYPE="menu-complete"
        else
           bind '"\t": complete'
           COMPLETION_TYPE="complete"
         fi
      }
      bind -x '"\ew": switch_type'

      So you can actively switch completion types by hitting Alt+w.

      Hope this helps,
      Henning

       
      • Ace_NoOne

        Ace_NoOne - 2009-07-30

        Thanks a lot for the quick and informative response!

        I'll give that script a try, see whether it fits my workflow.

        Thanks again!

         

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.