Skip to content

Commit

Permalink
Results can be copied to clipboard
Browse files Browse the repository at this point in the history
  • Loading branch information
ninckblokje committed Aug 25, 2018
1 parent 6d393e0 commit 87a7e19
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,4 @@ $ csheet -l
subject section
````

To get the version use `-v`.
Optionally the results can be copied to the clipboard by using `-c`. To get the version use `-v`.
22 changes: 18 additions & 4 deletions csheet.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ import (
"fmt"
"os/user"
"flag"
"github.com/atotto/clipboard"
)

var csheetFile string
var csheetRevision = "DEV-BUILD"
var csheetVersion = "DEV-BUILD"

func main() {
var clipboardArg = flag.Bool("c", false, "Copy result to clipboard")
var fileArg = flag.String("f", "", "Cheat sheet Mardown file")
var listArg = flag.Bool("l", false, "Show all possible entries")
var versionArg = flag.Bool("v", false, "Display version")
Expand All @@ -33,12 +35,12 @@ func main() {
if *versionArg {
printVersion()
} else if *listArg {
printEntries()
printEntries(*clipboardArg)
} else {
subject := args[0]
section := args[1]

printEntry(subject, section)
printEntry(subject, section, *clipboardArg)
}
}

Expand Down Expand Up @@ -118,30 +120,42 @@ func openFile() (fp *os.File) {
}
}

func printEntry(subject string, section string) {
func printEntry(subject string, section string, copyToClipboard bool) {
fp := openFile()
defer fp.Close()

code := findEntry(fp, subject, section)
for i := 0; i< len(code); i++ {
fmt.Println(code[i])
}

if copyToClipboard {
clipboardEntries := strings.Join(code, "\n")
clipboard.WriteAll(clipboardEntries)
}
}

func printEntries() {
func printEntries(copyToClipboard bool) {
fp := openFile()
defer fp.Close()

entries := findEntries(fp)
for i := 0; i< len(entries); i++ {
fmt.Println(entries[i])
}

if copyToClipboard {
clipboardEntries := strings.Join(entries, "\n")
clipboard.WriteAll(clipboardEntries)
}
}

func printUsage() {
fmt.Println("Usage: csheet { OPTIONS } [SUBJECT] [SECTION]")
fmt.Println("Options:")
fmt.Println("-c : Copy result to clipboard")
fmt.Println("-f [FILE] : Specifies the Markdown file to read")
fmt.Println("-l : Show all possible entries")
fmt.Println("-v : Shows the versions")
}

Expand Down
7 changes: 7 additions & 0 deletions csheet_dev.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,11 @@ Test 3

````
Test 4
````

### test 311
````
line 1
line 2
line 3
````

0 comments on commit 87a7e19

Please sign in to comment.