diff options
-rw-r--r-- | Makefile | 30 | ||||
-rwxr-xr-x | foil.sh | 83 |
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 | |||
7 | PREFIX=/usr/local | ||
8 | SCRIPT=$(PWD)/foil.sh | ||
9 | |||
10 | COPYCMD=yoink | ||
11 | PASTECMD=yeet | ||
12 | |||
13 | help: | ||
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 | |||
20 | install: $(SCRIPT) | ||
21 | install -D $< $(DESTDIR)$(PREFIX)/bin/$(COPYCMD) | ||
22 | install -D $< $(DESTDIR)$(PREFIX)/bin/$(PASTECMD) | ||
23 | |||
24 | link: $(SCRIPT) | ||
25 | ln -sf $< $(DESTDIR)$(PREFIX)/bin/$(COPYCMD) | ||
26 | ln -sf $< $(DESTDIR)$(PREFIX)/bin/$(PASTECMD) | ||
27 | |||
28 | uninstall: | ||
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 | |||
4 | t="$(mktemp)" | ||
5 | trap '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 | |||
82 | test -n "$DEBUG" && set -x | ||
83 | test -z "$SOURCE" && _main "$0" "$@" | ||