Date:        Wed, 24 Sep 2025 13:07:09 +0100
    From:        Ralph Corderoy <[email protected]>
    Message-ID:  <[email protected]>


  |     if t=%f-$$.jpeg && ln %f "$t"; then (xv "$t"; rm "$t") & fi
  |
  | But appending to it destroys its suffix which needs re-creating with
  | a hard-cording.

not so much:

    t=%f ; suf=${t##*.} ; t=${t%.${suf}} ; t="$t-$$.$suf" ; ln %f "$t" && ....

which should work given it is assuming that %f must have a suffix in
order for this to be invoked.  To allow for that to not be required is
just a little extra code, more like

    t=%f suf=; case "$t" in (*.*) suf=${t##*.}; t=${t%.${suf}};;        esac;
    t="$t-${$}${suf:+.${suf}}"; ln ...

which could be simpler if you don't mind results like /tmp/foo.jpg-1234.jpg
but not all that much simpler, and needs to be slightly more complex if
we also need to deal with the empty suffix where %f == /path/to/file. and
that '.' isn't e-mail punctuation!

Also unless there is a command substitution involved (none in any
of these variations) there's never any point in testing whether a variable
assignment worked or not (as in checking its exit status).  Those *never*
fail (unless the shell runs out of memory, in which case you're screwed),
so testing the status is pointless.   The value assigned might sometimes
not be what was hoped it would be (as in the suf=${t##*.} in my first
variation, where if there is no suffix, that becomes suf=$t rather than
suf= which would be preferred) but the exit status is still always 0 (OK).

So:

  | %-escapes for the %f's dirname, basename, and an escape
  | for the mh...-suffix-... entry could be useful.

perhaps - but definitely not required.

kre

ps: personally I prefer copying the file, doing so avoids complications
should the original file be modified to contain something different later.



Reply via email to