diff options
-rw-r--r-- | files_panel.go | 4 | ||||
-rw-r--r-- | gitcommands.go | 39 | ||||
-rw-r--r-- | main.go | 10 |
3 files changed, 29 insertions, 24 deletions
diff --git a/files_panel.go b/files_panel.go index a102399f7..4104845fc 100644 --- a/files_panel.go +++ b/files_panel.go @@ -193,8 +193,8 @@ func genericFileOpen(g *gocui.Gui, v *gocui.View, open func(*gocui.Gui, string) } return nil } - if output, err := open(g, file.Name); err != nil { - return createErrorPanel(g, output) + if _, err := open(g, file.Name); err != nil { + return createErrorPanel(g, err.Error()) } return nil } diff --git a/gitcommands.go b/gitcommands.go index 0f5692e87..e4f500a8f 100644 --- a/gitcommands.go +++ b/gitcommands.go @@ -19,6 +19,9 @@ import ( var ( // ErrNoCheckedOutBranch : When we have no checked out branch ErrNoCheckedOutBranch = errors.New("No currently checked out branch") + + // ErrNoOpenCommand : When we don't know which command to use to open a file + ErrNoOpenCommand = errors.New("Unsure what command to use to open this file") ) // GitFile : A staged/unstaged file @@ -278,8 +281,26 @@ func sublimeOpenFile(g *gocui.Gui, filename string) (string, error) { } func openFile(g *gocui.Gui, filename string) (string, error) { - cmdName, cmdTrail := getOpenCommand() - return runCommand(cmdName + " " + filename + " " + cmdTrail) // TODO: find out why finder is being opened here + cmdName, cmdTrail, err := getOpenCommand() + if err != nil { + return "", err + } + return runCommand(cmdName + " " + filename + cmdTrail) +} + +func getOpenCommand() (string, string, error) { + //NextStep open equivalents: xdg-open (linux), cygstart (cygwin), open (OSX) + trailMap := map[string]string{ + "xdg-open": " &>/dev/null &", + "cygstart": "", + "open": "", + } + for name, trail := range trailMap { + if out, _ := runCommand("which " + name); out != "exit status 1" { + return name, trail, nil + } + } + return "", "", ErrNoOpenCommand } func gitAddPatch(g *gocui.Gui, filename string) { @@ -299,20 +320,6 @@ func editFile(g *gocui.Gui, filename string) (string, error) { return "", nil } -func getOpenCommand() (string, string) { - //NextStep open equivalents: xdg-open (linux), cygstart (cygwin), open (OSX) - trailMap := map[string]string{ - "xdg-open": "&>/dev/null &", - "cygstart": "", - } - for name, trail := range trailMap { - if out, _ := runCommand("which " + name); out != "exit status 1" { - return name, trail - } - } - return "open", "" -} - func runSubProcess(g *gocui.Gui, cmdName string, commandArgs ...string) { subprocess = exec.Command(cmdName, commandArgs...) subprocess.Stdin = os.Stdin @@ -19,7 +19,6 @@ var ( ErrSubprocess = errors.New("running subprocess") subprocess *exec.Cmd startTime time.Time - debugging bool // Rev - Git Revision Rev string @@ -27,9 +26,9 @@ var ( // Version - Version number Version = "unversioned" - builddate string - debuggingPointer = flag.Bool("debug", false, "a boolean") - versionFlag = flag.Bool("v", false, "Print the current version") + builddate string + debuggingFlag = flag.Bool("debug", false, "a boolean") + versionFlag = flag.Bool("v", false, "Print the current version") ) func homeDirectory() string { @@ -53,7 +52,7 @@ func commandLog(objects ...interface{}) { } func localLog(colour color.Attribute, path string, objects ...interface{}) { - if !debugging { + if !*debuggingFlag { return } f, _ := os.OpenFile(path, os.O_APPEND|os.O_WRONLY, 0644) @@ -75,7 +74,6 @@ func navigateToRepoRootDirectory() { func main() { startTime = time.Now() - debugging = *debuggingPointer devLog("\n\n\n\n\n\n\n\n\n\n") flag.Parse() if *versionFlag { |