Skip to content

Commit

Permalink
Merge pull request #18 from dbalan/args_editor
Browse files Browse the repository at this point in the history
Bug fix: Editor spec can have arguments.
  • Loading branch information
dbalan committed Jul 12, 2019
2 parents 30f54ed + ab79e1a commit 6dd8eac
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 7 deletions.
68 changes: 64 additions & 4 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 10 additions & 2 deletions cmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import (
"fmt"
"io/ioutil"
"os"
"strings"

"github.com/spf13/cobra"
"gopkg.in/yaml.v2"
Expand Down Expand Up @@ -81,14 +82,21 @@ var initCmd = &cobra.Command{
}

if eBin != "" {
path, err := which(eBin)
// eBin might be editor + args
// for e.g emacsclient -t
actualBinPath := strings.Split(eBin, " ")[0]
path, err := which(actualBinPath)
errorGuard(err, "No such editor found!")

// expanded path
if path != eBin {
fmt.Printf("Using %s as the absoulte path to editor\n", Green(path))
}
config.EBin = path
if actualBinPath != eBin {
config.EBin = path + " " + strings.Join(strings.Split(eBin, " ")[1:], " ")
} else {
config.EBin = path
}
} else {
errorGuard(fmt.Errorf("empty input"), "no editor sepcified")
}
Expand Down
7 changes: 6 additions & 1 deletion cmd/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,12 @@ func getDataStore() *pipetdata.DataStore {
// call external editor to edit the snippet.
func editSnippet(fn string) error {
editorBin := viper.Get("editor_binary").(string)
cmd := exec.Command(editorBin, fn)

// editor_binary is of form bin args
parsed := strings.Split(editorBin, " ")
args := parsed[1:]
args = append(args, fn)
cmd := exec.Command(parsed[0], args...)
cmd.Stdin = os.Stdin
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
Expand Down

0 comments on commit 6dd8eac

Please sign in to comment.