Browse Source

Merge pull request #69 from sdushantha/add-copy-to-clipboard

Add copy to clipboard
Siddharth Dushantha 3 years ago
parent
commit
b28789b9ea
1 changed files with 28 additions and 4 deletions
  1. 28 4
      tmpmail

+ 28 - 4
tmpmail

@@ -5,12 +5,16 @@
 # Dependencies: jq, curl, w3m
 # Dependencies: jq, curl, w3m
 #
 #
 
 
-version=1.1.9
+version=1.2.0
 
 
 # By default 'tmpmail' uses 'w3m' as it's web browser to render
 # By default 'tmpmail' uses 'w3m' as it's web browser to render
 # the HTML of the email
 # the HTML of the email
 browser="w3m"
 browser="w3m"
 
 
+# The default command that will be used to copy the email address to
+# the user's clipboard when running 'tmpmail --copy'
+copy_to_clipboard_cmd="xclip -selection c"
+
 # If the value is set to 'true' tmpmail will convert the HTML email
 # If the value is set to 'true' tmpmail will convert the HTML email
 # to raw text and send that to stdout
 # to raw text and send that to stdout
 raw_text=false
 raw_text=false
@@ -48,8 +52,13 @@ the inbox and their numeric IDs.  When called with one argument, tmpmail
 shows the email message with specified ID.
 shows the email message with specified ID.
 
 
 -b, --browser BROWSER
 -b, --browser BROWSER
-        Specify BROWSER (default: w3m) that is used to render the HTML of
-        the email
+        Specify BROWSER that is used to render the HTML of
+        the email (default: w3m)
+    --clipboard-cmd COMMAND
+        Specify the COMMAND to use for copying the email address to your
+        clipboard (default: xclip -selection c)
+-c, --copy
+        Copy the email address to your clipboard
 -g, --generate [ADDRESS]
 -g, --generate [ADDRESS]
         Generate a new email address, either the specified ADDRESS, or
         Generate a new email address, either the specified ADDRESS, or
         randomly create one
         randomly create one
@@ -279,6 +288,11 @@ view_recent_email() {
     view_email "$mail_id"
     view_email "$mail_id"
 }
 }
 
 
+copy_email_to_clipboard(){
+    # Copy the email thats being used to the user's clipboard
+    $copy_to_clipboard_cmd < $tmpmail_email_address
+}
+
 die() {
 die() {
     # Print error message and exit
     # Print error message and exit
     #
     #
@@ -297,7 +311,15 @@ main() {
     # dep_missing allows us to keep track of how many dependencies the user is missing
     # dep_missing allows us to keep track of how many dependencies the user is missing
     # and then print out the missing dependencies once the checking is done.
     # and then print out the missing dependencies once the checking is done.
     dep_missing=""
     dep_missing=""
-    for dependency in jq $browser curl; do
+
+    # The main command from $copy_to_clipboard_cmd
+    # Example:
+    #   xclip -selection c
+    #   ├───┘
+    #   └ This part
+    clipboard=${copy_to_clipboard_cmd%% *}
+
+    for dependency in jq $browser $clipboard curl; do
         if ! command -v "$dependency" >/dev/null 2>&1; then
         if ! command -v "$dependency" >/dev/null 2>&1; then
             # Append to our list of missing dependencies
             # Append to our list of missing dependencies
             dep_missing="$dep_missing $dependency"
             dep_missing="$dep_missing $dependency"
@@ -333,6 +355,8 @@ main() {
         case "$1" in
         case "$1" in
             --help | -h) usage && exit ;;
             --help | -h) usage && exit ;;
             --generate | -g) generate_email_address true "$2" && exit ;;
             --generate | -g) generate_email_address true "$2" && exit ;;
+            --clipboard-cmd) copy_to_clipboard_cmd="$2" ;;
+            --copy | -c) copy_email_to_clipboard && exit ;;
             --browser | -b) browser="$2" ;;
             --browser | -b) browser="$2" ;;
             --text | -t) raw_text=true ;;
             --text | -t) raw_text=true ;;
             --version) echo "$version" && exit ;;
             --version) echo "$version" && exit ;;