Skip to content

Commit

Permalink
git-p: default to listing only HEAD, slightly nicer LESS
Browse files Browse the repository at this point in the history
In practice this is almost always how I use git-p, so make it the
default.
  • Loading branch information
aclements committed Apr 12, 2021
1 parent 072870b commit e2d4f59
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 5 deletions.
5 changes: 5 additions & 0 deletions git-p/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module github.com/aclements/go-misc/git-p

go 1.17

require golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2
9 changes: 9 additions & 0 deletions git-p/go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2 h1:It14KIkyBFYkHkwZ7k45minvA9aorojkyjGk9KJ5B/w=
golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4=
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68 h1:nxC68pudNYkKU6jWhgrqdreuFiOQWj1Fs7T3VrH4Pjw=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1 h1:v+OssWQX+hTHEmOBgwxdZxK4zHq3yOs8F9J7mk0PY8E=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
14 changes: 13 additions & 1 deletion git-p/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,16 +81,28 @@ const (
func main() {
flag.Usage = func() {
fmt.Fprintf(os.Stderr, "Usage: %s [flags] [branches...]\n\n", os.Args[0])
fmt.Fprintf(os.Stderr, "With no arguments, list branches from newest to oldest.\n\n")
fmt.Fprintf(os.Stderr, "With no arguments, list the current branch.\n\n")
flag.PrintDefaults()
}
defIgnore, _ := tryGit("config", "p.ignore")
flagIgnore := flag.String("ignore", defIgnore, "ignore branches matching shell `pattern` [git config p.ignore]")
flagLocal := flag.Bool("l", false, "local state only; don't query Gerrit")
flagAll := flag.Bool("a", false, "list all branches from newest to oldest")
flag.Parse()
branches := flag.Args()
ignores := strings.Fields(*flagIgnore)

if *flagAll {
if len(branches) != 0 {
fmt.Fprintf(os.Stderr, "cannot use both -a and branches\n")
os.Exit(1)
}
} else {
if len(branches) == 0 {
branches = []string{"HEAD"}
}
}

// Check the branch names.
for _, b := range branches {
if out, err := tryGit("rev-parse", b, "--"); err != nil {
Expand Down
7 changes: 3 additions & 4 deletions git-p/pager.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,9 @@ func setupPager() (inTerm bool) {
w.Close()
syscall.Dup2(int(r.Fd()), 0)
r.Close()
if os.Getenv("LESS") == "" {
// We need -R at least to interpret color codes.
os.Setenv("LESS", "FRX")
}
// We need -R at least to interpret color codes.
// Add -F so single-screen output doesn't invoke paging.
os.Setenv("LESS", "-FR "+os.Getenv("LESS"))
if os.Getenv("LV") == "" {
os.Setenv("LV", "-c")
}
Expand Down

0 comments on commit e2d4f59

Please sign in to comment.