<<< Date Index >>>     <<< Thread Index >>>

Re: use current folder name as argument to abitrary command



On 02May2009 14:55, David J. Weller-Fahy 
<dave-lists-mutt-users@xxxxxxxxxxxxxxx> wrote:
[...snip...]
| # save the state of wait_key
| folder-hook . "set my_wait_key=\$wait_key"
| # turn off wait_key
| folder-hook . "set wait_key=no"
| # run command to create file to source
| folder-hook . "push <shell-escape>\"~/.mutt/muttecho.sh \$my_curdir\"<enter>"
| # set wait_key to saved state
| folder-hook . "set wait_key=\$my_wait_key"
| # source the file
| folder-hook . "push <enter-command>\"source ~/.mutt/muttintest\"<enter>"
| #v-
| 
| And the following muttecho.sh file.
| #v+
| [ -e ~/.mutt/muttintest ] && rm ~/.mutt/muttintest
| echo set my_revdir="$1" > ~/.mutt/muttintest
| #v-
| 
| I get two results that I did not expect.
| 1) I get the "any key" prompt after the shell command executes.
| 2) my_revdir is not filled with the current folder name.

Ok, you've got a few issues.

Mutt config commands _are_ executed in series, in the order in the
config file.

The keyboard input stream is not consulted until commmands have stopped.

So what's happening here is that your folder hooks are running in series
as you might hope. BUT the "push" folder-hook _just_ pushes the text
onto the keyboard input stream. The input stream is not run until
the folder-hooks are over.

So your wait_key shuffling runs to completion before anything you pushed
is used. So "push" is not what you want, at least for what you're trying
to use it for.

I also suggest you utilise the `backtick` syntax. Like the shell, mutt will
use shell output. For example:

  `echo set my_foo=bah`

in your muttrc runs the shell command:

  echo set my_foo=bah

which produces:

  set my_foo=bah

which mutt then executes, setting my_foo to "bah".

So you can go:

  `muttecho.sh ...`

in your muttrc. You'll have to escape a little to embed that in a folder
hook. This avoids a lot of racy mucking around with temp files.

I'm trying to solve a similar problem to yours, so I'm somewhat
interested in this discussion.

I'm doing this:

  folder-hook . 'set my_oldrecord=$record; set record=^; set my_folder=$record; 
set record=$my_oldrecord'
  folder-hook . "macro index '\$' \"<change-folder>\$my_folder<enter>\""

That's exactly two lines in case your mail reader folds something.

The first one stores the current folder in $my_folder.
The second maps '$', normally the sync op, to a change-folder command.
This is to work around the fact that mutt's sync only pushes pending
deletes etc to the folder and does not then consult the folder for new
mail.

The macro is done as a folder hook because it must run _after_ the
folder-hook that sets $my_folder, and it must set the macro to a string
that has the value of $my_folder in it. You'll notice that the macro
does _not_ mention $my_folder:

  $     macro <change-folder>=me<enter>

That's from the macro listing produced by the '?' key.

Cheers,
-- 
Cameron Simpson <cs@xxxxxxxxxx> DoD#743
http://www.cskk.ezoshosting.com/cs/

Although it does not mindfully keep guard, in the small mountain fields the
scarecrow does not stand in vain.       - trans. Bukkoku Kokushi