-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpath_unix.go
119 lines (93 loc) · 2.43 KB
/
path_unix.go
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
// +build !windows
package main
import (
"bytes"
"fmt"
"github.com/gosimple/conf"
"golang.org/x/term"
"log"
"os"
"os/exec"
"path/filepath"
)
func parseConfig() (c Config) {
var cfgExists bool
homedir, err := os.UserHomeDir()
if err != nil {
log.Fatal(err)
}
// Syntax of note version file names
c.VersionTimeFormat = "20060102-150405"
// Short timestamp format
c.OutputTimeFormatShort = "2006-01-02"
// Long timestamp format
c.OutputTimeFormatLong = "2006-01-02 15:04:05"
// File and Directory Permissions
// Read+Write
c.FilePermission = 0600
// ReadOnly. Attachments should be readonly, so they are not being accidently
// overwritten, when browsing with file manager.
c.FilePermissionReadonly = 0400
// Read+Write+Execute
c.DirPermission = 0700
// Command Wrapper for Default Applications
c.FileManager = `open`
// Pagination Reader (Default: less)
c.TerminalReader = `less`
// default data directory
c.DataDir = filepath.Clean(homedir + "/.notes")
// set default editor
editors := []string{"nano", "nvim", "vim", "vi", "emacs", "ed"}
for _, editor := range editors {
path, err := exec.LookPath(editor)
if (err == nil) {
c.Editor = filepath.Clean(path)
break
}
}
cfg, err := conf.ReadFile(filepath.Clean(homedir + "/.noterc"))
if err == nil {
cfgExists = true
} else {
cfgExists = false
}
if cfgExists {
datadir, err := cfg.String("default", "datadir")
if err == nil {
c.DataDir = filepath.Clean(datadir)
}
editor, err := cfg.String("default", "editor")
if err == nil {
c.Editor = filepath.Clean(editor)
}
terminalReader, err := cfg.String("default", "terminalReader")
if err == nil {
c.TerminalReader = filepath.Clean(terminalReader)
}
}
c.TemplateDir = filepath.Clean(c.DataDir + "/templates")
c.TempDir = filepath.Clean(c.DataDir + "/tmp")
c.NoteDir = filepath.Clean(c.DataDir + "/notes")
if c.Editor == "" {
log.Fatal("Please define a text editor")
}
return
}
func runFileManager(path string) {
//command := append([]Any{"cmd", "/C"}, notemanager.FileManager..., path)
//command := append(notemanager.FileManager, path)
cmd := exec.Command(notemanager.FileManager, path)
var out bytes.Buffer
var stderr bytes.Buffer
cmd.Stdout = &out
cmd.Stderr = &stderr
err := cmd.Run()
if err != nil {
fmt.Println(fmt.Sprint(err) + ": " + stderr.String())
return
}
}
func terminalWidth() (width int) {
width, _, _ = term.GetSize(0)
return
}