Terminal autocompletar: recorrer las sugerencias


37

Tenía esto en mi configuración de Ubuntu y desde que cambié a Fedora quiero configurarlo y olvidé cómo ... La idea es simple:

No quiero que el terminal me muestre sugerencias cuando duplico tab, en cambio quiero que recorra todas las sugerencias posibles con cada pulsación tab... esto también se puede hacer en Vim.

Entonces, cuando escribo gedit ay presiono tab, me mostrará todos los archivos con una primera letra a.


Respuestas:


51

Esto es en realidad una característica de línea de lectura llamada menu-complete. Puede vincularlo a la pestaña (reemplazando el valor predeterminado complete) ejecutando:

bind TAB:menu-complete

Probablemente quieras agregar eso a tu ~/.bashrc. Alternativamente, puede configurarlo para todas las terminaciones de línea de lectura (no solo bash) en ~/.inputrc.

También puede encontrar bind -p(mostrar enlaces actuales, nota que muestra la pestaña como "\C-i") y bind -l(enumerar todas las funciones que se pueden vincular) útiles, así como la sección de edición de línea del manual bash y la documentación de readline .


3
@vanjadjurdjevic: Claro, solo unirlos a diferentes claves.
derobert

44
menu-completees genial, pero oculta la lista de todas las sugerencias posibles ;-( ¿Es posible tanto ver la lista como recorrer las opciones?
Ciro Santilli i 改造 中心 法轮功 六四 事件

2
@CiroSantilli 六四 事件 法轮功 包 卓 轩 También me gusta esta característica en los shells basados ​​en readline. Actualmente, la forma zsh de hacerlo es genial: el primer golpe de la pestaña muestra todas las posibilidades, el segundo golpe de la pestaña comienza a cambiar los elementos de finalización.
xuhdev

1
Vamos a suponer que usted está usando cdy menu-completey en bicicleta más de directorios. ¿Qué tecla presionas para "elegir" ese directorio y comenzar a cambiar el contenido de ese directorio? ¿Hay otra cosa para establecer / vincular?
Tony

1
@ Tony, sí, lo insertará. Pero si usa la barra diagonal, está bien, una ruta como " /usr/local//" sigue siendo perfectamente válida y comenzará a completar el menú dentro /usr/local.
derobert

6

Puede recorrer el menú de finalización en Bash, y también puede mostrar el menú de elementos. A diferencia de Zsh, el elemento del menú actual no se resaltará.

Añadir a ~/.inputrc:

set show-all-if-ambiguous on
set show-all-if-unmodified on
set menu-complete-display-prefix on
"\t": menu-complete
"\e[Z": menu-complete-backward

Documentación de man bash:

Readline Variables
    menu-complete-display-prefix (Off)
           If set to On, menu completion displays the common prefix of the
           list of possible completions (which may be empty) before cycling
           through the list.
    show-all-if-ambiguous (Off)
           This alters the default behavior of the completion functions. If
           set to On, words which have more than one possible completion
           cause the matches to be listed immediately instead of ringing
           the bell.
    show-all-if-unmodified (Off)
           This alters the default behavior of the completion functions in
           a fashion similar to show-all-if-ambiguous. If set to On, words
           which have more than one possible completion without any
           possible partial completion (the possible completions don't
           share a common prefix) cause the matches to be listed
           immediately instead of ringing the bell.

Completing
    menu-complete
          Similar to 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.
    menu-complete-backward
          Identical to menu-complete, but moves backward through the list
          of possible completions, as if menu-complete had been given
          a negative argument. This command is unbound by default.
Al usar nuestro sitio, usted reconoce que ha leído y comprende nuestra Política de Cookies y Política de Privacidad.
Licensed under cc by-sa 3.0 with attribution required.