searbe

    • Edit
    • Delete
    • Tags
    • Autopost

    Add Custom Tab Auto-Completion to your Bash Scripts

    I like shoving little methods in my bash ~/.profile ... to complete the laziness I added tab auto-completion.

    Create a method that generates the tab options then use "complete" to assign it to your custom method:

    # a method which returns all my project dirs via COMPREPLY - note the use of 
    # compgen and ls /clients within backticks, that's where you want to do
    # your own thang
    function _clientdirs()
     {
            local curw
            COMPREPLY=()
            curw=${COMP_WORDS[COMP_CWORD]}
            COMPREPLY=($(compgen -W '`ls /clients`' -- $curw))
            return 0
    }
    
    # my 'q' shortcut method to run a queue script in one of my projects
     function q()
    {
            if [ $# -eq 1 ]
            then
                    php /clients/$1/core/tools/run_queue.php local
            else
                    php core/tools/run_queue.php local
            fi
    }
    
     # assigning the complete method to my method
    complete -F _clientdirs -o dirnames q

    • 22 December 2010
    • Views
    • Permalink
    • Favorited 0 Times

    Comments 0 Comments

    Leave a Comment

  • Craig Bendell's Posterous

    PHP developer living in Worthing, UK working for D3R. Starting Android / Java development for fun.

  • About Craig Bendell

    PHP developer living in Worthing, UK working for D3R. Starting Android / Java development for fun.

  • Subscribe

    Subscribe to this posterous
    Unsubscribe
    Subscribe via RSS
    You're a contributor here (Edit)
    This is your Space (Edit)
    Follow by email »
    Get the latest updates in your email box automatically.
    Follow on Twitter
  • Follow Me