Subject: tested :-) macros for Bourne/Ksh/Bash _and_ Csh/Tcsh

From: [email-masked] (Clark O. Morgan)
Date: Wed, 15 Jan 1997 12:30:29 -0800

Documentation has been expanded.
I posted this to comp.editors as well.

; Included below are 4 vile macros to sign buffers with PGP 2.6.2 plain
; text signatures.  One use for these macros is to sign e-mail messages
; or USENET postings.  When selecting one or more of the macros below, 
; choose based on these criteria:
;   - type of shell specified in $SHELL
;   - whether or not the buffer contains message headers (at top of 
;     buffer) that are separated from message body by a blank line.  
;     Some mail user agents expose headers to the end user (e.g., mush)
;     and others do not (elm).  If you post USENET messages via Pnews,
;     message headers are included in the buffer.
;
; All macros use the same principle:
;   - prompts for PGP pass phrase for user Clark (change this user id
;     as appropriate for your application)
;   - places pass phrase at appropriate point in buffer
;   - filters buffer to pgp and forces pgp to read passphrase from buffer.

; Buffer signed from the first blank line of the buffer to end-of-file.  
; Macro applicable to Bourne shell and derivatives (ksh, bash, etc).  
; Macro elides all pgp stderr output and so if something goes wrong 
; (e.g., passphrase typo), you get to figure out what happened.  Look at 
; csh-based macros below for a (slower) method that leaves error messages 
; in the buffer if pgp fails.
19 store-macro
    set-variable %phrase &cat @"PGP PassPhrase? " "\n"
    write-message " "  ; erase passphrase
    set-variable %var "PGPPASSFD=0; export PGPPASSFD;"
    set-variable %cmd &cat %var "pgp -fsta -u Clark 2>/dev/null"
    beginning-of-file
    search-forward "^[ \t]*$"
    ~force down-line
    insert-string %phrase
    ~force up-line-at-bol
    filter-til end-of-file %cmd
~endm
bind-key execute-macro-19 #-s   ; invoke with the keystroke #s

;
; Same macro as above, except that the entire buffer is signed.
;
20 store-macro
    set-variable %phrase &cat @"PGP PassPhrase? " "\n"
    write-message " "  ; erase passphrase
    set-variable %var "PGPPASSFD=0; export PGPPASSFD;"
    set-variable %cmd &cat %var "pgp -fsta -u Clark 2>/dev/null"
    beginning-of-file
    insert-string %phrase
    ~force up-line-at-bol
    filter-til end-of-file %cmd
~endm
bind-key execute-macro-20 #-S   ; invoke with the keystroke #S

; Buffer signed from the first blank line of the buffer to end-of-file.  
; Macro applicable to csh and its derivatives (tcsh, etc).  Due to 
; inherent limitations in csh commandline syntax, this macro reads all 
; pgp output (stdout & stderr) and then filters it.  Consequently, if 
; something goes wrong (e.g., passphrase typo), the pgp error msg is 
; retained in the buffer.
21 store-macro
    set-variable %phrase &cat @"PGP PassPhrase? " "\n"
    write-message " "  ; erase passphrase
    set-variable %var "setenv PGPPASSFD 0;"
    set-variable %cmd &cat %var "pgp -fsta -u Clark"
    beginning-of-file
    search-forward "^[ \t]*$"
    set-named-mark q
    ~force down-line
    insert-string %phrase
    ~force up-line-at-bol
    filter-til end-of-file %cmd
    goto-named-mark q
    down-line
    ~force delete-til search-forward "--*BEGIN PGP SIGNED MESSAGE"
~endm
bind-key execute-macro-21 #-t   ; invoke with the keystroke #t

;
; Same macro as above, except that the entire buffer is signed.
;
22 store-macro
    set-variable %phrase &cat @"PGP PassPhrase? " "\n"
    write-message " "  ; erase passphrase
    set-variable %var "setenv PGPPASSFD 0;"
    set-variable %cmd &cat %var "pgp -fsta -u Clark"
    beginning-of-file
    insert-string %phrase
    ~force up-line-at-bol
    filter-til end-of-file %cmd
    beginning-of-file
    ~force delete-til search-forward "--*BEGIN PGP SIGNED MESSAGE"
