zsh-users
 help / color / mirror / code / Atom feed
* "Literal" command execution
@ 2012-01-23 19:51 Yuri D'Elia
  2012-01-23 22:13 ` Damien Thébault
  2012-01-23 22:32 ` "Literal" command execution Bart Schaefer
  0 siblings, 2 replies; 11+ messages in thread
From: Yuri D'Elia @ 2012-01-23 19:51 UTC (permalink / raw)
  To: zsh-users

Hi everyone.

I'm trying to reduce some typing here, as usual ;).
I have a command line logger that allows free text as its main arguments (random example: taskwarrior). A typical example might be:

  command log [free text follows]

I want to reduce escaping to the bare minimum. Dollars are not really a problem, but I discovered myself to escape '<' '>' and '!' too often.

Of course I am already aware of both noglob and nocorrect, but I would need something more extreme, as in "feed whatever text, including #, etc, that follows the command as arguments".

Is there any way to achieve that?
Maybe by some rewriting trick?


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: "Literal" command execution
  2012-01-23 19:51 "Literal" command execution Yuri D'Elia
@ 2012-01-23 22:13 ` Damien Thébault
  2012-02-13 12:38   ` Catch URLs (was: "Literal" command execution) mark+lists
  2012-01-23 22:32 ` "Literal" command execution Bart Schaefer
  1 sibling, 1 reply; 11+ messages in thread
From: Damien Thébault @ 2012-01-23 22:13 UTC (permalink / raw)
  To: Yuri D'Elia; +Cc: zsh-users

On Mon, Jan 23, 2012 at 20:51, Yuri D'Elia <wavexx@users.sf.net> wrote:
> I'm trying to reduce some typing here, as usual ;).
> I have a command line logger that allows free text as its main arguments (random example: taskwarrior). A typical example might be:
>
>  command log [free text follows]
>
> I want to reduce escaping to the bare minimum. Dollars are not really a problem, but I discovered myself to escape '<' '>' and '!' too often.
>
> Of course I am already aware of both noglob and nocorrect, but I would need something more extreme, as in "feed whatever text, including #, etc, that follows the command as arguments".
>
> Is there any way to achieve that?
> Maybe by some rewriting trick?

Hello,

For URLs I'm using something called url-quote-magic: when I start
writing an URL, it's detected and then all special characters are
escaped (&, <, >, !).
autoload -U url-quote-magic ; zle -N self-insert url-quote-magic
This is really great for copying+pasting URLs, for example to use it in wget.

What you want to do looks pretty similar, so maybe this could be a
starting point for you? (except it's during a specific command
arguments instead of autodetected)

Regards,

-- 
Damien Thebault


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: "Literal" command execution
  2012-01-23 19:51 "Literal" command execution Yuri D'Elia
  2012-01-23 22:13 ` Damien Thébault
@ 2012-01-23 22:32 ` Bart Schaefer
  2012-01-24 11:52   ` Yuri D'Elia
  1 sibling, 1 reply; 11+ messages in thread
From: Bart Schaefer @ 2012-01-23 22:32 UTC (permalink / raw)
  To: Yuri D'Elia, zsh-users

On Jan 23,  8:51pm, Yuri D'Elia wrote:
}
}   command log [free text follows]
} 
} I want to reduce escaping to the bare minimum. Dollars are not really
} a problem, but I discovered myself to escape '<' '>' and '!' too
} often.
}
} Of course I am already aware of both noglob and nocorrect, but I would
} need something more extreme, as in "feed whatever text, including #,
} etc, that follows the command as arguments".

Have a look at Functions/Zle/url-quote-magic, which relies on being able
to substitute itself for the self-insert ZLE builtin.  You can skip over
the introductory comments about zstyles and focus on the function at the
end of the file, particularly the way it analyzes $KEYS and modifies
$LBUFFER.

