Softpanorama
(slightly skeptical) Open Source Software Educational Society

May the source be with you, but remember the KISS principle ;-)

Google   


Command completion

News

Bash

Recommended  Links

Advanced navigation Command history reuse
ksh completion Bash completion modes bash programmable completion package Unix shell history Etc

One of the most powerful (and typically underused) features of  many shells (ksh, bash, zsh) is filename completion facility, introduced to Unix in C shell, and originated in DEC TOPS-20 operating system.

The idea behind filename completion is that when you need to type a filename, you should not have to type more than is necessary to identify the file unambiguously. This is an excellent idea although it is limited by absence of visual feedback (compare with OFM filename completion). Still in moderate dozes it can save you some typing.

There is also a possibility to increase efficiency of programming completion by considering the type of arguments (which can be deducted from the command and its options) that particular command accepts. For example if you have type cd command  you are interesting in the list of directories not any other type of files.

Command completion is different is BASH and ksh93.  In ksh93 it means two things:

  1. The ability to complete the path/filename from the first few letters > typed Yes, ksh supports both command and filename completion.
  2. The ability to use the arguments of previous commands (in the history)

Bash has more elaborate completion system. The most primitive completion is when instead of typing in the arguments/options following a command, the user presses TAB TAB and the shell automatically inserts (or gives you the option of inserting) new text based on which bit of the full command you're editing.

Note: A highly recommended shell site is SHELLdorado by Heiner Steven.
This is a really excellent site with the good coding practice section,
some interesting example scripts and tips and tricks

For example, say you want to extract files from a UNIX tape archive (.tar or .tar.gz file) of the Linux kernel source tree, which you just downloaded to the /tmp directory. You type:

tar -zxvf l[press TAB TAB]
tar -zxvf linux-2.0.38.tar.gz  

If you had chosen -xvf instead, it would complete on files ending in .tar. Say there was also a file called allmail.tar in tmp:

tar -xvf [press TAB]
tar -xvf allmail.tar  
  

Using completion in this way, you can use the completion system as a way of browsing around directory structures. Note that this applies equally outside compressed archives, if you were intending to view or edit a file but didn't know exactly where it was, for example.

Bash completion modes

bash has offered many forms of completion since its inception, including path, file, user, host and variable completion.

Programmable completion indefinitely extends the type of completion you can perform.

Bash supports several completion modes (via readline). Only few first have practical importance and return on investment for other modes might in general be negative:

