Tag Info

Hot answers tagged

36

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 ...


22

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/


20

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


19

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.


15

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 ...


14

Redirecting the standard error immediately to /dev/null is a bad idea as it will hide early error messages, and failures may be hard to diagnostic. I suggest something like the following start-app zsh script: #!/usr/bin/env zsh coproc "$@" 2>&1 quit=$(($(date +%s)+5)) nlines=0 while [[ $((nlines++)) -lt 10 ]] && read -p -t 5 line do [[ ...


12

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=( ...


12

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 ...


12

It does this using bash v4's completion features. The completion code for apt-get is provided by the bash-completion package and located at /usr/share/bash-completion/completions/apt-get. Applications that have completion and are not part of the base bash-completion package place their completion scripts in /etc/bash_completion.d. The completions are loaded ...


11

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' ...


11

The easiest way of doing this is to include a shell script in /etc/bash_completion.d/. The basic structure of this file is a simple function that performs the completion and then invocation of complete which is a bash builtin. Rather than go into detail on how to use complete, I suggest you read An Introduction to Bash Completion. Part 1 covers the basics ...


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

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.


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 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

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

Zsh completion works with so called ssh bookmarks. These are per host configurations in ~/.ssh/config. For example, host baz hostname 192.168.1.2 port 22 user warrick host bar hostname example.com port 2200 user kevin identityfile /home/warrick/.ssh/ec2.pem man ssh_config to see a full list of options. EDIT I am using ...


7

Readline library has bell-style variable: Controls what happens when Readline wants to ring the terminal bell. If set to ‘none’, Readline never rings the bell. If set to ‘visible’, Readline uses a visible bell if one is available. If set to ‘audible’ (the default), Readline attempts to ring the terminal’s bell. So you can put into your ...


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 ...



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