Re: use current folder name as argument to abitrary command
On Fri, May 01, 2009 at 11:28:39PM -0500, David J. Weller-Fahy wrote:
> folder-hook +lists* "set shell=\"~/.mutt/gen-set-from.pl \$my_curdir && sleep
> 0.5\""
> folder-hook +lists* "push <shell-escape><enter>"
> folder-hook +lists* "push <enter-command>source ~/.mutt/list-from<enter>"
> #v-
>
> Some explanation is in order. The gen-set-from.pl script takes the
> current mailing list mailbox name (something similar to
> "=lists.mutt-users") on the command-line, and writes the file list-from
> containing the line "set from=dave-lists-mutt-users@xxxxxxxxxxxxxxx".
>
> Right now everything works except from never gets set. I thought this
> might be because of the timing (source happening before the link is
> created), so I added a 0.5 second sleep after "list-from" generation.
> Adding the sleep did not fix the problem from never gets set because the
> source command runs before the shell finishes creating the link, but I'm
> not sure.
Hmm, I implemented a similar thing, and it worked correctly (thanks for
suggesting the whole using a script to write a mutt command to a file and
then sourcing it, since I hadn't gotten that far before).
For reference, here is exactly what I had:
in muttrc:
#get the name of the current directory in a variable, but preserve the
normal
#record setting (where to save sent messages)
folder-hook . "set my_oldrecord=\$record"
folder-hook . "set record=^"
folder-hook . "set my_curdir=\$record"
folder-hook . "set record=\$my_oldrecord"
#test, results in my_revdir containing the current folder name, reversed
folder-hook . "set shell=\"~/muttecho.sh \$my_curdir\""
folder-hook . "push <shell-escape><enter>"
folder-hook . "source ~/muttintest"
muttecho.sh takes the first command-line parameter and places a set
command to put that value into the my_revdir mutt variable:
[ -e ~/muttintest ] && rm ~/muttintest
echo set my_revdir="$1" > ~/muttintest
As I said, this works for me, and I don't have any timing issues either.
I'm curious, why the "push <enter-command>" at the beginning of the last
folder hook up above?
I never knew whether mutt ran hooks in parallel or one after the other.
Was it just a hunch you had that mutt doesn't wait for one hook to
complete before moving on to another, or do you have some documentation
which indicates this? I checked the mutt documentation but did not see
anything to that end.
--
Noah Sheppard
Assistant Computer Resource Manager
Taylor University CSE Department
nsheppar@xxxxxxxxxxxxxx