complete (TAB)
Attempt to perform completion on the text before point. The actual completion performed is application-specific. Bash attempts completion treating the text as a variable (if the text begins with `$'), username (if the text begins with `~'), hostname (if the text begins with `@'), or command (including aliases and functions) in turn. If none of these produces a match, filename completion is attempted.
possible-completions (M-?)
List the possible completions of the text before point.
insert-completions (M-*)
Insert all completions of the text before point that would have been generated by possible-completions.
menu-complete ()
Similar to complete, but replaces the word to be completed with a single match from the list of possible completions. Repeated execution of menu-complete steps through the list of possible completions, inserting each match in turn. At the end of the list of completions, the bell is rung (subject to the setting of bell-style) and the original text is restored. An argument of n moves n positions forward in the list of matches; a negative argument may be used to move backward through the list. This command is intended to be bound to TAB, but is unbound by default.
delete-char-or-list ()
Deletes the character under the cursor if not at the beginning or end of the line (like delete-char). If at the end of the line, behaves identically to possible-completions. This command is unbound by default.
complete-filename (M-/)
Attempt filename completion on the text before point.
possible-filename-completions (C-x /)
List the possible completions of the text before point, treating it as a filename.
complete-username (M-~)
Attempt completion on the text before point, treating it as a username.
possible-username-completions (C-x ~)
List the possible completions of the text before point, treating it as a username.
complete-variable (M-$)
Attempt completion on the text before point, treating it as a shell variable.
possible-variable-completions (C-x $)
List the possible completions of the text before point, treating it as a shell variable.
complete-hostname (M-@)
Attempt completion on the text before point, treating it as a hostname.
possible-hostname-completions (C-x @)
List the possible completions of the text before point, treating it as a hostname.
complete-command (M-!)
Attempt completion on the text before point, treating it as a command name. Command completion attempts to match the text against aliases, reserved words, shell functions, shell builtins, and finally executable filenames, in that order.
possible-command-completions (C-x !)
List the possible completions of the text before point, treating it as a command name.
dynamic-complete-history (M-TAB)
Attempt completion on the text before point, comparing the text against lines from the history list for possible completion matches.
complete-into-braces (M-{)
Perform filename completion and insert the list of possible completions enclosed within braces so the list is available to the shell

Korn shell command completion

Backslash (\) is the command that tells the Korn shell to do filename completion in vi-mode. If you type in a word, type ESC to enter control mode, and then type \, one of four things will happen:

  1. If there is no file whose name begins with the word, the shell will beep and nothing further will happen.

  2. If there is exactly one way to complete the filename and the file is a regular file, the shell will type the rest of the filename, followed by a space in case you want to type in more command arguments.

  3. If there is exactly one way to complete the filename and the file is a directory, the shell will complete the filename, followed by a slash.

  4. If there is more than one way to complete the filename, the shell will complete out to the longest common prefix among the available choices.

A related command is *.  It behaves similarly to ESC \, but if there is more than one completion possibility (number four in the list above), it lists all of them and allows you to type further. Thus, it resembles the * shell wildcard character.

The command = does the same kind of filename expansion as the * shell wildcard, but in a different way. Instead of expanding the filenames onto the command line, it prints them in a numbered list with one filename on each line. Then it gives you your shell prompt back and retypes whatever was on your command line before you typed =. You can select the filename you which and put it on the command line using the middle button of the mouse.

LUG@GT Using the Korn Shell

[esc] [=]

Display list of pathnames that result from expanding the word under the cursor.

[esc] [esc]

Append characters to the word under the cursor to complete the pathname of an existing file.

[esc] [*]

Replace words under the cursor with the list of pathnames that result from expanding the word.

2.7. Command completion -- vi mode

[=]

Display list of pathnames that result from expanding the word under the cursor.

[\]

Append characters to the word under the cursor to complete the pathname of an existing file.

[*]

Replace words under the cursor with the list of pathnames that result from expanding the word.

=

Pathname listing. Causes the current word on the command line to be expanded to a list of pathnames. For example,
                    $ls m<ESC>=
                    1) myfile
                    2) myhome
                    $

\

Pathname completion. Causes the current word on the command line to be expanded to a filename or directory. If it is a directory then a / is added. For example,
                    $ echo my<Esc>\
  would expand to myfile.

@letter

Searches your list of aliases for one named _letter. If an alias is defined, its value is inserted as keystrokes. For example,
                    alias _Q='LBi"^V<Esc>Ea"^V<Esc>'
  now if you are editing a command and type <Esc>@Q the current word you are on would be quoted.

#

Insert a # (comment marker) at the beginning of a command.

Another interesting feature is incremental searching, usually bound to C-r (Control R). This is a sort of cross between the other two: press it, and start typing a word which exists somewhere in the history. By the time you've typed enough of it to uniquely identify it, you've plucked the whole of that line out of the history. This is available in bash (C-r by default), tcsh (not bound by default) and zsh (C-r by default).

Completion is when you can press a key (often TAB) and the shell automatically cleverly completes the rest of the word you are typing, based on the context you are typing it in. bash offers basic filename, hostname and command completion. Only tcsh and zsh offer fully programmable context-sensitive completion of many different types with zsh functionality clearly superior.

Another nice examples of the zsh extended completion system are: the ytalk, finger and ssh commands, which complete on usernames and hostnames (automatically appending an @ symbol in between); the find command, which has different completions for each option (e.g. completes file/directory names for the initial parameter(s), users for -user, groups for -group ... zsh is even able to treat the arguments to -exec as a whole new command line!). The rpm, cvs, and gcc completions are even more fiendish.

You certainly get "hardcore hacker" points for fully grokking the internals of the zsh completion system. However, you can rejoice in the knowledge that you won't ever need to in order to enjoy this sophisticated time-saver, since the latest development versions come with a complete, `out of the box' pre-configured completions system.



Old News ;-)

Please visit  Heiner Steven SHELLdorado: the best shell scripting site on the Internet

bash completion

