Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: babarot/gomi
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v1.0.1
Choose a base ref
...
head repository: babarot/gomi
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v1.0.2
Choose a head ref
  • 2 commits
  • 4 files changed
  • 1 contributor

Commits on Jan 18, 2020

  1. Fix goreleaser.yml

    babarot committed Jan 18, 2020

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    90a875b View commit details
  2. Add binary file detection

    babarot committed Jan 18, 2020
    Copy the full SHA
    10bcea6 View commit details
Showing with 23 additions and 2 deletions.
  1. +2 −2 .goreleaser.yml
  2. +1 −0 go.mod
  3. +2 −0 go.sum
  4. +18 −0 main.go
4 changes: 2 additions & 2 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -9,8 +9,8 @@ builds:
binary: gomi
ldflags:
- -s -w
- -X github.com/b4b4r07/gomi/main.Version={{.Version}}
- -X github.com/b4b4r07/gomi/main.Revision={{.ShortCommit}}
- -X main.Version={{.Version}}
- -X main.Revision={{.ShortCommit}}
env:
- CGO_ENABLED=0
archives:
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -4,6 +4,7 @@ go 1.12

require (
github.com/dustin/go-humanize v1.0.0
github.com/gabriel-vasile/mimetype v1.0.2
github.com/jessevdk/go-flags v1.4.0
github.com/manifoldco/promptui v0.7.0
github.com/mattn/go-colorable v0.1.4 // indirect
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -6,6 +6,8 @@ github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1 h1:q763qf9huN11kDQavWs
github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU=
github.com/dustin/go-humanize v1.0.0 h1:VSnTsYCnlFHaM2/igO1h6X3HA71jcobQuxemgkq4zYo=
github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
github.com/gabriel-vasile/mimetype v1.0.2 h1:GKCo1TUCg0pV0R4atTcaLv/9SI2W9xPgMySZxUxcJOE=
github.com/gabriel-vasile/mimetype v1.0.2/go.mod h1:6CDPel/o/3/s4+bp6kIbsWATq8pmgOisOPG40CJa6To=
github.com/jessevdk/go-flags v1.4.0 h1:4IU2WS7AumrZ/40jfhf4QVDMsQwqA7VEHozFRrGARJA=
github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=
github.com/juju/ansiterm v0.0.0-20180109212912-720a0952cc2a h1:FaWFmfWdAUKbSCtOU2QjDaorUexogfaMgbipgYATUMU=
18 changes: 18 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
@@ -13,6 +13,7 @@ import (
"time"

"github.com/dustin/go-humanize"
"github.com/gabriel-vasile/mimetype"
"github.com/jessevdk/go-flags"
"github.com/manifoldco/promptui"
"github.com/rs/xid"
@@ -128,6 +129,20 @@ func makeFile(groupID string, arg string) (File, error) {
}, nil
}

func isBinary(path string) bool {
detectedMIME, err := mimetype.DetectFile(path)
if err != nil {
return true
}
isBinary := true
for mime := detectedMIME; mime != nil; mime = mime.Parent() {
if mime.Is("text/plain") {
isBinary = false
}
}
return isBinary
}

func head(path string) string {
max := 5
wrap := func(line string) string {
@@ -171,6 +186,9 @@ func head(path string) string {
lines = append(lines, fmt.Sprintf("%s\t%s", dir.Mode().String(), dir.Name()))
}
default:
if isBinary(path) {
return "(binary file)"
}
lines = []string{""}
fp, _ := os.Open(path)
defer fp.Close()