diff --git a/README.md b/README.md index a19a3e7..92a8645 100644 --- a/README.md +++ b/README.md @@ -42,12 +42,13 @@ You can grab one from: https://resend.com/api-keys. ### Environment -To avoid typing your `From: ` email address, you can also set the `RESEND_FROM` +To avoid typing your `From: ` email address, you can also set the `POP_FROM` environment to pre-fill the field anytime you launch `pop`. ```bash export RESEND_API_KEY=$(pass RESEND_API_KEY) -export RESEND_FROM=pop@charm.sh +export POP_FROM=pop@charm.sh +export POP_SIGNATURE="Sent with [Pop](https://github.com/charmbracelet/pop)!" ``` ## Installation diff --git a/main.go b/main.go index a70d267..696c87d 100644 --- a/main.go +++ b/main.go @@ -12,7 +12,8 @@ import ( ) const RESEND_API_KEY = "RESEND_API_KEY" -const RESEND_FROM = "RESEND_FROM" +const POP_FROM = "POP_FROM" +const POP_SIGNATURE = "POP_SIGNATURE" var ( from string @@ -21,6 +22,7 @@ var ( body string attachments []string preview bool + signature string ) var rootCmd = &cobra.Command{ @@ -42,6 +44,10 @@ var rootCmd = &cobra.Command{ body = string(b) } + if signature != "" { + body += "\n\n" + signature + } + if len(to) > 0 && from != "" && subject != "" && body != "" && !preview { err := sendEmail(to, from, subject, body, attachments) if err != nil { @@ -85,9 +91,12 @@ func init() { rootCmd.Flags().StringSliceVarP(&attachments, "attach", "a", []string{}, "Email's attachments") rootCmd.Flags().StringSliceVarP(&to, "to", "t", []string{}, "Recipients") rootCmd.Flags().StringVarP(&body, "body", "b", "", "Email's contents") - rootCmd.Flags().StringVarP(&from, "from", "f", os.Getenv(RESEND_FROM), "Email's sender "+commentStyle.Render("($RESEND_FROM)")) + envFrom := os.Getenv(POP_FROM) + rootCmd.Flags().StringVarP(&from, "from", "f", envFrom, "Email's sender "+commentStyle.Render("($"+POP_FROM+")")) rootCmd.Flags().StringVarP(&subject, "subject", "s", "", "Email's subject") rootCmd.Flags().BoolVarP(&preview, "preview", "p", false, "Whether to preview the email before sending") + envSignature := os.Getenv("POP_SIGNATURE") + rootCmd.Flags().StringVarP(&signature, "signature", "x", envSignature, "Signature to display at the end of the email. "+commentStyle.Render("($"+POP_SIGNATURE+")")) } func main() { diff --git a/model.go b/model.go index b035883..e593fde 100644 --- a/model.go +++ b/model.go @@ -101,6 +101,11 @@ func NewModel(defaults resend.SendEmailRequest) Model { body.Cursor.Style = cursorStyle body.CharLimit = 4000 body.SetValue(defaults.Text) + + // Adjust for signature (if none, this is a no-op) + body.CursorUp() + body.CursorUp() + body.Blur() // Decide which input to focus.