summaryrefslogtreecommitdiff
path: root/bin/scripts/cclip
diff options
context:
space:
mode:
authorA Farzat <a@farzat.xyz>2024-10-23 20:01:31 +0900
committerA Farzat <a@farzat.xyz>2024-11-04 20:01:32 +0900
commitb9f5ffd0d3ad2f5744fc6ca3b497e3278aa78f35 (patch)
tree69da499265cfc48a837cc755638aa930cd13b27c /bin/scripts/cclip
parent76d408c93ee3192d6f95d9781b7e08b36b42cb87 (diff)
downloaddotfiles-b9f5ffd0d3ad2f5744fc6ca3b497e3278aa78f35.tar.gz
dotfiles-b9f5ffd0d3ad2f5744fc6ca3b497e3278aa78f35.zip
Add a few scripts
Diffstat (limited to 'bin/scripts/cclip')
-rwxr-xr-xbin/scripts/cclip21
1 files changed, 21 insertions, 0 deletions
diff --git a/bin/scripts/cclip b/bin/scripts/cclip
new file mode 100755
index 0000000..29320ad
--- /dev/null
+++ b/bin/scripts/cclip
@@ -0,0 +1,21 @@
+#!/usr/bin/env sh
+
+# Copy text from the standard input to the clipboard.
+# If connected from an ssh session, use clipper to send back to local computer.
+# Otherwise just use xclip.
+
+# The code block checks whether it is an ssh session or not.
+# If so, SESSION_TYPE is set to remote/ssh.
+if [ -n "$SSH_CLIENT" ] || [ -n "$SSH_TTY" ]; then
+ SESSION_TYPE=remote/ssh
+else
+ case $(ps -o comm= -p "$PPID") in
+ sshd|*/sshd) SESSION_TYPE=remote/ssh;;
+ esac
+fi
+
+if [ "$SESSION_TYPE" = "remote/ssh" ]; then
+ nc -q 0 -U ~/.clipper.sock
+else
+ xclip -sel clip
+fi