diff --git a/lib/cmd/cat.sh b/lib/cmd/cat.sh new file mode 100644 index 0000000..b709e60 --- /dev/null +++ b/lib/cmd/cat.sh @@ -0,0 +1,4 @@ +# usaco cat +[[ $# -ge 1 ]] || usage +dir="$(find_problem "$1")" +cat "$dir/main.cpp" diff --git a/lib/cmd/copy.sh b/lib/cmd/copy.sh new file mode 100644 index 0000000..7de2e6f --- /dev/null +++ b/lib/cmd/copy.sh @@ -0,0 +1,16 @@ +# usaco copy (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 diff --git a/usaco b/usaco index 2d4848f..a9c9727 100755 --- a/usaco +++ b/usaco @@ -11,6 +11,8 @@ # usaco skip Move solving/ -> skipped/ # usaco io [io-name] Show the problem's io name, or set it: renames .in/.out # and rewires STDIO("...") in main.cpp (adds it if missing) +# usaco cat Print the problem's main.cpp to stdout (pipeable) +# usaco copy Copy the problem's main.cpp to the clipboard (alias: cp) # usaco vim Open the problem's main.cpp in $EDITOR (aliases: edit, e) # usaco open Open the problem's saved URL in a browser # usaco list List problems by status @@ -47,6 +49,8 @@ case "$cmd" in undo|u) cmd=undo ;; skip|sk) cmd=skip ;; io) cmd=io ;; + cat) cmd=cat ;; + copy|cp) cmd=copy ;; vim|edit|e) cmd=edit ;; open|o) cmd=open ;; list|l|ls) cmd=list ;;