Skip to content

Commit

Permalink
Support sensible_command (knqyf263#94)
Browse files Browse the repository at this point in the history
  • Loading branch information
knqyf263 authored Feb 3, 2019
1 parent bbef0ad commit 268498d
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package config
import (
"fmt"
"os"
"os/exec"
"path/filepath"
"runtime"

Expand Down Expand Up @@ -94,7 +95,11 @@ func (cfg *Config) Load(file string) error {

cfg.General.Editor = os.Getenv("EDITOR")
if cfg.General.Editor == "" && runtime.GOOS != "windows" {
cfg.General.Editor = "vim"
if isCommandAvailable("sensible-editor") {
cfg.General.Editor = "sensible-editor"
} else {
cfg.General.Editor = "vim"
}
}
cfg.General.Column = 40
cfg.General.SelectCmd = "fzf"
Expand Down Expand Up @@ -135,3 +140,11 @@ func expandPath(s string) string {
}
return os.Expand(s, os.Getenv)
}

func isCommandAvailable(name string) bool {
cmd := exec.Command("/bin/sh", "-c", "command -v "+name)
if err := cmd.Run(); err != nil {
return false
}
return true
}

0 comments on commit 268498d

Please sign in to comment.