A difficulty with this technique is that it becomes difficult to cascade
it with other similar techniques; ZLE doesn't have emacs' concept of
"advice" around a keybinding.


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: "Literal" command execution
  2012-01-23 22:32 ` "Literal" command execution Bart Schaefer
@ 2012-01-24 11:52   ` Yuri D'Elia
  2012-01-24 21:12     ` Bart Schaefer
  0 siblings, 1 reply; 11+ messages in thread
From: Yuri D'Elia @ 2012-01-24 11:52 UTC (permalink / raw)
  To: zsh-users

On Mon, 23 Jan 2012 14:32:09 -0800
Bart Schaefer <schaefer@brasslantern.com> wrote:

> Have a look at Functions/Zle/url-quote-magic, which relies on being able
> to substitute itself for the self-insert ZLE builtin.  You can skip over
> the introductory comments about zstyles and focus on the function at the
> end of the file, particularly the way it analyzes $KEYS and modifies
> $LBUFFER.

Thank you Bart (and also Damien) for this suggestion.
This is indeed a step in the right direction.

> A difficulty with this technique is that it becomes difficult to cascade
> it with other similar techniques; ZLE doesn't have emacs' concept of
> "advice" around a keybinding.

I think I can simplify it a lot, by basically escaping everything unless it already starts in quotes.

I'm just missing this: can I substitute self-insert just for a specific zstyle? This way I could make it work just for a specific command?


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: "Literal" command execution
  2012-01-24 11:52   ` Yuri D'Elia
@ 2012-01-24 21:12     ` Bart Schaefer
  0 siblings, 0 replies; 11+ messages in thread
From: Bart Schaefer @ 2012-01-24 21:12 UTC (permalink / raw)
  To: zsh-users

On Jan 24, 12:52pm, Yuri D'Elia wrote:
}
} I'm just missing this: can I substitute self-insert just for a
} specific zstyle? This way I could make it work just for a specific
} command?

You can't substitute self-insert for just a specific style, but you
can test the style inside the widget function and fall back to the
builtin with "zle .self-insert" if the test fails.  url-quote-magic
does that when the current word being input doesn't appear to have
a URL scheme at the front of it.


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Catch URLs (was: "Literal" command execution)
  2012-01-23 22:13 ` Damien Thébault
@ 2012-02-13 12:38   ` mark+lists
  2012-02-13 12:57     ` Peter Stephenson
  0 siblings, 1 reply; 11+ messages in thread
From: mark+lists @ 2012-02-13 12:38 UTC (permalink / raw)
  To: zsh-users

Hi,

>> I want to reduce escaping to the bare minimum. Dollars are not 
>> really a problem, but I discovered myself to escape '<' '>' and '!' 
>> too often.
> For URLs I'm using something called url-quote-magic: when I start
> writing an URL, it's detected and then all special characters are
> escaped (&, <, >, !).
> autoload -U url-quote-magic ; zle -N self-insert url-quote-magic
> This is really great for copying+pasting URLs, for example to use it 
> in wget.

It's almost really great. :)

I have setopt warncreateglobal enabled by default because it helps me 
to catch global variables that should be local, especially in my own 
functions.
Now, when I run the autoload line above and then paste an URL I am 
warned every time the URL is being escaped.

Try something like this to reproduce it. In this example I'll just use 
an arbitrary URL I happen to have on my clipboard:

setopt warncreateglobal
autoload -U url-quote-magic; zle -N self-insert url-quote-magic
curl -LO 
https://git.kernel.org/?p=linux/kernel/git/stable/stable-queue.git;a=blob_plain;f=queue-3.2/mm-fix-up-thp-spin_is_locked-bugs.patch;hb=50c8f68647a605333fe78c86966e802c07a105c0

output:
8 of these:
url-quote-magic:68: array parameter reply created globally in function
url-quote-magic:72: array parameter reply created globally in function

I'm not sure how to fix this, tips for that are appreciated.

