diff options
author | Jesse Duffield <jessedduffield@gmail.com> | 2020-03-01 12:30:48 +1100 |
---|---|---|
committer | Jesse Duffield <jessedduffield@gmail.com> | 2020-03-04 00:12:23 +1100 |
commit | 355f1615aba5b0b75485596fee0ae93d054081d4 (patch) | |
tree | 81a932f5ec7ae0bed07d114e7d8bf37cdaf6a08a /pkg/commands | |
parent | 113252b0ae3cb4d9f978398a6292b7f4737034ff (diff) |
supporing custom pagers step 1
Diffstat (limited to 'pkg/commands')
-rw-r--r-- | pkg/commands/git.go | 44 | ||||
-rw-r--r-- | pkg/commands/os.go | 8 |
2 files changed, 42 insertions, 10 deletions
diff --git a/pkg/commands/git.go b/pkg/commands/git.go index 1e4f1e990..e41648ed3 100644 --- a/pkg/commands/git.go +++ b/pkg/commands/git.go @@ -177,7 +177,7 @@ func stashEntryFromLine(line string, index int) *StashEntry { // GetStashEntryDiff stash diff func (c *GitCommand) ShowStashEntryCmdStr(index int) string { - return fmt.Sprintf("git stash show -p --color stash@{%d}", index) + return fmt.Sprintf("git stash show -p --color=%s stash@{%d}", c.colorArg(), index) } // GetStatusFiles git status files @@ -558,11 +558,11 @@ func (c *GitCommand) Ignore(filename string) error { } func (c *GitCommand) ShowCmdStr(sha string) string { - return fmt.Sprintf("git show --color --no-renames --stat -p %s", sha) + return fmt.Sprintf("git show --color=%s --no-renames --stat -p %s", c.colorArg(), sha) } func (c *GitCommand) GetBranchGraphCmdStr(branchName string) string { - return fmt.Sprintf("git log --graph --color --abbrev-commit --decorate --date=relative --pretty=medium %s", branchName) + return fmt.Sprintf("git log --graph --color=always --abbrev-commit --decorate --date=relative --pretty=medium %s", branchName) } // GetRemoteURL returns current repo remote url @@ -591,7 +591,7 @@ func (c *GitCommand) Diff(file *File, plain bool, cached bool) string { func (c *GitCommand) DiffCmdStr(file *File, plain bool, cached bool) string { cachedArg := "" trackedArg := "--" - colorArg := "--color" + colorArg := c.colorArg() split := strings.Split(file.Name, " -> ") // in case of a renamed file we get the new filename fileName := c.OSCommand.Quote(split[len(split)-1]) if cached { @@ -601,10 +601,10 @@ func (c *GitCommand) DiffCmdStr(file *File, plain bool, cached bool) string { trackedArg = "--no-index /dev/null" } if plain { - colorArg = "" + colorArg = "never" } - return fmt.Sprintf("git diff --stat -p %s %s %s %s", colorArg, cachedArg, trackedArg, fileName) + return fmt.Sprintf("git diff --stat -p --color=%s %s %s %s", colorArg, cachedArg, trackedArg, fileName) } func (c *GitCommand) ApplyPatch(patch string, flags ...string) error { @@ -896,12 +896,12 @@ func (c *GitCommand) ShowCommitFile(commitSha, fileName string, plain bool) (str } func (c *GitCommand) ShowCommitFileCmdStr(commitSha, fileName string, plain bool) string { - colorArg := "--color" + colorArg := c.colorArg() if plain { - colorArg = "" + colorArg = "never" } - return fmt.Sprintf("git show --no-renames %s %s -- %s", colorArg, commitSha, fileName) + return fmt.Sprintf("git show --no-renames --color=%s %s -- %s", colorArg, commitSha, fileName) } // CheckoutFile checks out the file for the given commit @@ -967,7 +967,7 @@ func (c *GitCommand) ResetSoft(ref string) error { // DiffCommits show diff between commits func (c *GitCommand) DiffCommits(sha1, sha2 string) (string, error) { - return c.OSCommand.RunCommandWithOutput("git diff --color --stat -p %s %s", sha1, sha2) + return c.OSCommand.RunCommandWithOutput("git diff --color=%s --stat -p %s %s", c.colorArg(), sha1, sha2) } // CreateFixupCommit creates a commit that fixes up a previous commit @@ -1128,3 +1128,27 @@ func (c *GitCommand) GetReflogCommits() ([]*Commit, error) { return commits, nil } + +func (c *GitCommand) GetPager(width int) (string, error) { + pager := c.Config.GetUserConfig().GetString("git.pager") + switch pager { + case "": + return "", nil + case "diff-so-fancy": + return "diff-so-fancy", nil + case "ydiff": + return fmt.Sprintf("ydiff -s --wrap --width=%d", width/2-6), nil + case "delta": + return "delta --dark", nil + default: + return "", errors.New("pager not supported. Pick one of diff-so-fancy, ydiff, delta, or nothing") + } +} + +func (c *GitCommand) colorArg() string { + pager := c.Config.GetUserConfig().GetString("git.pager") + if pager == "diff-so-fancy" || pager == "" { + return "always" + } + return "never" +} diff --git a/pkg/commands/os.go b/pkg/commands/os.go index e85b3e19c..9cf266f58 100644 --- a/pkg/commands/os.go +++ b/pkg/commands/os.go @@ -401,3 +401,11 @@ func (c *OSCommand) PipeCommands(commandStrings ...string) error { } return nil } + +func Kill(cmd *exec.Cmd) error { + if cmd.Process == nil { + // somebody got to it before we were able to, poor bastard + return nil + } + return cmd.Process.Kill() +} |