Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: Command line preprocessing

by clemburg (Curate)
on Sep 01, 2001 at 18:45 UTC ( [id://109638]=note: print w/replies, xml ) Need Help??


in reply to Command line preprocessing

I do not know of any shell that has a feature that would allow one to do command preprocessing, but I have managed to persuade shell-mode in emacs to do what you want.

Emacs shell-mode can be customized by setting some variables defined in the comint package. Put the following code in a file with ending ".el" (emacs lisp), and load it with the command "M-x load-file". After that, opening a shell buffer with "M-x shell" will give you a "shell" that does what you want. Quoting is achieved by enclosing the text to quote with "my-quote()".

Emacs lisp code:

(defun my-quote-function (s) "quote special chars in string" (shell-quote-argument s)) (defun my-input-sender (proc command) "specialized comint-input-sender function with extra quoting" (let ((quoting-regex "my-quote(\\(.*\\))")) (string-match quoting-regex command) (let ((string-to-quote (match-string 1 command))) (if (null string-to-quote) (comint-simple-send proc command) (let ((quoted-string (my-quote-function string-to-quote))) (string-match quoting-regex command) (comint-simple-send proc (replace-match quoted-string t t command))))))) (setq comint-input-sender 'my-input-sender)

Works like this (excerpt from shell mode buffer):

--> echo $foo --> echo my-quote($foo) $foo --> echo "This is not quoted but" my-quote("this") is This is not quoted but "this" is -->

Christian Lemburg
Brainbench MVP for Perl
http://www.brainbench.com

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://109638]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (4)
As of 2024-04-24 00:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found