Tag Info

Hot answers tagged

34

To rebuild the cache of executable commands, use rehash or hash -rf. Make sure you haven't unset the hash_list_all option (it causes even fewer disk accesses but makes the cache update less often). If you don't want to have to type a command, you can tell zsh not to trust its cache when completing by putting the following line in your ~/.zshrc¹: zstyle ...


23

You could make use of the builtin compgen: compgen: compgen [-abcdefgjksuv] [-o option] [-A action] [-G globpat] [-W wordlist] [-F function] [-C command] [-X filterpat] [-P prefix] [-S suffix] [word] Display possible completions depending on the options. Intended to be used from within a shell function generating possible completions. If the ...


18

There aren't that many bash completion tutorials around, but this one is pretty good: Introduction to Bash Completion Part 1 is for general knowledge Part 2 covers creating scripts in /etc/bash_completion.d/


17

Pressing Ctrl+R will open the reverse history search. Now start typing your command, this will give the first match. By pressing Ctrl+R again (and again) you can cycle through the history. mysq(Ctrl+R) Would give: mysqldump --add-drop-table -e -q -n -C -u Ctrl+R again: mysql -u ben.dauphinee -p


17

This is actually a readline feature called menu-complete . You can bind it to tab (replacing the default complete) by running: bind TAB:menu-complete You probably want to add that to your ~/.bashrc. Alternatively, you could configure it for all readline completions (not just bash) in ~/.inputrc. You may also find bind -p (show current bindings, note that ...


16

For commands use compgen -c: $ compgen -c bas basename base64 bashbug bash basename base64 bashbug This output you can simply pipe through grep.


13

Make sure that you've turned on the fancy autocompletion. On many distributions, this means your ~/.bashrc needs to contain . /etc/bash_completion. You'll need to have passwordless authentication set up, i.e. with a key that's already loaded in ssh-agent. Establishing an SSH connection is slow, so you can considerably speed up completions by establishing a ...


11

Add the following to your .inputrc file, (exact location varies between systems): "\C-i": menu-complete This maps TAB to menu-complete, which auto-completes the first match. Then add (or uncomment) show-all-if-ambiguous, this shows the list of possible completions on the first TAB press. Alternatively, you can set menu-complete per session (without ...


11

It's because the caret is often used to signify the ctrl key having been pressed, or that it's otherwise a control character. The key sequence that you actually typed was this: cp filename.xsl .ctrl+Vbackspace~Enter You were presumably trying to copy the file to your home directory (~). You can repeat this by typing ctrl+Vbackspace. You'll see ^? printed ...


10

There is a great thread about this on the Ubuntu forums. Ole J proposes the following alias completion definition function: function make-completion-wrapper () { local function_name="$2" local arg_count=$(($#-3)) local comp_function_name="$1" shift 2 local function=" function $function_name { ((COMP_CWORD+=$arg_count)) COMP_WORDS=( ...


10

Those are commands. If you start typing on the commandline and hit Tab, it won't expand the subdirectories and files of your location but available commands. Basically, tab completion is context sensitive. If you just start writing and hit Tab, it will complete commands found in your $PATH. If you have already written a command, cd for example, it will ...


9

Depending on the command: Someone may have written a function to generate possible completions of arguments, including options. You'll find functions for some commands in /etc/bash_completion.d/* (or a different location on some systems). These functions are registered with the complete built-in (e.g. complete -F _find find tells bash to call the _find ...


9

Have a look at the file /etc/bash_completion and observe the files from the directory: /etc/bash_completion.d You will find the answer.


9

I have implemented a zsh-autosuggestions plugin. It should integrate nicely with zsh-history-substring-search and zsh-syntax-highlighting which are features ported from fish.


9

I would suggest you work around it and use another type of key binding with readline, such as Shift+TAB. Add the following to your ~/.inputrc: "\e[Z": menu-complete Then issue an exec bash (this should then read the settings in your ~/.inputrc). As a one-off, instead of restarting bash, you can set up the same binding by running bind '"\e[Z": ...


9

You can do this easily by setting rm's completion to an empty wordlist. complete -W "" rm Set it in /root/.bashrc if you only want it to apply to root.


8

To expand on what Gilles said, I have the following in my .bashrc to bind the up/down arrow key to history-search-backward and history-search-forward: # Key bindings, up/down arrow searches through history bind '"\e[A": history-search-backward' bind '"\e[B": history-search-forward' bind '"\eOA": history-search-backward' bind '"\eOB": history-search-forward' ...


8

This has not at all to do with bash, but it depends on the completions programmed in the package bash-completion. From some comments in the file /etc/bash_completion.d/mount: # mount(8) completion. This will pull a list of possible mounts out of # /etc/{,v}fstab, unless the word being completed contains a ':', which # would indicate the specification of an ...


8

Add source /usr/share/git/completion/git-completion.bash to your ~/.bashrc. References Arch Linux Wiki


8

compgen -c # will list all the commands you could run. compgen -a # will list all the aliases you could run. compgen -b # will list all the built-ins you could run. compgen -k # will list all the keywords you could run. compgen -A function # will list all the functions you could run. compgen -A function -abck # will list all the above in one go.


7

In short: source /etc/bash_completion should do the trick (run it in the shell within the SSH session). Long story: in order for bash completion to work, you have to tell bash how to complete each command's arguments. This requires a long sequence of invocations of the bash built-in command complete; therefore, they are usually collected in a separate ...


7

On Linux systems, you can generally find a large number of example scripts under: /etc/bash_completion.d. If you source these scripts, then you will get the autocomplete behavior. I've included an example from that directory. This is the completion script for unrar. _unrar() { local cur COMPREPLY=() _get_comp_words_by_ref cur if [[ ...


7

I don't know if it is in bash (the default shell). It is possible in zsh (a more powerful shell than bash, available on most unices including Ubuntu but often not installed by default). The first time you run zsh, it will offer to create a configuration file (~/.zshrc) for you. The default configuration is a bit barren, for historical compatibility. For ...


7

Bind < to self-insert-command in bash mode and then it will insert only the character. By default it is bound to sh-maybe-here-document when in bash mode and that function does the auto-insertion. Here is a way to rebound the key: (add-hook 'sh-set-shell-hook 'my-disable-here-document) (defun my-disable-here-document () (local-set-key "<" ...


7

This is likely caused by your setting of the prompt confusing zsh about where the cursor is in the terminal. You've included terminal control characters in your prompt without letting zsh know that those won't actually show up on the terminal. This needs to be done by surrounding those portions of the prompt with %{ and %}. This has already been done when ...


6

Add this line to your ~/.zshrc: setopt menu_complete See man zshoptions for details.


6

I use the following function to say that a function or alias or wrapper script (e.g. s) is to be completed like an existing command (e.g. ssh): compdefas () { local a a="$1" shift compdef "$_comps[$a]" "${(@)*}=$a" } compdefas xterm cxterm uxterm xterm-color Some completion commands apply to a family of functions and read the first word of the ...


6

If you are having problems getting “argument completion” working for the new commands then compinit is probably the command you need, however it has a caching mechanism that might be causing your problem. The documentation for my version (4.3.10) says that compinit uses a cached “dump file”, .zcompdump, to store compiled completion functions to speed up ...


6

Mercurial ships it's own bash completion - see contrib/bash_completion in the tarball. At least on openSUSE, this file is installed to /etc/bash_completion.d/, so that bash completion for mercurial is working automatically. You might need to check Ubuntu's mercurial package, if it installs the completion script.


6

complete -p ls or plain complete to list everything.



Only top voted, non community-wiki answers of a minimum length are eligible