~endm
bind-key execute-macro-22 #-T   ; invoke with the keystroke #T

Documentation has been expanded.
I posted this to comp.editors as well.

; Included below are 4 vile macros to sign buffers with PGP 2.6.2 plain
; text signatures.  One use for these macros is to sign e-mail messages
; or USENET postings.  When selecting one or more of the macros below, 
; choose based on these criteria:
;   - type of shell specified in $SHELL
;   - whether or not the buffer contains message headers (at top of 
;     buffer) that are separated from message body by a blank line.  
;     Some mail user agents expose headers to the end user (e.g., mush)
;     and others do not (elm).  If you post USENET messages via Pnews,
;     message headers are included in the buffer.
;
; All macros use the same principle:
;   - prompts for PGP pass phrase for user Clark (change this user id
;     as appropriate for your application)
;   - places pass phrase at appropriate point in buffer
;   - filters buffer to pgp and forces pgp to read passphrase from buffer.

; Buffer signed from the first blank line of the buffer to end-of-file.  
; Macro applicable to Bourne shell and derivatives (ksh, bash, etc).  
; Macro elides all pgp stderr output and so if something goes wrong 
; (e.g., passphrase typo), you get to figure out what happened.  Look at 
; csh-based macros below for a (slower) method that leaves error messages 
; in the buffer if pgp fails.
19 store-macro
    set-variable %phrase &cat @"PGP PassPhrase? " "\n"
    write-message " "  ; erase passphrase
    set-variable %var "PGPPASSFD=0; export PGPPASSFD;"
    set-variable %cmd &cat %var "pgp -fsta -u Clark 2>/dev/null"
    beginning-of-file
    search-forward "^[ \t]*$"
    ~force down-line
    insert-string %phrase
    ~force up-line-at-bol
    filter-til end-of-file %cmd
~endm
bind-key execute-macro-19 #-s   ; invoke with the keystroke #s

;
; Same macro as above, except that the entire buffer is signed.
;
20 store-macro
    set-variable %phrase &cat @"PGP PassPhrase? " "\n"
    write-message " "  ; erase passphrase
    set-variable %var "PGPPASSFD=0; export PGPPASSFD;"
    set-variable %cmd &cat %var "pgp -fsta -u Clark 2>/dev/null"
    beginning-of-file
    insert-string %phrase
    ~force up-line-at-bol
    filter-til end-of-file %cmd
~endm
bind-key execute-macro-20 #-S   ; invoke with the keystroke #S

; Buffer signed from the first blank line of the buffer to end-of-file.  
; Macro applicable to csh and its derivatives (tcsh, etc).  Due to 
; inherent limitations in csh commandline syntax, this macro reads all 
; pgp output (stdout & stderr) and then filters it.  Consequently, if 
; something goes wrong (e.g., passphrase typo), the pgp error msg is 
; retained in the buffer.
21 store-macro
    set-variable %phrase &cat @"PGP PassPhrase? " "\n"
    write-message " "  ; erase passphrase
    set-variable %var "setenv PGPPASSFD 0;"
    set-variable %cmd &cat %var "pgp -fsta -u Clark"
    beginning-of-file
    search-forward "^[ \t]*$"
    set-named-mark q
    ~force down-line
    insert-string %phrase
    ~force up-line-at-bol
    filter-til end-of-file %cmd
    goto-named-mark q
    down-line
    ~force delete-til search-forward "--*BEGIN PGP SIGNED MESSAGE"
~endm
bind-key execute-macro-21 #-t   ; invoke with the keystroke #t

;
; Same macro as above, except that the entire buffer is signed.
;
22 store-macro
    set-variable %phrase &cat @"PGP PassPhrase? " "\n"
    write-message " "  ; erase passphrase
    set-variable %var "setenv PGPPASSFD 0;"
    set-variable %cmd &cat %var "pgp -fsta -u Clark"
    beginning-of-file
    insert-string %phrase
    ~force up-line-at-bol
    filter-til end-of-file %cmd
    beginning-of-file
    ~force delete-til search-forward "--*BEGIN PGP SIGNED MESSAGE"
~endm
bind-key execute-macro-22 #-T   ; invoke with the keystroke #T