The Debian bash package features support for command line completion through the file /etc/bash_completion. This page of the chicken wiki provides a file to add completion for the chicken tools in bash. Currently, only chicken-setup is supported. Hopefully csi and csc will follow.
Copy the following code in a file named chicken in /etc/bash_completion.d. Alternatively, source it after /etc/bash_completion (which is sourced from ~/.bashrc or elsewhere).
options.
# chicken-setup command line completion for bash.
#
# version 0.2 -- 2007.01.13 -- vo minh thu 
#  - chicken-setup  completes for *.egg files.
# version 0.1 -- 2007.01.13 -- vo minh thu

_chicken_setup()
{
    local cur prev frst opts
    COMPREPLY=()
    cur=${COMP_WORDS[COMP_CWORD]}
    prev=${COMP_WORDS[COMP_CWORD-1]}
    frst=${COMP_WORDS[1]}

    opts='-help -version -repository -program-path -host \
          -uninstall -list -run -script -eval -verbose \
          -keep -csc-option -dont-ask -no-install -docindex \
          -check -test -ls -fetch-tree -tree -svn -revision \
          -local -destdir'

    paroptions=${opts}

    # the following options take zero or one argument
    case "${prev}" in
    '-repository' | '-program-path' | '-local' | '-destdir' )
        COMPREPLY=( $(compgen -A directory ${cur}) )
        return 0;;
    '-host' )
        COMPREPLY=( $(compgen -A hostname ${cur}) )
        return 0;;
    '-run' | '-script' | '-tree' )
        COMPREPLY=( $(compgen -A file ${cur}) )
        return 0;;
    '-uninstall' | '-ls' )
        local exts=$( chicken-setup -list | awk '{ print $1 }' )
        COMPREPLY=( $(compgen -W "${exts}" -- ${cur}) )
        return 0;;
    esac

    # the following options take zero or more arguments
    case "${frst}" in
    '-list' | '-test' )
        local exts=$( chicken-setup -list | awk '{ print $1 }' )
        COMPREPLY=( $(compgen -W "${exts}" -- ${cur}) )
        return 0;;
    esac

    case ${cur} in
    -* )
        COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
        return 0;;
    * )
        COMPREPLY=($(compgen -f -X "egg" -- ${cur}))
    esac

}
[ "$have" ] && complete

An introduction to bash completion part 1

Sometimes this luxury drives me crazy...

If I have a tar file not named with suffix .tar and I type "tar xvf filenamebeginning<tab>", what will happen?

Same effect for many other extension driven suggestions or completions...

It is very usefull to know, that if I type "\tar" instead of "tar", command completion will not happen at all. Even if "tar was aliased, "\tar" will override this IIRC...

But now for something (not really) completely different...

Another nice feature for small functions or big screens is the way functions are "completed". Try

 "function _mc<tab><tab>".

You can edit the function with bash's commandline editor and even rename the function name.

Similar for aliases. Assume having aliased "ll" to somethig obvious then "alias ll=<tab>" gives the alias definition als editable line...

====

If I have a tar file not named with suffix .tar and I type "tar xvf filenamebeginning", what will happen?
You will try Shift-TAB (or ESC-TAB or Alt-/)  instead of TAB to revert to standard filename expansion.

 

A Bash Completion Script for Rant

Rant is a build tool that uses Ruby as the underlying scripting language. It is a competitor to SCons (which uses Python as the programming language) but perhaps more especially to Rake, which like Rant is build on Ruby. There has been a lot written about the relationship of Rake and Rant elsewhere and I am not yet in a position to comment on this as I am only just beginning to try Rant having done some work with SCons and Rake.

The problem is that whilst Rake comes with a Bash completion script, Rant does not.

The Solution

The solution is totally clear: create a Bash completion script for Rant. Given the similarity between Rake and Rant, and having done equivalents for SCons and Gant, it is easy to take the Rake script and edit it a bit. So I came up with a script (that you can download by clicking here) that seems to do the job. It almost certainly has error and/or bugs but for the moment it ‘works for me’.

