Files
usaco/lib/cmd/copy.sh
T
2026-09-24 12:51:33 +01:00

17 lines
633 B
Bash

# usaco copy <name> (alias: cp)
# Copies the problem's main.cpp to the clipboard.
# Wayland: wl-copy; X11: xclip/xsel; last resort OSC52 escape (works over SSH).
[[ $# -ge 1 ]] || usage
dir="$(find_problem "$1")"
if [[ -n ${WAYLAND_DISPLAY:-} ]] && command -v wl-copy >/dev/null 2>&1; then
wl-copy < "$dir/main.cpp"
elif command -v xclip >/dev/null 2>&1; then
xclip -selection clipboard < "$dir/main.cpp"
elif command -v xsel >/dev/null 2>&1; then
xsel -b --input < "$dir/main.cpp"
else
# OSC52: terminal-native clipboard, also works through SSH
base64 -w0 < "$dir/main.cpp" | printf '\e]52;c;%s\a' "$(cat)"
fi