Mark


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Catch URLs (was: "Literal" command execution)
  2012-02-13 12:38   ` Catch URLs (was: "Literal" command execution) mark+lists
@ 2012-02-13 12:57     ` Peter Stephenson
  2012-02-14 15:27       ` Mark van Dijk
  2012-03-31 16:00       ` Mark
  0 siblings, 2 replies; 11+ messages in thread
From: Peter Stephenson @ 2012-02-13 12:57 UTC (permalink / raw)
  To: zsh-users

On Mon, 13 Feb 2012 12:38:55 +0000
<mark+lists@internecto.net> wrote:
> url-quote-magic:68: array parameter reply created globally in function
> url-quote-magic:72: array parameter reply created globally in function

I don't think reply can be need outside url-quote-magic, can it?
In fact, the function itself doesn't use it either --- ideally zstyle
should have a mechanism for making it local within itself.

Index: Functions/Zle/url-quote-magic
===================================================================
RCS file: /cvsroot/zsh/zsh/Functions/Zle/url-quote-magic,v
retrieving revision 1.3
diff -p -u -r1.3 url-quote-magic
--- Functions/Zle/url-quote-magic	11 Jul 2008 19:12:24 -0000	1.3
+++ Functions/Zle/url-quote-magic	13 Feb 2012 12:56:17 -0000
@@ -60,6 +60,7 @@
 #       Use compsys for nested quoting analysis and command parsing.
 
 # Establish default values for styles, but only if not already set
+local -a reply
 
 zstyle -m ':url-quote-magic:\*' url-metas '*' ||
     zstyle ':url-quote-magic:*' url-metas '*?[]^(|)~#{}='

-- 
Peter Stephenson <pws@csr.com>            Software Engineer
Tel: +44 (0)1223 692070                   Cambridge Silicon Radio Limited
Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, UK