To use this script you can do one of:

            # -*- mode:shell-script -*-

            for file in bash_completion.d/*
            do
                    [[ ${file##*/} != @(*~|*.bak|*.swp|\#*\#|*.dpkg*|.rpm*) ]] &&
                                [ \( -f $file -o -h $file \) -a -r $file ] &&
                                . $file
            done
          

The last has the advantage of working for all users of the machine but does require super-user privileges. I use the first (obviously).

Turn on Bash Smart Completion

Ubuntu Blog

The Bash shell has this sweet feature where you can use the TAB key to auto-complete certain things. For example, when I am in my home directory, the following command:

$cd Do[TAB-key]

will automatically yield:

$cd Documents

If you are an absolute novice, like I was, not so long ago, discovering tab completion in the terminal can make you go “Wow!”. Wait till you hear the rest now 

Though you can use the TAB key to complete the names of files and directories, by default the completion is pretty “dumb”. If you have already typed $cd D you would expect that the tab key would cause only the directory names to be completed, but if I try it on my machine, the tab completion tool uses filenames too.

Now, don’t despair! There is now a smart bash tab completion trick you can use. Smart completion even complete the arguments to commands!!

To enable smart completion, edit your /etc/bash.bashrc file. Uncomment the following lines, by removing the # in the beginning of the lines:

#if [ -f /etc/bash_completion ]; then
# . /etc/bash_completion
#fi
 

Now you can use tab completion to power your way through commands.

You can even extend bash smart completion to your own favourite commands by using /etc/bash_completion, the “complete” utility and /etc/bash_completion.d . Explaining the nitty-gritty is beyond me. I refer you to the Debian Administration gurus for more information regarding smarter bash completion.

BASH Help - A Bash Tutorial

Basic Bash Completion will work in any bash shell. It allows for completion of:

  1. File Names
  2. Directory Names
  3. Executable Names
  4. User Names (when they are prefixed with a ~)
  5. Host Names (when they are prefixed with a @)
  6. Variable Names (when they are prefixed with a $)

This is done simply by pressing the tab key after enough of the word you are trying to complete has been typed in. If when hitting tab the word is not completed there are probably multiple possibilities for the completion. Press tab again and it will list the possibilities. Sometimes on my machine I have to hit it a third time.

Extended Programmable Bash Completion is a program that you can install to complete much more than the names of the things listed above. With extended bash completion you can, for example, complete the name of a computer you are trying to connect to with ssh or scp. It achieves this by looking through the known_hosts file and using the hosts listed there for the completion. This is greatly customizable and the package and more information can be found here.

Configuration of Programmable Bash Completion is done in /etc/bash_completion. Here is a list of completions that are in my bash_completion file by default.

An introduction to bash completion part 2

Previously we showed how to add basic completion to commands, using facilities which were already provided by the bash completion routines. In this second part we'll demonstrate how to add completely new custom completion to commands.

In part one we looked at adding hostname completion to arbitrary commands by executing:

complete -F _known_hosts xvncviewer

This uses the complete command to tell bash that the function _known_hosts should be used to handle the completion of arguments to the xvncviewer.

If we wish to add custom completion to a command we will instead write our own function, and bind that to the command.

A Basic Example

As a basic example we'll first look at adding some simple completions to the binary foo. This hypothetical command takes three arguments:

To handle these arguments we'll create a new file /etc/bash_completion.d/foo. This file will be automatically sourced (or loaded) when the bash completion code is loaded.

Inside that file save the following text:

_foo() 
{
    local cur prev opts
    COMPREPLY=()
    cur="${COMP_WORDS[COMP_CWORD]}"
    prev="${COMP_WORDS[COMP_CWORD-1]}"
    opts="--help --verbose --version"

    if [[ ${cur} == -* ]] ; then
        COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
        return 0
    fi
}
complete -F _foo foo

To test it you can now source the file:

skx@lappy:~$ . /etc/bash_completion.d/foo
skx@lappy:~$ foo --[TAB]
--help     --verbose  --version  

If you experiment you'll see that it successfully completes the arguments as expected. Type "foo --h[TAB]" and the --help argument is completed. Press [TAB] a few times and you'll see all the options. (In this case it doesn't actually matter if you don't have a binary called foo installed upon your system.)

So now that we have something working we should look at how it actually works!

 

[Dec 11, 2007] CLI Magic Bash complete By Shashank Sharma

May 08, 2006 | Linux.com
 
The auto complete feature of the Bourne Again SHell makes bash one of the most loved and newbie-friendly Linux shells. Just by pressing the Tab key you can complete commands and filenames. Press the Tab key twice and all files in the directory get displayed. But you can do more with autocomplete -- such as associating file types with applications, and automatically designating whether you're looking for directories, text, or MP3 files. With simple commands such as complete and the use of Escape sequences, you can save time and have fun on the command line.
 
You can use the dollar sign ($), tilde (~), and at (@) characters along with the Tab key to get quick results in autocomplete.

For instance, if you want to switch to the testing subdirectory of your home directory, you can either type cd /ho[Tab]/tes[Tab] to get there, or use the tilde -- cd ~tes[Tab]. If the partial text -- that is, the portion before you press Tab -- begins with a dollar sign, bash looks for a matching environment variable. The tilde tells bash to look for a matching user name, and the at-sign tells it to look for a matching hostname.

Escaping is good

The Tab key can complete the names of commands, files, directories, users, and hosts. Sometimes, it is overkill to use the Tab key. If you know that you are looking for a file, or only user names, then use the Escape key instead for completion, as it limits bash's completion field.

You can use several Escape key combinations to tell bash what you are looking for. Invoke Escape key combinations by pressing a key while keeping the Escape key pressed. When looking for a file, you can use the Esc-/ (press / along with Escape) key combination. This will attempt filename completion only. If you have one file and one directory beginning with the letter 'i,' you will have to press the Tab key twice to see all the files:

$ less i <tab><tab>
ideas im articles/

When you type less i and press '/' while keeping the Escape key pressed, bash completes the filename to 'ideas.'

While Control key combinations work no matter how long you keep the Ctrl key pressed before pressing the second key, this is not the case with Escape key sequences. The Esc-/ sequence will print out a slash if you delay in pressing the / key after you press the Escape key.

You can also use Escape along with the previously discussed $, ~, and @ keys. Esc-$, for example, completes only variable names. You can use Esc-! when you wish to complete command names. Of course you need to press the Shift key in order to use any of the "upper order" characters.

Wildcard expansion
The asterisk (*), caret (^), and question mark (?) are all wildcard characters. All *nix shells can perform wildcard expansion. Use the asterisk wildcard if you don't wish to view any hidden files. ls * would display all files and directories in the current directory except for those beginning with a dot (hidden).

If you wish to view only files with five-letter names beginning with a given letter, use the question mark wildcard. ls p???? will display only files with names with five letter files starting with 'p.' You can also use the square brackets for filename completion. ls [a-d]* displays all files and directories that begin with any letter between 'a' and 'd.' The caret wildcard excludes files. mv *[^.php] ../ would move all files to the parent directory, exculding those with .php extension.

Even smarter completion

By default, Tab completion is quite dim-witted. This is because when you have already typed cd down before pressing Tab, you'd expect bash to complete only directory names. But bash goes ahead and displays all possible files and directories that begin with 'down.'

You can, however, convert bash into a brilliant command-reading whiz. As root, edit the /etc/bash.bashrc file. Scroll down to the end of the file till you see the section:

# enable bash completion in interactive shells
#if [ -f /etc/bash_completion ]; then
#    . /etc/bash_completion
#fi

Uncomment this section and voilà, you have given bash powers far beyond your imagination! Not only is bash now smart enough to know when to complete only directory names, it can also complete man pages and even some command arguments.

Don't despair if you don't have root previleges. Just edit the last section of your ~/.bashrc file.

Associating application with file types

The complete command in bash lets you associate file types with certain applications. If after associating a file type to an application you were to write the name of the application and press Tab, only files with associated file types would be displayed.

complete -G "*.txt" gedit would associate .txt files with gedit. The downfall of using complete is that it overwrites bash's regular completion. That is, if you have two files named invoice.txt and ideas.txt, gedit [Tab][Tab] displays both the files, but gedit inv[Tab], which should complete to invoice.txt, no longer works.

complete associations last only for the current bash session. If you exit and open a console, gedit will no longer be associated with .txt files. You need to associate file types to applications each time you start a new console session.

For permanent associations, you need to add the command to one of the bash startup scripts, such as ~/.bashrc. Then, whenever you are at the console, gedit will be associated with .txt files.

Shashank Sharma is studying for a degree in computer science. He specializes in writing about free and open source software for new users.

Shashank Sharma is studying for a degree in computer science. He specializes in writing about free and open source software for new users. He is the co-author of Beginning Fedora, published by Apress.

 

bash Tricks From the Developers of the O'Reilly Network - O'Reilly ONLamp Blog

No more worrying about cases

The best bash tip I can share is very helpful when working on systems that don't allow filenames to differ only in case (like OSX and Windows):
create a file called .inputrc in your home directory and put this line in it:

set completion-ignore-case on

Now bash tab-completion won't worry about case in filenames. Thus 'cd sit[tab]' would complete to 'cd Sites/'

Re: command completion


> I was wondering if anyone knows if there is software (or built in
> functionality) for the korn shell in UWin which allows for the following two
> functions available in the Unix Cshell:
> 
> 1.)the ability to complete the path/filename from the first few letters
> typed
Yes, ksh supports both command and filename completion.  In emacs
mode use, <ESC><ESC> to complete a command or pathname up to the
point of uniqueness.  If the complete the first word on the line,
then this indicates command completion and it will uses functions,
builtins, and path search to complete the argument.  You can use
<ESC>= to get the matching list.
In vi-mode use <ESC> to go to control mode and then \ to
complete or = to list.
U/WIN provides functions emacs_keybind and vi_keybind to allow
the tab key to be used for completion, but there is a bug in
the emacs_keybind function in which a $ is missing in front of the '\E\E".

