コマンドラインでコマンドかファイルかを判断する。

まあ、いつか使えるかもしれないので残しておく。

irb(main):018:0> s="ls aaa|cat bbb|echo aP";a,*d=s.split(/\||;/).map{|i|i.split(/\s/)}.pop;if /(.*)P/.match(a) then ["command",$1] else until /(.*)P/.match(d.shift); end; ["file",$1] ;end
=> ["file", "a"]
irb(main):019:0> s="ls aaa|cat bbb|echP";a,*d=s.split(/\||;/).map{|i|i.split(/\s/)}.pop;if /(.*)P/.match(a) then ["command",$1] else until /(.*)P/.match(d.shift); end; ["file",$1] ;end
=> ["command", "ech"]
irb(main):020:0> s="ls aaa|cat bbb|echo P";a,*d=s.split(/\||;/).map{|i|i.split(/\s/)}.pop;if /(.*)P/.match(a) then ["command",$1] else until /(.*)P/.match(d.shift); end; ["file",$1] ;end
=> ["file", ""]

xyzzyでかき換え直そうとした残骸は以下

(progn
  (setq s "ls aaa|cat bbb|echo aa ;P")
  (setq l (car (last (mapcar (lambda (i) (split-string i " \t")) (split-string s "|;")))))
  (if (string-match "\\(.*\\)P" (car l))
      (list "command" (match-string 1))
    (progn
      (setq l (cdr l))
      (while (not (string-match "\\(.*\\)P" (car l)))
	(setq l (cdr l)))
      (list "file" (match-string 1)))))