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

Re: detect from mailcap whether called for view or reply



On 30Jan2009 20:06, Aron Griffis <agriffis@xxxxxxxxx> wrote:
| Cameron Simpson wrote:  [Fri Jan 30 2009, 07:35:27PM EST]
| > You could get your reply keystroke macro to set some state before commencing
| > the reply, for example. Untested (and this hould be one line):
| > 
| >   macro index,pager r '<shell-escape>touch 
$HOME/var/flag/80-cols<enter><reply><shell-escape>rm -f 
$HOME/var/flag/80-cols<enter>'
| 
| Heh, I'd briefly thought about this, just couldn't stomach
| implementing it.  Thanks for the suggestion. :-)

Personally, I have a "flag" command (which I have attached), thus:

  % flag
  mail-despam-RUNNING   TRUE
  mail-despam-SA        TRUE
  % flag FOO 1
  % flag FOO && echo YES || echo NO
  YES
  % flag FOO 0
  % flag FOO && echo YES || echo NO
  NO
  % if flag FOO; then echo FOO; else echo BAR; fi
  BAR

It does the above, but abstracts it nicely. It certainly makes for
readable scripts with behaviour based on "global" Booleans.
It accepts "true" (or "TRUE") or 1 and "false"/"FALSE"/0.

You can then solve the "concurrent-mutts" issue with suitable flag
names, should it be an issue.

So:

  macro index,pager r '<shell-escape>flag DISPLAY_TTY_WIDTH 
0<enter><reply><shell-escape>flag DISPLAY_TTY_WIDTH 1<enter>'

which at least doesn't read as clunkily.

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

The trouble with the rat-race is, even if you win, you're still a rat.
        - James Youngman <JYoungman@xxxxxxxxx>
#!/bin/sh -u
#
# Simple boolean states kept as files.
#       - Cameron Simpson <cs@xxxxxxxxxx> 25sep2006
#

flagdir=$HOME/var/flags
invert=

cmd=$0
usage="Usage: $0 [-d flagdir] [!] flagname [true|false|0|1]"

badopts=

[ $# -gt 0 ] && [ "x$1" = x-d ] && { flagdir=$2; shift; shift; }
[ $# -gt 0 ] && [ "x$1" = x!  ] && { invert=1; shift; }

if [ $# = 0 ]
then
  cd "$flagdir" || exit 1
  for flag in *
  do
    if flag "$flag"
    then  echo "$flag   TRUE"
    else  echo "$flag   FALSE"
    fi
  done
  exit 0
fi

flagname=$1
shift
case "$flagname" in
  '' | */* | . | .. )
    echo "$cmd: illegal flagname: $flagname" >&2
    badopts=1
    ;;
esac
if [ $# = 0 ]
then
  setstate=
else
  setstate=1
  value=$1
  shift
  case "$value" in
    [Tt][Rr][Uu][Ee]|1)
        newstate=1 ;;
    [Ff][Aa][Ll][Ss][Ee]|0)
        newstate= ;;
    *)  echo "$cmd: unsupported value: $value" >&2
        badopts=1
        ;;
  esac
  [ $invert ] && { echo "$cmd: can't use ! (invert) while setting flag" >&2
                   badopts=1
                 }
  [ $# = 0 ] || { echo "$cmd: extra arguments after value: $*" >&2
                  badopts=1
                }
fi

[ $badopts ] && { echo "$usage" >&2; exit 2; }

flagfile=$flagdir/$flagname

if [ $setstate ]
then
  [ -d "$flagdir/." ] || needdir "$flagdir" || exit 1
  if [ $newstate ]
  then  echo 1 >"$flagfile" || exit 1
  else  : >"$flagfile"      || exit 1
  fi
  exit 0
fi

if [ -s "$flagfile" ]
then  [ $invert ] && exit 1
      exit 0
else  [ $invert ] && exit 0
      exit 1
fi