> 2.)the ability to use the arguments of previous commands (in the history)
In vi-mode you can use _ from control mode to get the last argument
of the previous command, or n_ to get the n-th argument of the
pervious command.  With emacs you can use <ESC>_ or <ESC>.
> 
> 

David Korn
research!dgk
dgk@research.att.com

freshmeat.net Project details for bash programmable completion

Please allow user to revert to standard bash completion at any time (a must-have).
by Stéphane Gourichon - Oct 4th 2004 07:59:13

Currently, the arguably interesting features of  bash_completion actually interfere with some completion
patterns that bash had for years, (for example completing a path stopping at cursor, when the cursor is in the middle
of the line, but there are other cases in previous comments).

Generally, until it can be proven that a change makes the situation better at all times without any (even minor)
downside, the change should be reversible and never imposed.

So, any user should be able to turn it off. The simplest idea is to unset the involved environment variables.

But BASH_COMPLETION and BASH_COMPLETION_DIR
are declared as read-only. Why ?
This prevents a particular user to turn it off... :-(

On a system with many users, there's currently no other choice than to ask the administrator to remove the
package for all users (or make it not activated by default, which is not what we need either).

Is it currently possible for a user to revert to standard bash completion ? If not, please consider changing
something in the package (even something as simple as checking for some ~/.bash_completionrc for a hint should
be fine).

The risk is that, on any big site, new users don't even know what comes from your package or even that it
exists, but people that used normal bash completion completion in ways *you* don't use will dislike the package
(becauses it causes less efficient work) and have it removed for all users.

A last suggestion : use savannah.nongnu.org or sourceforge.net to have real forums. Freshmeat comments
aren't structured enough so that contributors can make a good job of checking if a request was already issued
before. User feedback quality depends on this.

Regards,

--
"J'y gagne, répondit le renard, à cause de la couleur du blé."

[»] Re: Please allow user to revert to standard bash completion at any time (a must-have).
by Ian Macdonald - Oct 8th 2004 17:20:08


> So, any user should be able to turn it

> off. The simplest

> idea is to unset the involved

> environment variables.

>

> But BASH_COMPLETION and

> BASH_COMPLETION_DIR

> are declared as read-only. Why ?

> This prevents a particular user to turn

> it off... :-(

These are set read-only, because it's bad to change them once they've been set. They are used later on and it's important that the value doesn't change. They can be set before the bash_completion script is run, however, and the original value will be honoured.

> On a system with many users, there's

> currently no other

> choice than to ask the administrator to

> remove the

> package for all users (or make it not

> activated by default,

> which is not what we need either).

>

> Is it currently possible for a user to

> revert to standard

> bash completion ?

Yes, just run 'complete -r' and all completions will be removed, leaving just the default. However, I agree that this isn't the most useful way of achieving this, so I will consider the implementation of a better mechanism.


> A last suggestion : use

> savannah.nongnu.org or

> sourceforge.net to have real forums.

> Freshmeat comments

> aren't structured enough so that

> contributors can make a

> good job of checking if a request was

> already issued

> before. User feedback quality depends on

> this.

Well, e-mail works well, too. I agree that this forum isn't very efficient or convenient, so just e-mail me your comments instead. It would be nice to have a real mailing list, though. I'll consider setting one up.
 

[»] Wonderful... but...
by GaelicWizard - Oct 5th 2003 02:14:11

I LOVE bash_completion, but I think that it is growing
just a tad too big... and a little unmanageable.
Spesific gripes:
1) If $UNAME isn't tested explicitly for an OS that
doesn't return xyz then feature abc which worx, is not
completed upon. I'm not sure how this is fixable, its just
a comment. :-)
2) some of the functions and completions seem to be
slightly more complex than neccessary. What I mean is
that I don't see the need to redefine the builtin
completions if the builtin ones work.
3) It seems to be very linux spesific, although almost all
worx on freeBSD it checks vigorously for linux in
$UNAME.