Member of the CSR plc group of companies. CSR plc registered in England and Wales, registered number 4187346, registered office Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, United Kingdom
More information can be found at www.csr.com. Follow CSR on Twitter at http://twitter.com/CSR_PLC and read our blog at www.csr.com/blog


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Catch URLs (was: "Literal" command execution)
  2012-02-13 12:57     ` Peter Stephenson
@ 2012-02-14 15:27       ` Mark van Dijk
  2012-03-31 16:00       ` Mark
  1 sibling, 0 replies; 11+ messages in thread
From: Mark van Dijk @ 2012-02-14 15:27 UTC (permalink / raw)
  To: zsh-users

> I don't think reply can be need outside url-quote-magic, can it?
> In fact, the function itself doesn't use it either --- ideally zstyle
> should have a mechanism for making it local within itself.
> 
> Index: Functions/Zle/url-quote-magic
> ===================================================================
> RCS file: /cvsroot/zsh/zsh/Functions/Zle/url-quote-magic,v
> retrieving revision 1.3
> diff -p -u -r1.3 url-quote-magic
> --- Functions/Zle/url-quote-magic	11 Jul 2008 19:12:24
> -0000	1.3 +++ Functions/Zle/url-quote-magic	13 Feb 2012
> 12:56:17 -0000 @@ -60,6 +60,7 @@
>  #       Use compsys for nested quoting analysis and command parsing.
>  
>  # Establish default values for styles, but only if not already set
> +local -a reply
>  
>  zstyle -m ':url-quote-magic:\*' url-metas '*' ||
>      zstyle ':url-quote-magic:*' url-metas '*?[]^(|)~#{}='
> 

Ah, that's easier than I expected. Thanks!


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Catch URLs (was: "Literal" command execution)
  2012-02-13 12:57     ` Peter Stephenson
  2012-02-14 15:27       ` Mark van Dijk
@ 2012-03-31 16:00       ` Mark
  2012-04-01 17:18         ` Peter Stephenson
  1 sibling, 1 reply; 11+ messages in thread
From: Mark @ 2012-03-31 16:00 UTC (permalink / raw)
  To: zsh-users

Hi,

On Mon, 13 Feb 2012 12:57:59 +0000
Peter Stephenson <Peter.Stephenson@csr.com> wrote:

> On Mon, 13 Feb 2012 12:38:55 +0000
> <mark+lists@internecto.net> wrote:
> > url-quote-magic:68: array parameter reply created globally in
> > function url-quote-magic:72: array parameter reply created globally
> > in function
> 
> I don't think reply can be need outside url-quote-magic, can it?
> In fact, the function itself doesn't use it either --- ideally zstyle
> should have a mechanism for making it local within itself.
> 
> Index: Functions/Zle/url-quote-magic
> ===================================================================
> RCS file: /cvsroot/zsh/zsh/Functions/Zle/url-quote-magic,v
> retrieving revision 1.3
> diff -p -u -r1.3 url-quote-magic
> --- Functions/Zle/url-quote-magic	11 Jul 2008 19:12:24
> -0000	1.3 +++ Functions/Zle/url-quote-magic	13 Feb 2012
> 12:56:17 -0000 @@ -60,6 +60,7 @@
>  #       Use compsys for nested quoting analysis and command parsing.
>  
>  # Establish default values for styles, but only if not already set
> +local -a reply
>  
>  zstyle -m ':url-quote-magic:\*' url-metas '*' ||
>      zstyle ':url-quote-magic:*' url-metas '*?[]^(|)~#{}='
> 

Hmm, I have recently upgraded zsh and although I saw your patch
included, the error came back. Apparently I had fixed it manually.
Please see below. I wonder whether this method is ideal for you.

Thanks,
Mark

diff -pU1 old/url-quote-magic new/url-quote-magic 
--- old/url-quote-magic	2012-03-31 17:58:23.646634259 +0200
+++ new/url-quote-magic	2012-03-31 17:57:13.587013805 +0200
@@ -68,3 +68,3 @@ zstyle -m ':url-quote-magic:\*' url-meta
 zstyle -m ':url-quote-magic:\*' url-seps '*' ||
-    zstyle -e ':url-quote-magic:*' url-seps 'reply=(";&<>${histchars[1]}")'
+    zstyle -e ':url-quote-magic:*' url-seps 'local -a reply; reply=(";&<>${histchars[1]}")'
 
@@ -72,3 +72,3 @@ zstyle -m :url-quote-magic url-globbers
     zstyle -e :url-quote-magic url-globbers \
-	'zmodload -i zsh/parameter;
+	'local -a reply; zmodload -i zsh/parameter;
 	 reply=( noglob


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Catch URLs (was: "Literal" command execution)
  2012-03-31 16:00       ` Mark
@ 2012-04-01 17:18         ` Peter Stephenson
  2012-04-02 16:13           ` Mark van Dijk
  0 siblings, 1 reply; 11+ messages in thread
From: Peter Stephenson @ 2012-04-01 17:18 UTC (permalink / raw)
  To: zsh-users

