-
-
Save evil5hadow/a55ce980ec79c44cadd061774d5b40d0 to your computer and use it in GitHub Desktop.
Revisions
-
RichardBronosky revised this gist
Dec 12, 2018 . 1 changed file with 7 additions and 3 deletions.There are no files selected for viewing
This file contains 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 charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,4 @@ # cb ## A leak-proof tee to the clipboard @@ -11,8 +12,9 @@ It's like your normal copy and paste commands, but unified and able to sense whe ### Copy ```bash $ echo -n $(date) | cb # clipboard contains: Tue Jan 24 23:00:00 EST 2017 # but, because of `echo -n` there is no newline at the end ``` ### Paste @@ -21,9 +23,11 @@ $ date | cb # clipboard retained from the previous block $ cb Tue Jan 24 23:00:00 EST 2017 # above there is a newline after the output for readability # below there is no newline because cb recognized that it was outputing to a pipe and any alterations would "contaminate" the data $ cb | cat Tue Jan 24 23:00:00 EST 2017$ cb > foo # look carefully at this ^^ that's a new $ prompt at the end of the content exactly as copied $ cat foo Tue Jan 24 23:00:00 EST 2017 ``` -
draketyl revised this gist
Nov 27, 2018 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains 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 charactersOriginal file line number Diff line number Diff line change @@ -18,7 +18,7 @@ else t1=0 fi if [[ -f /proc/version ]] && grep -q Microsoft /proc/version; then os="WSL" else unameOut="$(uname -s)" -
draketyl revised this gist
Nov 27, 2018 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
Empty file. -
RichardBronosky revised this gist
Aug 3, 2018 . 4 changed files with 75 additions and 117 deletions.There are no files selected for viewing
This file contains 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,75 @@ #!/bin/bash if [[ -p /dev/stdin ]]; then # stdin is a pipe p0=1 else p0=0 fi if [[ -t 0 ]]; then # stdin is a tty t0=1 else t0=0 fi if [[ -t 1 ]]; then # stdout is a tty t1=1 else t1=0 fi if grep -q Microsoft /proc/version; then os="WSL" else unameOut="$(uname -s)" case "${unameOut}" in Linux*) os=LINUX;; Darwin*) os=MAC;; CYGWIN*) os=CYGWIN;; esac fi LINUX_copy(){ cat | xclip -selection clipboard } LINUX_paste(){ xclip -selection clipboard -o } WSL_copy(){ cat | /mnt/c/Windows/System32/clip.exe } WSL_paste(){ /mnt/c/Windows/System32/WindowsPowerShell/v1.0/powershell.exe Get-Clipboard | sed 's/\r//' } CYGWIN_copy(){ cat > /dev/clipboard } CYGWIN_paste(){ cat /dev/clipboard } MAC_copy(){ cat | pbcopy } MAC_paste(){ pbpaste } if [[ $p0 -eq 1 || $t0 -eq 0 ]]; then # stdin is pipe-ish ${os}_copy # so send it to the clipboard if [[ $t1 -eq 0 ]]; then # also, stdout is not a tty (meaning it must be a pipe or redirection) ${os}_paste # so pass that pipe/redirection the content of the clipboard (enables `man tee` like chaining) fi else # stdin is not a pipe ${os}_paste # so output the clipboard if [[ $t1 -eq 1 ]]; then # stdout is a tty (so we don't have to be strict about not altering the output) echo # prevent the prompt from being on the same line fi fi This file contains 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 charactersOriginal file line number Diff line number Diff line change @@ -1,39 +0,0 @@ This file contains 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 charactersOriginal file line number Diff line number Diff line change @@ -1,39 +0,0 @@ This file contains 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 charactersOriginal file line number Diff line number Diff line change @@ -1,39 +0,0 @@ -
RichardBronosky revised this gist
Aug 3, 2018 . 3 changed files with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes.File renamed without changes.File renamed without changes. -
RichardBronosky revised this gist
Jun 26, 2017 . 3 changed files with 36 additions and 12 deletions.There are no files selected for viewing
This file contains 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 charactersOriginal file line number Diff line number Diff line change @@ -18,14 +18,22 @@ else t1=0 fi _copy(){ cat > /dev/clipboard } _paste(){ cat /dev/clipboard } if [[ $p0 -eq 1 || $t0 -eq 0 ]]; then # stdin is pipe-ish _copy # so send it to the clipboard if [[ $t1 -eq 0 ]]; then # also, stdout is not a tty (meaning it must be a pipe or redirection) _paste # so pass that pipe/redirection the content of the clipboard (enables `man tee` like chaining) fi else # stdin is not a pipe _paste # so output the clipboard if [[ $t1 -eq 1 ]]; then # stdout is a tty (so we don't have to be strict about not altering the output) echo # prevent the prompt from being on the same line fi fi This file contains 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 charactersOriginal file line number Diff line number Diff line change @@ -18,14 +18,22 @@ else t1=0 fi _copy(){ cat | xclip -selection clipboard } _paste(){ xclip -selection clipboard -o } if [[ $p0 -eq 1 || $t0 -eq 0 ]]; then # stdin is pipe-ish _copy # so send it to the clipboard if [[ $t1 -eq 0 ]]; then # also, stdout is not a tty (meaning it must be a pipe or redirection) _paste # so pass that pipe/redirection the content of the clipboard (enables `man tee` like chaining) fi else # stdin is not a pipe _paste # so output the clipboard if [[ $t1 -eq 1 ]]; then # stdout is a tty (so we don't have to be strict about not altering the output) echo # prevent the prompt from being on the same line fi fi This file contains 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 charactersOriginal file line number Diff line number Diff line change @@ -18,14 +18,22 @@ else t1=0 fi _copy(){ cat | pbcopy } _paste(){ pbpaste } if [[ $p0 -eq 1 || $t0 -eq 0 ]]; then # stdin is pipe-ish _copy # so send it to the clipboard if [[ $t1 -eq 0 ]]; then # also, stdout is not a tty (meaning it must be a pipe or redirection) _paste # so pass that pipe/redirection the content of the clipboard (enables `man tee` like chaining) fi else # stdin is not a pipe _paste # so output the clipboard if [[ $t1 -eq 1 ]]; then # stdout is a tty (so we don't have to be strict about not altering the output) echo # prevent the prompt from being on the same line fi fi -
RichardBronosky revised this gist
Mar 13, 2017 . 3 changed files with 69 additions and 6 deletions.There are no files selected for viewing
This file contains 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 charactersOriginal file line number Diff line number Diff line change @@ -1,10 +1,31 @@ #!/bin/bash if [[ -p /dev/stdin ]]; then # stdin is a pipe p0=1 else p0=0 fi if [[ -t 0 ]]; then # stdin is a tty t0=1 else t0=0 fi if [[ -t 1 ]]; then # stdout is a tty t1=1 else t1=0 fi if [[ $p0 -eq 1 || $t0 -eq 0 ]]; then # stdin is pipe-ish cat > /dev/clipboard # so send it to the pasteboard if [[ $t1 -eq 0 ]]; then # also, stdout is not a tty (meaning it must be a pipe or redirection) cat /dev/clipboard # so pass that pipe/redirection the content of the pasteboard (enables `man tee` like chaining) fi else # stdin is not a pipe cat /dev/clipboard # so output the pasteboard if [[ $t1 -eq 1 ]]; then # stdout is a tty (so we don't have to be strict about not altering the output) echo # prevent the prompt from being on the same line fi fi This file contains 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 charactersOriginal file line number Diff line number Diff line change @@ -1,10 +1,31 @@ #!/bin/bash if [[ -p /dev/stdin ]]; then # stdin is a pipe p0=1 else p0=0 fi if [[ -t 0 ]]; then # stdin is a tty t0=1 else t0=0 fi if [[ -t 1 ]]; then # stdout is a tty t1=1 else t1=0 fi if [[ $p0 -eq 1 || $t0 -eq 0 ]]; then # stdin is pipe-ish cat | xclip -selection clipboard # so send it to the pasteboard if [[ $t1 -eq 0 ]]; then # also, stdout is not a tty (meaning it must be a pipe or redirection) xclip -selection clipboard -o # so pass that pipe/redirection the content of the pasteboard (enables `man tee` like chaining) fi else # stdin is not a pipe xclip -selection clipboard -o # so output the pasteboard if [[ $t1 -eq 1 ]]; then # stdout is a tty (so we don't have to be strict about not altering the output) echo # prevent the prompt from being on the same line fi fi This file contains 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 charactersOriginal file line number Diff line number Diff line change @@ -1,10 +1,31 @@ #!/bin/bash if [[ -p /dev/stdin ]]; then # stdin is a pipe p0=1 else p0=0 fi if [[ -t 0 ]]; then # stdin is a tty t0=1 else t0=0 fi if [[ -t 1 ]]; then # stdout is a tty t1=1 else t1=0 fi if [[ $p0 -eq 1 || $t0 -eq 0 ]]; then # stdin is pipe-ish cat | pbcopy # so send it to the pasteboard if [[ $t1 -eq 0 ]]; then # also, stdout is not a tty (meaning it must be a pipe or redirection) pbpaste # so pass that pipe/redirection the content of the pasteboard (enables `man tee` like chaining) fi else # stdin is not a pipe pbpaste # so output the pasteboard if [[ $t1 -eq 1 ]]; then # stdout is a tty (so we don't have to be strict about not altering the output) echo # prevent the prompt from being on the same line fi fi -
RichardBronosky revised this gist
Jan 25, 2017 . 1 changed file with 17 additions and 14 deletions.There are no files selected for viewing
This file contains 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 charactersOriginal file line number Diff line number Diff line change @@ -17,23 +17,26 @@ $ date | cb ### Paste ```bash # clipboard retained from the previous block $ cb Tue Jan 24 23:00:00 EST 2017 $ cb | cat Tue Jan 24 23:00:00 EST 2017 $ cb > foo $ cat foo Tue Jan 24 23:00:00 EST 2017 ``` ### Chaining ```bash $ date | cb | tee updates.log Tue Jan 24 23:11:11 EST 2017 $ cat updates.log Tue Jan 24 23:11:11 EST 2017 # clipboard contains: Tue Jan 24 23:11:11 EST 2017 ``` [1]: https://gist.github.com/RichardBronosky/56d8f614fab2bacdd8b048fb58d0c0c7 [2]: -
RichardBronosky revised this gist
Jan 25, 2017 . 1 changed file with 5 additions and 3 deletions.There are no files selected for viewing
This file contains 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 charactersOriginal file line number Diff line number Diff line change @@ -10,9 +10,11 @@ It's like your normal copy and paste commands, but unified and able to sense whe ### Copy ```bash $ date | cb # clipboard contains: Tue Jan 24 23:00:00 EST 2017 ``` ### Paste # clipboard retained from the previous block -
RichardBronosky renamed this gist
Jan 25, 2017 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
RichardBronosky renamed this gist
Jan 25, 2017 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
RichardBronosky revised this gist
Jan 25, 2017 . 1 changed file with 38 additions and 0 deletions.There are no files selected for viewing
This file contains 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,38 @@ # cb ## A leak-proof tee to the clipboard This script is modeled after `tee` (see [`man tee`][2]). It's like your normal copy and paste commands, but unified and able to sense when you want it to be chainable ## Examples ### Copy $ date | cb # clipboard contains: Tue Jan 24 23:00:00 EST 2017 ### Paste # clipboard retained from the previous block $ cb Tue Jan 24 23:00:00 EST 2017 $ cb | cat Tue Jan 24 23:00:00 EST 2017 $ cb > foo $ cat foo Tue Jan 24 23:00:00 EST 2017 ### Chaining $ date | cb | tee updates.log Tue Jan 24 23:11:11 EST 2017 $ cat updates.log Tue Jan 24 23:11:11 EST 2017 # clipboard contains: Tue Jan 24 23:11:11 EST 2017 [1]: https://gist.github.com/RichardBronosky/56d8f614fab2bacdd8b048fb58d0c0c7 [2]: http://man7.org/linux/man-pages/man1/tee.1.html -
RichardBronosky created this gist
Jan 25, 2017 .There are no files selected for viewing
This file contains 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,10 @@ #!/bin/bash if [[ -p /dev/stdin ]]; then # stdin is a pipe cat > /dev/clipboard # so send it to the clipboard if [[ ! -t 1 ]]; then # also, stdout is not a tty (meaning it must be a pipe or redirection) cat /dev/clipboard # so pass that pipe/redirection the content of the clipboard (enables `man tee` like chaining) fi else # stdin is not a pipe cat /dev/clipboard # so output the clipboard fi This file contains 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,10 @@ #!/bin/bash if [[ -p /dev/stdin ]]; then # stdin is a pipe cat | xclip -selection clipboard # so send it to the pasteboard if [[ ! -t 1 ]]; then # also, stdout is not a tty (meaning it must be a pipe or redirection) xclip -selection clipboard -o # so pass that pipe/redirection the content of the pasteboard (enables `man tee` like chaining) fi else # stdin is not a pipe xclip -selection clipboard -o # so output the pasteboard fi This file contains 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,10 @@ #!/bin/bash if [[ -p /dev/stdin ]]; then # stdin is a pipe cat | pbcopy # so send it to the pasteboard if [[ ! -t 1 ]]; then # also, stdout is not a tty (meaning it must be a pipe or redirection) pbpaste # so pass that pipe/redirection the content of the pasteboard (enables `man tee` like chaining) fi else # stdin is not a pipe pbpaste # so output the pasteboard fi