Thanx, keep up the good work!

[»] Re: Automatic change directory
by Ian Macdonald - Apr 18th 2003 18:37:42


> Would it be possible to add the
> automatic change directory feature to
> Bash Completion?
>
> If a directory called /usr/local/lib/foo
> exists and the command line is:
> $ /usr/local/lib/foo <return>
>
> Then the action is to change to that
> directory instead of reporting that
> "/usr/local/lib/foo" is a
> directory.
>
> I've used this feature in other shells.
> Can this be done at the command
> completion level or does it call for a
> more fundamental change in bash
> itself?
>


bash can't really do this, since it has no pre-execution hook for you to tap into with code.
Nevertheless, to my surprise, I managed to botch together the following hack:

trap '{ d=$_; [ -d "$d" ] && cd $d; unset d; }' ERR

This does what you want, but won't stop the attempt to run a directory from displaying an error before changing to the directory.

Recommended Links


In case of broken links please try to use Google search. If you find the page please notify us about new location
Google     

Please visit  Heiner Steven SHELLdorado  the best shell scripting site on the Internet

Bash Reference Manual - Commands For Completion

An introduction to bash completion part 1

An introduction to bash completion part 2

Working more productively with bash 2.x by Ian Macdonald . See below his bash programmable completion package

Bash Reference Manual Command Line Editing

