4 ms·
I have linux/macos-agnostic bash functions in my dotfiles that unify this to “clip” and “paste” (since “copy” is too close semantically to “cp”)
by pmarreck 3y ago
I have linux/macos-agnostic bash functions in my dotfiles that unify this to “clip” and “paste” (since “copy” is too close semantically to “cp”)
- kps 3y agopaste(1) is a POSIX standard utility, though (going back to System III), pairing with cut(1). https://pubs.opengroup.org/onlinepubs/9699919799/utilities/paste.html https://pubs.opengroup.org/onlinepubs/9699919799/utilities/p...
- vram22 3y agoThe Unix join command is also useful: https://en.m.wikipedia.org/wiki/Join_(Unix) https://en.m.wikipedia.org/wiki/Join_(Unix)
- svieira 3y agoAnd I have one that unifies _both_ to `clip` so you can put the same command in both sides of the pipe, e. g. to turn a line-delimited blob on your clipboard to a space-separated one: clip | tr '\n' ' ' | clip https://github.com/svieira/dotfiles/blob/a3654d6a194e36899787aa7850f4a9a23617c64f/functions#L136-L141 https://github.com/svieira/dotfiles/blob/a3654d6a194e3689978... # Use clipboard in shell pipelines # clip | xargs echo # uses pbpaste # ps -A | grep search | clip # uses pbcopy clip() { [ -t 0 ] && pbpaste || pbcopy }
- pmarreck 3y agoHoly crap. Of course! You win! Amazing! Simple is genius
- pmarreck 3y agoSo to check if there's anything sitting on stdin without reading it I've been using `if read -r -t0; then` # returns true if there is data but times out instantly so it doesn't consume any Is `[ -t 0 ]` more idiomatic? Apparently it fails on this case: function < file `read -r -t0` is Bash-only though and not POSIX, but it will work regardless of what type of data is on stdin
- naniwaduni 3y ago[ -t 0 ] instead checks whether stdin (fd 0) is a tty.