Make xc/xs read from stdin by default, if it's not a terminal

This commit is contained in:
Alexander Gehrke 2020-01-08 11:16:11 +01:00
parent cefd40b6dc
commit 21e3cf65e6

5
bin/xc
View file

@ -30,12 +30,13 @@ function common() {
shift 3 shift 3
case "$cmd" in case "$cmd" in
"read") $setc;; "read") $setc;;
"clear") echo -n | $setc;;
"readboth") read_both ;; "readboth") read_both ;;
"showboth") show_both ;; "showboth") show_both ;;
"sed") $getc | sed -e "$@" | $setc; $getc;; "sed") $getc | sed -e "$@" | $setc; $getc;;
"pipe") $getc | "$@" | $setc; $getc;; "pipe") $getc | "$@" | $setc; $getc;;
"edit") need vipe moreutils; $getc | vipe | $setc; $getc;; "edit") need vipe moreutils; $getc | vipe | $setc; $getc;;
"") $getc ;; "") if [[ -t 0 ]]; then $getc; else $setc; fi;;
*) <<-HELP *) <<-HELP
Usage: xc [COMMAND] Usage: xc [COMMAND]
xc fromxs|toxs xc fromxs|toxs
@ -49,7 +50,7 @@ function common() {
Commands: Commands:
show/showboth: show contents of clipboard (default if no command given) show/showboth: show contents of clipboard (default if no command given)
read/readboth: store input to clipboard read/readboth: store input to clipboard (default if stdin is not a terminal)
sed: modify contents using a sed expression sed: modify contents using a sed expression
pipe: modify contents by piping through a command pipe: modify contents by piping through a command
edit: edit clipboard contents using \$EDITOR edit: edit clipboard contents using \$EDITOR