Tag Info

Hot answers tagged

32

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


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


15

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/


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

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


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

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

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


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


8

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


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

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

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


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

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


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

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


6

you want to bind the editor command reverse-menu-complete to the menuselect keymap. bindkey -M menuselect '^[[Z' reverse-menu-complete I am not sure how portable the escape sequence ^[[Z is, so you may want to check terminfo(5) to see if there is a way of using the $terminfo array to correctly bind it. Note that the menuselect keymap is available after ...


6

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


5

(No answer to your exact question, but many workarounds.) You don't need to match your scripting shell with your interactive shell. (For example, most (t)csh or zsh users write sh scripts). If you have or can install a better interactive shell than the Bourne shell (zsh, bash, tcsh), go for it. Even if you can't, look if there's a ksh, which is likely to ...


5

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


5

I would modify the example from the link you mentioned into something like this: _foo() { local cur prev opts COMPREPLY=() cur="${COMP_WORDS[COMP_CWORD],,}" # this downcases the result prev="${COMP_WORDS[COMP_CWORD-1],,}" # here too opts="--help --verbose --version" if [[ ${cur} == -* ]] ; then COMPREPLY=( $(compgen -W ...


5

Try rlwrap -c patch -i patch.diff rlwrap tries do add readline functionality to commands that lack it. There exists a couple of alternatives to rlwrap. If you're a zsh user, you may also have a look at Using zsh's line editor to wrap around subprocesses and at /usr/share/zsh/functions/Misc/nslookup for an example of how to add the zsh line editor to a ...


5

The bash completion package includes completions for ssh commands, including: ssh ssh-add ssh-copy-id sshfs You can browse the source here: https://alioth.debian.org/scm/browser.php?group_id=100114


5

Zsh comes with the insert-and-predict¹ edition widget, which makes it suggest completions spontaneously based on your command history. ¹ info -f zsh --index-search=predict-on or LESS=$LESS+/predict-on man zshcontrib on your machine. To try it out: autoload predict-on predict-toggle() { ((predict_on=1-predict_on)) && predict-on || predict-off ...



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