Bash: get TAB completion as a list

I would like to know a way to get a list of possible command completions, but without executing it. For example, to get a list of Linux modules that can be loaded, you can do:

$ sudo modprobe [TAB][TAB]
... list of completions

But what if you want to "save" this list in a file? I think that for this purpose there should be any command parameter complete:

$ complete <whanever option> modprobe > modprobe-completion-list.txt

or, for partial improvements:

$ complete <whanever options> "modprobe i2" > modules-prefix-i2-list.txt
+4
source share
2 answers

compgen. bash -, modprobe , . compgen, , , , .

$ complete -p modprobe
complete -F _modprobe modprobe
$ compgen -F _modprobe
bash: compgen: warning: -F option may not work as you expect

, , , ; .

, , script readline. , , (cron, dememons), .

$ echo -en "bind 'set page-completions Off'
            bind 'set completion-query-items 0'
            sudo modprobe \t\t\x15" | bash -i
$ sudo modprobe 
3c574_cs                       msi-laptop
3c589_cs                       msi-wmi
3c59x                          msp3400
3w-9xxx                        mspro_block
  (...)
ms_block                       zr36067
msdos                          zr364xx
msi001                         zram
msi2500                        
$ exit

:

  • bind 'set page-completions Off' "--More--", script, , .

  • set completion-query-items 0 " 3598 ? (y n)".

  • sudo modprobe \t\t . .

  • \x15 - hex C-u, unix-line-discard, , sudo modprobe .

, stderr. , , 2> file, 2>&1 |&.

, @betterworld M-* :

$ echo -en 'sudo modprobe \e*\x01\ed\edecho' | bash -i 2>/dev/null

emacs ( ). set -o emacs\n, .

+2

sudo modprobe <Esc>*, . , echo [list of modules] > file

+1

All Articles