Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: "Pull just the text of a single command" (was Re: .zsh_history)




On 2023-04-16 08:53, Bart Schaefer wrote:
chain=( ${(s:; :)${(z)1}} )

in preexec ():

chain=( ${(s:; :)${(z)1}} )
print -lr $chain

try it:

0 /aWorking/Zsh/Boot 1 $ echo *; echo howdy; echo $path; echo $path > nowhere; echo "Now is the time" | grep 'time'
echo *
echo howdy
echo $path
echo $path > nowhere
echo "Now is the time" | grep 'time'

... so that's about it.  I'm not going to be throwing anything more troublesome at it than globs and variables and redirections and pipes, and those are remaining as raw text so that's fit for purpose.  Only thing that would break it is chained commands which isn't really a problem.  However, even there, I can't help but notice that if there was a way of matching each one of the chained commands to its appropriate member of the array, then even that would be solvable.  Some sort of counter for each one of the chained commands?  'echo $path' is command #3 above so its match is $chain[3] and its tail is '$path'.  Easy.







Messages sorted by: Reverse Date, Date, Thread, Author