-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfile.go
More file actions
55 lines (46 loc) · 1.01 KB
/
Copy pathfile.go
File metadata and controls
55 lines (46 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package ilse
import (
"fmt"
"os"
"os/exec"
"path/filepath"
"github.com/tjmtmmnk/ilse/util"
)
func getEditorLineFlag() string {
editor := os.Getenv("EDITORLINEFLAG")
if len(editor) == 0 {
editor = "+"
}
return editor
}
func getEditor() string {
editor := os.Getenv("EDITOR")
if len(editor) == 0 {
editor = "vim"
}
return editor
}
func openFile(fileName string, lineNum int) {
editor := getEditor()
path := filepath.Join(conf.userWorkDir, fileName)
if filepath.IsAbs(fileName) {
path = fileName
}
lineFlag := fmt.Sprintf("%s%d", getEditorLineFlag(), lineNum)
var cmd *exec.Cmd
_, file := filepath.Split(editor)
switch file {
case "emacs", "emacsclient":
// emacs expects the line before the file
cmd = exec.Command(editor, lineFlag, path)
default:
// default to adding the line after the file
cmd = exec.Command(editor, path, lineFlag)
}
cmd.Stdin = os.Stdin
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
if err := cmd.Run(); err != nil {
util.Logger.Error("can't open file")
}
}