Skip to content

Commit

Permalink
[help] Enable man appearing in path that has spaces
Browse files Browse the repository at this point in the history
Avoids shell-splitting manProgram unless the value was read from the
$PAGER environment variable.
  • Loading branch information
mislav committed Jun 28, 2019
1 parent ce213d7 commit 6a13adf
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions commands/help.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/github/hub/cmd"
"github.com/github/hub/ui"
"github.com/github/hub/utils"
"github.com/kballard/go-shellquote"
)

var cmdHelp = &Command{
Expand Down Expand Up @@ -120,12 +121,21 @@ func runListCmds(cmd *Command, args *Args) {
}

func displayManPage(manPage string, args *Args) error {
var manArgs []string
manProgram, _ := utils.CommandPath("man")
if manProgram == "" {
if manProgram != "" {
manArgs = []string{manProgram}
} else {
manPage += ".txt"
manProgram = os.Getenv("PAGER")
if manProgram == "" {
manProgram = "less -R"
if manProgram != "" {
var err error
manArgs, err = shellquote.Split(manProgram)
if err != nil {
return err
}
} else {
manArgs = []string{"less", "-R"}
}
}

Expand All @@ -140,8 +150,8 @@ func displayManPage(manPage string, args *Args) error {
return err
}

man := cmd.New(manProgram)
man.WithArg(manFile)
manArgs = append(manArgs, manFile)
man := cmd.NewWithArray(manArgs)
if err = man.Run(); err == nil {
os.Exit(0)
} else {
Expand Down

0 comments on commit 6a13adf

Please sign in to comment.