Tag Info

Hot answers tagged

46

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


29

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/


26

Typing Ctrli sends the same character as Tab would. This should work without rebinding any keys.


25

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


25

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


21

I don't have an OSX system handy to check on but on all *nixes, ~foo is a shorthand for the home directory of user foo. For example, this command will move into my user's $HOME (cd ~ alone will move into your home directory): cd ~terdon So, ~ and Tab will expand to all possible user names. The list should be the same as the list of users in /etc/passwd. ...


20

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


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


18

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


17

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


16

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


16

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


14

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.


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


14

Oooh, I found an explanation. To quote the relevant part: The zsh shell comes with (more than one) great feature(s), such as remote tabcompletion. If you for example want to copy a file over scp, simply hit tab at any part of the filename on the remote host. zsh is able to establish an ssh session on the background, and fetch the related information ...


13

You can bind the completion command to any key sequence. Pick something that's easy to type but unlikely to appear in a normal command, like say capital A. Put bind "A":complete in ~/.bashrc, and new bash instances will use capital A as well as TAB to invoke completion.


12

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


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

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


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

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


10

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


10

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.


10

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.


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

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 don't know about fixing — there are all kinds of things that could go cause delays. But I can offer a few tips to investigate. Just as a guess, maybe there's a directory somewhere in a search path ($PATH, or some place where bash looks for completion data) that's on a filesystem which is slow to respond. Usually it's remote filesystems that are slow, but ...


9

Try: autoload predict-on predict-on See: info zsh --index-search=predict-on for details.


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


8

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



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