Bash Completion on OpenSolaris

Bash Completion Initial Configuration

Bash completion has finally arrived on OpenSolaris - as of snv_126!

Unfortunately, for some reason it's not enabled by default - but it's not that difficult to enable it, the simple steps are:
  1. Create /etc/bash/bash_completion:

    # cp /etc/bash/bash_completion.example /etc/bash/bash_completion

  2. Edit ${HOME}/.bashrc and add lines like:

    if [ -f /etc/bash/bash_completion ]; then
        . /etc/bash/bash_completion
    fi
That's about it - if you then either source /etc/bash/bash_completion in your current shell, or start a new terminal, you should then be able to do things like:
  • ssh <TAB><TAB>
    <list of known hosts>
  • su - <TAB><TAB>
    <list of users in /etc/password>
  • evince <TAB><TAB>
    <list of dirs, ps and pdf files in current directory>
and so on...

Adding other completions

Of course these are only the default completions, it's possible to add many more! The simplest way to do this is to place a file in /etc/bash/bash_configuration.d and these files will be sourced automatically if you added the lines mentioned above to your .bashrc file.

A useful one for those of us using Mercurial is the version you get in /usr/demo/mercurial - this can be copied in and hey presto you have completion of the mercurial commands:
  • # cp /usr/demo/mercurial/bash_completion /etc/bash/bash_completion.d/
So if you again source /etc/bash/bash_completion, you will then pick this up and get:
  • $ hg <TAB><TAB>
    active       bisect       cddlchk      copyright    hdrchk       init         mv           permchk      reparent     showconfig   update
    add          blame        checkout     cp           heads        jstyle       nits         pull         resolve      st           verify
    ...

It's possible to add more completion for various commands, for example you could create one for zfs, zpool, pkg, etc. - the possibilities are to numerous to mention, but here are a few I found:

Enjoy :)
Comments:

Post a Comment:
Comments are closed for this entry.
About

dar

Search

Archives
« April 2014
MonTueWedThuFriSatSun
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
    
       
Today
News

No bookmarks in folder

Blogroll

No bookmarks in folder