-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpath_windows.go
125 lines (98 loc) · 2.66 KB
/
path_windows.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
120
121
122
123
124
125
//go:build windows
// +build windows
package main
import (
"bytes"
"fmt"
"log"
"os"
"os/exec"
"path/filepath"
"github.com/gosimple/conf"
"golang.org/x/term"
)
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 = 0600
// not sure why, but explorer.exe always returns exit code 1
// while 'start' does not.
c.FileManager = `start /B`
// Pagination Reader (Default: more)
c.TerminalReader = `more`
// default data directory
c.DataDir = filepath.Clean(homedir + `/AppData/Roaming/Notemanager`)
//c.Editor = `notepad`
// set default editor
editors := []string{"nvim", "gvim", "notepad"}
for _, editor := range editors {
path, err := exec.LookPath(editor)
if err == nil {
c.Editor = filepath.Clean(path)
break
}
}
cfgExists = false
cfg, err := conf.ReadFile(filepath.Clean(homedir + `/AppData/Roaming/Notemanager/noterc`))
if err == nil {
cfgExists = true
}
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)
}
// Default to more.exe as reader with pagination
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) {
//cmd := exec.Command("cmd", "/C", notemanager.FileManager, path)
//command := append([]string{"/C"}, notemanager.FileManager...)
//command = append(command, path)
//cmd := exec.Command("cmd", command...)
cmd := exec.Command("cmd", "/C", 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
}