BASHISH - the good stuff.

Advanced Bash-Scripting HOWTO - A guide to shell scripting, using Bash

Ian Macdonalds bash programmable completion package

freshmeat.net Project details for bash programmable completion project  by Ian Macdonald You generally need bash 2.05a or later to use the package.

Since v2.04, bash has allowed you to intelligently program and extend its standard completion behavior to achieve complex command lines with just a few keystrokes. Imagine typing ssh [Tab] and being able to complete on hosts from your ~/.ssh/known_hosts files. Or typing man 3 str [Tab] and getting a list of all string handling functions in the UNIX manual. mount system: [Tab] would complete on all exported file-systems from the host called system, while make [Tab] would complete on all targets in Makefile. This project was conceived to produce programmable completion routines for the most common Linux/UNIX commands, reducing the amount of typing sysadmins and programmers need to do on a daily basis.



Copyright © 1996-2008 by Dr. Nikolai Bezroukov. www.softpanorama.org was created as a service to the UN Sustainable Development Networking Programme (SDNP) in the author free time. Submit comments This document is an industrial compilation designed and created exclusively for educational use and is placed under the copyright of the Open Content License(OPL). Original materials copyright belong to respective owners. Quotes are made for educational purposes only in compliance with the fair use doctrine.

Standard disclaimer: The statements, views and opinions presented on this web page are those of the author and are not endorsed by, nor do they necessarily reflect, the opinions of the author present and former employers, SDNP or any other organization the author may be associated with. We do not warrant the correctness of the information provided or its fitness for any purpose.

Last modified: November 06, 2008