aboutsummaryrefslogtreecommitdiffstats
path: root/lpass_copy.sh
diff options
context:
space:
mode:
authorJoursoir <chat@joursoir.net>2020-10-28 14:12:54 +0000
committerJoursoir <chat@joursoir.net>2020-10-28 14:12:54 +0000
commit38a3be4a3eeacec75a534fef6951b9484b4d7098 (patch)
tree31c6f709d1d9ab45487bb2cd844f4969e002e24e /lpass_copy.sh
parentc992bb4c7cc230eff246f5368b7fc765750eec5b (diff)
downloadlock-password-38a3be4a3eeacec75a534fef6951b9484b4d7098.tar.gz
lock-password-38a3be4a3eeacec75a534fef6951b9484b4d7098.tar.bz2
lock-password-38a3be4a3eeacec75a534fef6951b9484b4d7098.zip
feature: copy password to clipboard
Diffstat (limited to 'lpass_copy.sh')
-rwxr-xr-xlpass_copy.sh24
1 files changed, 24 insertions, 0 deletions
diff --git a/lpass_copy.sh b/lpass_copy.sh
new file mode 100755
index 0000000..9499dec
--- /dev/null
+++ b/lpass_copy.sh
@@ -0,0 +1,24 @@
+#!/usr/bin/env bash
+
+error() {
+ echo "$@"
+ exit 1
+}
+
+if [[ -z $1 ]]; then
+ error "Error: nothing to copy"
+fi
+
+if [[ -n $WAYLAND_DISLPLAY ]]; then
+ command=(wl-copy)
+ if [[ $X_SELECTION == primary ]]; then
+ command+=( --primary )
+ fi
+elif [[ -n $DISPLAY ]]; then
+ command=(xclip -selection clipboard)
+else
+ error "Error: X11 or Wayland display were not detected"
+fi
+
+echo "$1" | "${command[@]}" || error "Error: failed to copy data to clipboard"
+echo "Password copied to clipboard." \ No newline at end of file