On Sat, 31 Mar 2012 18:00:50 +0200
Mark <lists+zsh@internecto.net> wrote:
> Hmm, I have recently upgraded zsh and although I saw your patch
> included, the error came back. Apparently I had fixed it manually.
> Please see below. I wonder whether this method is ideal for you.
> 
> Thanks,
> Mark
> 
> diff -pU1 old/url-quote-magic new/url-quote-magic 
> --- old/url-quote-magic	2012-03-31 17:58:23.646634259 +0200
> +++ new/url-quote-magic	2012-03-31 17:57:13.587013805 +0200
> @@ -68,3 +68,3 @@ zstyle -m ':url-quote-magic:\*' url-meta
>  zstyle -m ':url-quote-magic:\*' url-seps '*' ||
> -    zstyle -e ':url-quote-magic:*' url-seps 'reply=(";&<>${histchars[1]}")'
> +    zstyle -e ':url-quote-magic:*' url-seps 'local -a reply; reply=(";&<>${histchars[1]}")'
>  
> @@ -72,3 +72,3 @@ zstyle -m :url-quote-magic url-globbers
>      zstyle -e :url-quote-magic url-globbers \
> -	'zmodload -i zsh/parameter;
> +	'local -a reply; zmodload -i zsh/parameter;
>  	 reply=( noglob

I see what's happening now... there are functions defined internally,
and I only put the "local" in the function that's only run once to
define them.

Your solution's probably OK, since with the "-a" the shell doesn't print
the value after "local" the second time, as it would with "local reply;
local reply".  Still, I've kept with the spirit of what I did before...

Index: Functions/Zle/url-quote-magic
===================================================================
RCS file: /cvsroot/zsh/zsh/Functions/Zle/url-quote-magic,v
retrieving revision 1.4
diff -p -u -r1.4 url-quote-magic
--- Functions/Zle/url-quote-magic	14 Feb 2012 15:33:02 -0000	1.4
+++ Functions/Zle/url-quote-magic	1 Apr 2012 17:17:21 -0000
@@ -84,7 +84,7 @@ zstyle -m ':urlglobber' url-other-schema
 # Define the "urlglobber" helper function and shorthand "globurl" alias
 
 function urlglobber {
-    local -a args globbed localschema otherschema
+    local -a args globbed localschema otherschema reply
     local arg command="$1"
     shift
     zstyle -s :urlglobber url-local-schema localschema '|'
@@ -109,6 +109,7 @@ alias globurl='noglob urlglobber '
 function url-quote-magic {
     setopt localoptions noksharrays extendedglob
     local qkey="${(q)KEYS}"
+    local -a reply
     if [[ "$KEYS" != "$qkey" ]]
     then
 	local lbuf="$LBUFFER$qkey"

-- 
Peter Stephenson <p.w.stephenson@ntlworld.com>
Web page now at http://homepage.ntlworld.com/p.w.stephenson/


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Catch URLs (was: "Literal" command execution)
  2012-04-01 17:18         ` Peter Stephenson
@ 2012-04-02 16:13           ` Mark van Dijk
  0 siblings, 0 replies; 11+ messages in thread
From: Mark van Dijk @ 2012-04-02 16:13 UTC (permalink / raw)
  To: zsh-users

On Sun, 1 Apr 2012 18:18:20 +0100
Peter Stephenson <p.w.stephenson@ntlworld.com> wrote:

> On Sat, 31 Mar 2012 18:00:50 +0200
> Mark <lists+zsh@internecto.net> wrote:
> > Hmm, I have recently upgraded zsh and although I saw your patch
> > included, the error came back. Apparently I had fixed it manually.
> > Please see below. I wonder whether this method is ideal for you.

(snip)

> I see what's happening now... there are functions defined internally,
> and I only put the "local" in the function that's only run once to
> define them.
> 
> Your solution's probably OK, since with the "-a" the shell doesn't
> print the value after "local" the second time, as it would with
> "local reply; local reply".  Still, I've kept with the spirit of what
> I did before...
> 
> Index: Functions/Zle/url-quote-magic

(snip)

Yes, this fix works fine. Thanks again :)

Mark

-- 
Love truth, but pardon error.
  --Voltaire, "Deuxième discours: de la liberté,"
    Sept Discours en Vers sur l'Homme (1738)


^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2012-04-02 16:13 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-01-23 19:51 "Literal" command execution Yuri D'Elia
2012-01-23 22:13 ` Damien Thébault
2012-02-13 12:38   ` Catch URLs (was: "Literal" command execution) mark+lists
2012-02-13 12:57     ` Peter Stephenson
2012-02-14 15:27       ` Mark van Dijk
2012-03-31 16:00       ` Mark
2012-04-01 17:18         ` Peter Stephenson
2012-04-02 16:13           ` Mark van Dijk
2012-01-23 22:32 ` "Literal" command execution Bart Schaefer
2012-01-24 11:52   ` Yuri D'Elia
2012-01-24 21:12     ` Bart Schaefer

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).