From ed955bad860ce30ea6f1147150ec94c3514762f9 Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Tue, 13 Sep 2022 17:00:00 -0500 Subject: initial commit --- Makefile | 30 +++++++++++++++++++++++ foil.sh | 83 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 113 insertions(+) create mode 100644 Makefile create mode 100755 foil.sh diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..9f2c277 --- /dev/null +++ b/Makefile @@ -0,0 +1,30 @@ +# FOIL +# by C. Duckworth +# This program is free software; +# you can use it as you see fit, +# but don't hold me responsible. + +PREFIX=/usr/local +SCRIPT=$(PWD)/foil.sh + +COPYCMD=yoink +PASTECMD=yeet + +help: + @echo "FOIL: by C. Duckworth" + @echo "Makefile targets:" + @echo "install: install to $(DESTDIR)$(PREFIX)." + @echo "link: symlink to $(DESTDIR)$(PREFIX)." + @echo "uninstall: remove from $(DESTDIR)$(PREFIX)" + +install: $(SCRIPT) + install -D $< $(DESTDIR)$(PREFIX)/bin/$(COPYCMD) + install -D $< $(DESTDIR)$(PREFIX)/bin/$(PASTECMD) + +link: $(SCRIPT) + ln -sf $< $(DESTDIR)$(PREFIX)/bin/$(COPYCMD) + ln -sf $< $(DESTDIR)$(PREFIX)/bin/$(PASTECMD) + +uninstall: + -rm -f $< $(DESTDIR)$(PREFIX)/bin/$(COPYCMD) + -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 @@ +#!/bin/sh +# FOIL: copy and paste shit + +t="$(mktemp)" +trap 'rm -f "$t"' EXIT INT + +_run() { + c="$1" + shift + if command -v "$c" >/dev/null 2>&1; then + "$c" "$@" && rm "$t" + return 0 + else + return 1 + fi +} +_runs() { + _run "$@" # >/dev/null 2>&1 +} + +_copy() { + test -n "${TMUX:-}" && _run tmux load-buffer "${1:--}" + cat "${1:-/dev/stdin}" | + case "$OSTYPE" in + cygwin* | msys*) _run cat >/dev/clipboard ;; + linux-android*) + _runs termux-clipboard-set + ;; + *) + if test -n "$WAYLAND_DISPLAY"; then + _runs wl-copy + elif test -n "$DISPLAY"; then + _runs pbcopy || + _runs xsel --clipboard --input || + _runs xclip -selection clipboard -in + else + _runs lemonade copy || + _runs doitclient wclip || + _runs win32yank -i || + _runs clip.exe + fi + ;; + esac + ! test -f "$t" +} + +_paste() { + test -n "${TMUX:-}" && _run tmux save-buffer - + case "$OSTYPE" in + cygwin* | msys*) _run cat /dev/clipboard ;; + linux-android*) _run termux-clipboard-get ;; + *) + if test -n "$WAYLAND_DISPLAY"; then + _run wl-paste + elif test -n "$DISPLAY"; then + _run pbpaste || + _run xsel --clipboard --output || + _run xclip -out -selection clipboard + else + _run lemonade paste || + _run doitclient wclip -r || + _run win32yank -o || + exec powershell.exe -noprofile -command Get-Clipboard + fi + ;; + esac + ! test -f "$t" +} + +_main() { + c="$1" + shift + case "$c" in + *yoink* | *copy*) _copy "$@" ;; + *yeet* | *paste*) _paste "$@" ;; + *) + _main "$@" + ;; + esac +} + +test -n "$DEBUG" && set -x +test -z "$SOURCE" && _main "$0" "$@" -- cgit 1.4.1-21-gabe81