Created
July 30, 2015 21:17
-
-
Save erichs/573b15e127bbec235498 to your computer and use it in GitHub Desktop.
pb - DWIM clipboard manipulation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| pb() { | |
| if [[ -p /dev/stdin ]]; then # STDIN is attached to a pipe | |
| pbcopy | |
| fi | |
| if [[ ! -t 0 && ! -p /dev/stdin ]]; then # STDIN is attached to a redirect | |
| pbcopy | |
| fi | |
| if [[ -t 1 ]]; then # STDOUT is attached to a TTY | |
| if [[ -t 0 ]]; then # STDIN is attached to TTY | |
| pbpaste | |
| fi | |
| fi | |
| if [[ -p /dev/stdout ]]; then # STDOUT is attached to a pipe | |
| pbpaste | |
| fi | |
| if [[ ! -t 1 && ! -p /dev/stdout ]]; then # STDOUT is attached to a redirection | |
| pbpaste | |
| fi | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You'll need to source the above to use it as a command:
pbcould be used like: