|
Softpanorama |
May the source be with you, but remember the KISS principle ;-)
|
| 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:
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. |
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 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) possible-completions (M-?) insert-completions (M-*) possible-completions. menu-complete () 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 () delete-char). If at the end of the line, behaves
identically to possible-completions. This command is unbound by
default. complete-filename (M-/) possible-filename-completions (C-x /) complete-username (M-~) possible-username-completions (C-x ~) complete-variable (M-$) possible-variable-completions (C-x $) complete-hostname (M-@) possible-hostname-completions (C-x @) complete-command (M-!) possible-command-completions (C-x !) dynamic-complete-history (M-TAB) complete-into-braces (M-{) 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:
If there is no file whose name begins with the word, the shell will beep and nothing further will happen.
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.
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.
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.
[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.
|
Please visit Heiner Steven SHELLdorado: the best shell scripting site on the Internet |
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).
- chicken-setup <tab> completes for *.egg files.
- chicken-setup -<tab> completes for options.
options. # chicken-setup command line completion for bash. # # version 0.2 -- 2007.01.13 -- vo minh thu # - chicken-setupcompletes 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
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.
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:
- Ensure you have a ~/.bash_completion file that includes all the scripts in a personal Bash completion script library. I have a directory ~/bash_completion.d in which I put the various scripts – copying directly the way that Bash organizes scripts in /etc. My ~/.bash_completion file then contains a copy of the relevant bit of the system script:
# -*- 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
- Append the contents of the file to your ~/.bash_completion file.
- Put the file in /etc/bash_completion.d with all the other system-wide scripts.
The last has the advantage of working for all users of the machine but does require super-user privileges. I use the first (obviously).
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 DocumentsIf 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 Dyou 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.bashrcfile. 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.
Basic Bash Completion will work in any bash shell. It allows for completion of:
- File Names
- Directory Names
- Executable Names
- User Names (when they are prefixed with a ~)
- Host Names (when they are prefixed with a @)
- 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.
- completes on signal names
- completes on network interfaces
- expands tildes in pathnames
- completes on process IDs
- completes on process group IDs
- completes on user IDs
- completes on group IDs
- ifconfig(8) and iwconfig(8) helper function
- bash alias completion
- bash export completion
- bash shell function completion
- bash complete completion
- service completion
- chown(1) completion
- chgrp(1) completion
- umount(8) completion
- mount(8) completion
- Linux rmmod(8) completion
- Linux insmod(8), modprobe(8) and modinfo(8) completion
- man(1) completion
- renice(8) completion
- kill(1) completion
- Linux and FreeBSD killall(1) completion
- GNU find(1) completion
- Linux ifconfig(8) completion
- Linux iwconfig(8) completion
- RedHat & Debian GNU/Linux if{up,down} completion
- Linux ipsec(8) completion (for FreeS/WAN)
- Postfix completion
- cvs(1) completion
- rpm completion
- apt-get(8) completion
- chsh(1) completion
- chkconfig(8) completion
- user@host completion
- host completion based on ssh's known_hosts
- ssh(1) completion
- scp(1) completion
- rsync(1) completion
- Linux route(8) completion
- GNU make(1) completion
- GNU tar(1) completion
- jar(1) completion
- Linux iptables(8) completion
- tcpdump(8) completion
- autorpm(8) completion
- ant(1) completion
- mysqladmin(1) completion
- gzip(1) completion
- bzip2(1) completion
- openssl(1) completion
- screen(1) completion
- lftp(1) bookmark completion
- ncftp(1) bookmark completion
- gdb(1) completion
- Postgresql completion
- psql(1) completion
- createdb(1) completion
- dropdb(1) completion
- gcc(1) completion
- Linux cardctl(8) completion
- Debian dpkg(8) completion
- Debian GNU dpkg-reconfigure(8) completion
- Debian Linux dselect(8) completion
- Java completion
- PINE address-book completion
- mutt completion
- Debian reportbug(1) completion
- Debian querybts(1) completion
- update-alternatives completion
- Python completion
- Perl completion
- rcs(1) completion
- lilo(8) completion
- links completion
- FreeBSD package management tool completion
- FreeBSD kernel module commands
- FreeBSD portupgrade completion
- FreeBSD portinstall completion
- Slackware Linux removepkg completion
- look(1) completion
- ypcat(1) and ypmatch(1) completion
- mplayer(1) completion
- KDE dcop completion
- wvdial(1) completion
- gpg(1) completion
- iconv(1) completion
- dict(1) completion
- cdrecord(1) completion
- mkisofs(8) completion
- mc(1) completion
- yum(8) completion
- yum-arch(8) completion
- ImageMagick completion
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 xvncviewerThis 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 ExampleAs a basic example we'll first look at adding some simple completions to the binary foo. This hypothetical command takes three arguments:
- --help
- Shows the help options for foo, and exits.
- --version
- Shows the version of the foo command, and exits.
- --verbose
- Runs foo with extra verbosity
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 fooTo test it you can now source the file:
skx@lappy:~$ . /etc/bash_completion.d/foo skx@lappy:~$ foo --[TAB] --help --verbose --versionIf 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!
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 ascompleteand 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 iand 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 useEsc-!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 downbefore 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 #fiUncomment 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
completecommand 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" geditwould 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, butgedit inv[Tab], which should complete to invoice.txt, no longer works.
completeassociations 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.
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 onNow bash tab-completion won't worry about case in filenames. Thus 'cd sit[tab]' would complete to 'cd Sites/'
> 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.comfreshmeat.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:13Currently, 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:11I 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.
|
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
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-2007 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: April 01, 2008