-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 992cb1b
Showing
6 changed files
with
103 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# 0.1.0 (2019-10-09) | ||
- Initial release. |
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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) [year] [fullname] | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# cb | ||
## Usage | ||
Copy file contents to clipboard: | ||
```sh | ||
cb file.txt | ||
``` | ||
|
||
Copy stdin contents to clipboard: | ||
```sh | ||
echo foo | cb | ||
``` | ||
|
||
Copy stdin contents to clipboard, truncating 1 trailing line break if it exists: | ||
```sh | ||
echo foo | cb -n | ||
``` | ||
|
||
## Installation | ||
```sh | ||
go get -u github.com/setlog./cb | ||
``` |
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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module github.com/setlog/cb | ||
|
||
go 1.13 | ||
|
||
require github.com/atotto/clipboard v0.1.2 |
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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
github.com/atotto/clipboard v0.1.2 h1:YZCtFu5Ie8qX2VmVTBnrqLSiU9XOWwqNRmdT3gIQzbY= | ||
github.com/atotto/clipboard v0.1.2/go.mod h1:ZY9tmq7sm5xIbd9bOK4onWV4S6X0u6GY7Vn0Yu86PYI= |
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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package main | ||
|
||
import ( | ||
"flag" | ||
"fmt" | ||
"io/ioutil" | ||
"os" | ||
|
||
"github.com/atotto/clipboard" | ||
) | ||
|
||
func main() { | ||
flagTruncNewLine := flag.Bool("n", false, "Set to truncate one trailing line break if it exists.") | ||
flag.Parse() | ||
|
||
var cb string | ||
var err error | ||
if flag.NArg() == 0 { | ||
data, ioErr := ioutil.ReadAll(os.Stdin) | ||
cb, err = string(data), ioErr | ||
} else if flag.NArg() == 1 { | ||
filePath := flag.Arg(0) | ||
cb, err = readTextFile(filePath) | ||
} else { | ||
fatalf("provide file path or input on stdin") | ||
} | ||
if err != nil { | ||
fatalf("%v", err) | ||
} | ||
|
||
if *flagTruncNewLine && len(cb) > 0 && cb[len(cb)-1] == '\n' { | ||
cb = cb[:len(cb)-1] | ||
} | ||
|
||
err = clipboard.WriteAll(cb) | ||
if err != nil { | ||
fatalf("%v", err) | ||
} | ||
} | ||
|
||
func readTextFile(filePath string) (string, error) { | ||
data, err := ioutil.ReadFile(filePath) | ||
if err != nil { | ||
return "", err | ||
} | ||
return string(data), err | ||
} | ||
|
||
func fatalf(formatMessage string, args ...interface{}) { | ||
fmt.Printf(formatMessage+"\n", args...) | ||
os.Exit(1) | ||
} |