Seria possível usar $history
e < a href="http://zsh.sourceforge.net/Doc/Release/Options.html#index-INTERACTIVECOMMENTS"> INTERACTIVE_COMMENTS
:
echo_literally_helper () {
local str="$history[$(print -P %h)]"
echo "${str#*echo_literally\ }"
}
alias echo_literally='echo_literally_helper #'
# for using '$history'. (does not needed in zsh-5.5.1 here, though.)
zmodload zsh/parameter
# zsh does not enable this option by default, so turn on.
setopt interactivecomments
Então:
% echo_literally a; b; c
a; b; c
Nota: ele usa print -P %h
e $history
para obter o comando do histórico atual em vez do comando history
(ou fc
) bulitin.
Aqui estão algumas referências para documentações zsh.
history
This associative array maps history event numbers to the full history lines.
...
-
INTERACTIVE_COMMENTS
(-k
)
Allow comments even in interactive shells.
-
Comments:
In non-interactive shells, or in interactive shells with theINTERACTIVE_COMMENTS
option set, a word beginning with the third character of the histchars parameter (‘#’ by default) causes that word and all the following characters up to a newline to be ignored.
-
%h
%!
Current history event number.-- zshmisc(1): Shell state, Simple Prompt Escapes, Prompt Expansion