Browse Source

ix: copy response to clipboard

DanielFGray 2 years ago
parent
commit
7c6d1d1795
1 changed files with 14 additions and 10 deletions
  1. 14
    10
      ix

+ 14
- 10
ix View File

@@ -45,10 +45,7 @@ select_from() {
45 45
   local cmd='command -v'
46 46
   for a; do
47 47
     case "$a" in
48
-      -c)
49
-        cmd="$2"
50
-        shift 2
51
-        ;;
48
+      -c) cmd="$2"; shift 2 ;;
52 49
     esac
53 50
   done
54 51
   for c; do
@@ -68,9 +65,10 @@ create_account() {
68 65
   echo "It seems you don't have a ~/.netrc with ix.io in it. Let's make one!"
69 66
   read -r -p 'enter a username: ' username
70 67
   read -rs -p 'enter a password (this will be hashed with sha256sum): ' password
71
-  password=$(sha256sum <<< "$password" | awk '{print $1}')
72 68
   echo ''
73
-  echo "machine ix.io login $username password $password" >> ~/.netrc
69
+  password=$(sha256sum <<< "$password")
70
+  password="${password/%  -}"
71
+  printf "machine ix.io login %s password %s" "$username" "$password" >> ~/.netrc
74 72
   chmod 600 ~/.netrc
75 73
   if has_account; then
76 74
     echo 'success!'
@@ -126,8 +124,8 @@ while getopts ":hld:i:n:" x; do
126 124
     h) usage; exit ;;
127 125
     d) curl -s "${opts[@]}" -X DELETE "$OPTARG"; exit ;;
128 126
     l)
129
-      if [[ -z "$OPTARG" && -e ~/.netrc ]]; then
130
-        list_pastes | cut -d' ' -f1 | tee /dev/tty | xclip
127
+      if [[ -e ~/.netrc ]]; then
128
+        list_pastes | cut -d' ' -f1 | xclip
131 129
       else
132 130
         die 'no netrc found'
133 131
       fi
@@ -136,13 +134,19 @@ while getopts ":hld:i:n:" x; do
136 134
     n) opts+=( -F "read:1=$OPTARG" ) ;;
137 135
   esac
138 136
 done
139
-shift $(( OPTIND - 1))
137
+shift $(( OPTIND - 1 ))
140 138
 
141 139
 if [[ -t 0 ]]; then
142 140
   if [[ -n "$1" ]]; then
143 141
     filename="$1"
144 142
     shift
145
-    curl "${opts[@]}" -F f:1=@"$filename" "$@" "ix.io/$id"
143
+    response=$(curl "${opts[@]}" -F f:1=@"$filename" "$@" "ix.io/$id")
144
+    clipboard=$(select_from 'xclip' 'xsel')
145
+    if [[ -n "$clipboard" ]]; then
146
+      tee <<< "$response" | $clipboard
147
+    else
148
+      echo "$response"
149
+    fi
146 150
     exit
147 151
   fi
148 152
   echo "^C to cancel, ^D to send."

Loading…
Cancel
Save