Con zsh, usarías un alias global :
$ alias -g '^^=--help|grep --color -i'
$ ls ^^ size
--block-size=SIZE scale sizes by SIZE before printing them; e.g.,
'--block-size=M' prints sizes in units of
1,048,576 bytes; see SIZE format below
-h, --human-readable with -l and/or -s, print human readable sizes
-s, --size print the allocated size of each file, in blocks
-S sort by file size, largest first
--sort=WORD sort by WORD instead of name: none (-U), size (-S),
-T, --tabsize=COLS assume tab stops at each COLS instead of 8
The SIZE argument is an integer and optional unit (example: 10K is 10*1024)
Con bash, es posible que pueda usar la expansión de historial, que es una que ocurre lo suficientemente temprano en el análisis de sintaxis de shell que puede funcionar para sustituir una tubería:
Imprima la historia con el texto que desea sustituir y un carácter especial que probablemente no usará de otra manera (como £aquí que está en mi teclado):
$ --help $(: £)|grep
bash: --help: command not found
Usage: grep [OPTION]... PATTERN [FILE]...
Try 'grep --help' for more information.
Luego, usando la expansión del historial para recuperar eso:
$ ls !?£? size
ls --help $(: £)|grep size
--block-size=SIZE scale sizes by SIZE before printing them; e.g.,
'--block-size=M' prints sizes in units of
-h, --human-readable with -l and/or -s, print human readable sizes
-s, --size print the allocated size of each file, in blocks
-S sort by file size, largest first
--sort=WORD sort by WORD instead of name: none (-U), size (-S),
-T, --tabsize=COLS assume tab stops at each COLS instead of 8
O podría haber readlineexpandido --help|grepsobre alguna tecla o secuencia de teclas presionar. Para que eso se aplique bashsolo (y no a otras aplicaciones como gdbusar readline), puede usar el bindcomando bash builtin, que es bashla API de configuración readline, por ejemplo en su ~/.bashrc:
bind '"^^": "--help|grep "'
O agregue a su ~/.inputrc(archivo de configuración de readline):
$if Bash
"^^": "--help|grep "
$endif
(hay otros shells como rco esque usan readline y donde hacer ese enlace podría tener sentido, pero AFAICT, no configuran la rl_readline_namevariable antes de invocar, readlinepor lo que no podrá agregar algunas $ifdeclaraciones para ellos (se mostrarían como othertodas las aplicaciones) que usan readline sin decirle el nombre de su aplicación)).
Tenga en cuenta que debe ingresar el segundo ^dentro de medio segundo (por defecto) después del primero para que ocurra la sustitución.
qh () { type -all "$1" ; { "$1" --help || man "$1" ;} | egrep -i -- "$2" ;}# por lo tanto, podría: qh ls size, qh ls "algo | otro" etc. el (opcional)type -all "$1"también agregará la información sobre $ 1: dice si lanzará un alias, una función, un comando, etc. Y da información del hombre "$ 1" si el comando $ 1 no tenía la opción "--help" (esto sucede a veces)