about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorCase Duckworth2022-09-13 17:00:00 -0500
committerCase Duckworth2022-09-13 17:00:00 -0500
commited955bad860ce30ea6f1147150ec94c3514762f9 (patch)
treef7a6120a01e938d7470faa20c4e07b283b413208
downloadfoil-ed955bad860ce30ea6f1147150ec94c3514762f9.tar.gz
foil-ed955bad860ce30ea6f1147150ec94c3514762f9.zip
initial commit
-rw-r--r--Makefile30
-rwxr-xr-xfoil.sh83
2 files changed, 113 insertions, 0 deletions
diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..9f2c277 --- /dev/null +++ b/Makefile
@@ -0,0 +1,30 @@
1# FOIL
2# by C. Duckworth <acdw@acdw.net>
3# This program is free software;
4# you can use it as you see fit,
5# but don't hold me responsible.
6
7PREFIX=/usr/local
8SCRIPT=$(PWD)/foil.sh
9
10COPYCMD=yoink
11PASTECMD=yeet
12
13help:
14 @echo "FOIL: by C. Duckworth"
15 @echo "Makefile targets:"
16 @echo "install: install to $(DESTDIR)$(PREFIX)."
17 @echo "link: symlink to $(DESTDIR)$(PREFIX)."
18 @echo "uninstall: remove from $(DESTDIR)$(PREFIX)"
19
20install: $(SCRIPT)
21 install -D $< $(DESTDIR)$(PREFIX)/bin/$(COPYCMD)
22 install -D $< $(DESTDIR)$(PREFIX)/bin/$(PASTECMD)
23
24link: $(SCRIPT)
25 ln -sf $< $(DESTDIR)$(PREFIX)/bin/$(COPYCMD)
26 ln -sf $< $(DESTDIR)$(PREFIX)/bin/$(PASTECMD)
27
28uninstall:
29 -rm -f $< $(DESTDIR)$(PREFIX)/bin/$(COPYCMD)
30 -rm -f $< $(DESTDIR)$(PREFIX)/bin/$(PASTECMD)
diff --git a/foil.sh b/foil.sh new file mode 100755 index 0000000..e4a438f --- /dev/null +++ b/foil.sh
@@ -0,0 +1,83 @@
1#!/bin/sh
2# FOIL: copy and paste shit
3
4t="$(mktemp)"
5trap 'rm -f "$t"' EXIT INT
6
7_run() {
8 c="$1"
9 shift
10 if command -v "$c" >/dev/null 2>&1; then
11 "$c" "$@" && rm "$t"
12 return 0
13 else
14 return 1
15 fi
16}
17_runs() {
18 _run "$@" # >/dev/null 2>&1
19}
20
21_copy() {
22 test -n "${TMUX:-}" && _run tmux load-buffer "${1:--}"
23 cat "${1:-/dev/stdin}" |
24 case "$OSTYPE" in
25 cygwin* | msys*) _run cat >/dev/clipboard ;;
26 linux-android*)
27 _runs termux-clipboard-set
28 ;;
29 *)
30 if test -n "$WAYLAND_DISPLAY"; then
31 _runs wl-copy
32 elif test -n "$DISPLAY"; then
33 _runs pbcopy ||
34 _runs xsel --clipboard --input ||
35 _runs xclip -selection clipboard -in
36 else
37 _runs lemonade copy ||
38 _runs doitclient wclip ||
39 _runs win32yank -i ||
40 _runs clip.exe
41 fi
42 ;;
43 esac
44 ! test -f "$t"
45}
46
47_paste() {
48 test -n "${TMUX:-}" && _run tmux save-buffer -
49 case "$OSTYPE" in
50 cygwin* | msys*) _run cat /dev/clipboard ;;
51 linux-android*) _run termux-clipboard-get ;;
52 *)
53 if test -n "$WAYLAND_DISPLAY"; then
54 _run wl-paste
55 elif test -n "$DISPLAY"; then
56 _run pbpaste ||
57 _run xsel --clipboard --output ||
58 _run xclip -out -selection clipboard
59 else
60 _run lemonade paste ||
61 _run doitclient wclip -r ||
62 _run win32yank -o ||
63 exec powershell.exe -noprofile -command Get-Clipboard
64 fi
65 ;;
66 esac
67 ! test -f "$t"
68}
69
70_main() {
71 c="$1"
72 shift
73 case "$c" in
74 *yoink* | *copy*) _copy "$@" ;;
75 *yeet* | *paste*) _paste "$@" ;;
76 *)
77 _main "$@"
78 ;;
79 esac
80}
81
82test -n "$DEBUG" && set -x
83test -z "$SOURCE" && _main "$0" "$@"