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

Re: Multiple commands in binding



Hi,

On Thu, Sep 20, 2012 at 01:54:51PM +0200, Thorsten Wißmann wrote:
> === 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)

Yesterday implemented this as the commands "chain", "and" and "or". You
can find them temporarily in the chain branch[1]. They aren't merged to
master yet, because they're maybe not final, there is no documentation
yet and later commands still overwrite the output of previous commands
in the chain.

The current usage is:

    [chain|or|and] SEP COMMANDS...

"chain","or","and" expect a separator SEP and a list of COMMANDS,
separated by exactly on SEP between them. "chain" executes all commands
in the order they are given. "and" stops the execution after a command
fails (i.e. returns something != 0). "or" stops the execution after a
command succeeds (i.e. returns something == 0). So their equivalences in
Posix shell are:

    chain: ;
    and: &&
    or: ||

Some examples are:
  - Create a tag "foo" and directly use it:
    chain , add foo , use foo
  - Rotate the layout clockwise:
    chain . lock . rotate . rotate . rotate . unlock
  - Try to enter tag "browser". If it doesn't exist use "web". If that
    does not exist show an error message:
    or / use browser / use web / spawn xmessage "no tags found"
  - They also can be nested, but I couldn't find a useful example. You
    can play with it by using the tab completion (the separators show
    you in which chains you are).

Feel free to report further problems, comments or suggestions.


Thorsten

[1] git clone git://git.cs.fau.de/hlwm -b chain herbstluftwm
or: git fetch && git checkout origin/chain in an existing repository
or: http://git.cs.fau.de/?p=hlwm;a=shortlog;h=refs/heads/chain