[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Multiple commands in binding



Hi Carlos,

On Tue, Sep 18, 2012 at 09:39:52AM -0300, Carlos Pita wrote:
> this is from an somewhat old post in arch bbs:
> 
> """
> The Problem is that introducing a mechanism to bind a key to multiple
> commands would cause quite ugly escaping and quoting problems. Normal
> shells already handle quoting and escaping => spawn a shell
> """
> 
> I can't see the awkward quoting problems you mention. A sensible
> command separator would do it, won't it?

Yes, it would. But we had to pick one, either yet another command
separator (e.g. ",") or something that already is known (e.g. ";").

> And, after all, the entire
> 
> hc keybind ...
> 
> is already a shell statement that handles escaping and quoting like a
> champ, in case you need to escape the separator or something. Am I
> missing something here?

The problem is that one has to escape characters on two different
levels:

  1. On the shell
  2. In herbstluftwm

And the user always has to think twice: First how the shell escape works
and then how herbstluftwm interprets that what the shell-escaping
produces. It will also affect users who don't need multiple commands,
because then one also need to escape the escape character.

I like the current situation where one can say: herbstluftwm always
executes the commands like you send it to them.

There are currently some different ideas that don't need escaping at
all:

=== keybindadd ===
The idea is that you actually only need multiple commands for
keybindings. And multiple commands can be registred by creating a
keybinding and adding other commands afterwards, e.g.:

herbstclient keybind Mod1-Return use terminaltag
herbstclient keybindadd Mod1-Return spawn Terminal

=== chain commands by specifing their length ===
If you have two commands you want to chain and write them next to each
other

    cmd1 arg1a arg1b cmd2 arg2a

then you can determine where cmd2 starts if you know that the first
command takes two arguments (i.e. has length three). So we could add a
command "cmdchain" that takes two commands and the length of the first
one which executes cmd1 arg1a arg1b and then cmd2 arg2a:

    chaincmd 3 cmd1 arg1a arg1b cmd2 arg2a

=== Specify a command seperator dynamically ===
Similar to sed's s/search/replace/ where once can freely choose the
separator, we could add a chaimcmd that takes a seperator word first
followed by the two commands:

    chaincmd , cmd1 arg1a arg1b , cmd2 arg2a     # would be equal to
    chaincmd .-. cmd1 arg1a arg1b .-. cmd2 arg2a # or
    chaincmd ab cmd1 arg1a arg1b ab cmd2 arg2a

And as the separator is a complete word instead of just a single
character we could omit the implementation of escaping (because there
always is a word thats in none of the commands or their arguments)


Are there other ways to get around the escaping problem? What do you
like most? Currently I prefer the last method.

Regards,
Thorsten