lf/os_windows.go

76 lines
1.3 KiB
Go
Raw Normal View History

package main
import (
"log"
"os"
"os/exec"
2017-08-06 08:05:46 +00:00
"os/user"
"path/filepath"
2017-08-06 08:05:46 +00:00
"strings"
)
2017-08-06 08:05:46 +00:00
var (
gDefaultShell = "cmd"
gDefaultSocketProt = "tcp"
gDefaultSocketPath = ":12345"
)
var (
gUser *user.User
gConfigPath string
)
func init() {
2017-11-19 18:55:13 +00:00
u, err := user.Current()
2017-08-06 08:05:46 +00:00
if err != nil {
log.Printf("user: %s", err)
}
2017-11-19 18:55:13 +00:00
gUser = u
2017-08-06 08:05:46 +00:00
// remove domain prefix
gUser.Username = strings.Split(gUser.Username, `\`)[1]
gConfigPath = filepath.Join(gUser.HomeDir, "AppData", "Local", "lf", "lfrc")
}
func pauseCommand() *exec.Cmd {
return exec.Command("cmd", "/c", "pause")
}
func shellCommand(s string, args []string) *exec.Cmd {
args = append([]string{"/c", s}, args...)
return exec.Command(gOpts.shell, args...)
}
func putCommand(list []string, dir *dir, copy bool) *exec.Cmd {
var args []string
sh := "robocopy"
if !copy {
args = []string{"/move"}
}
for _, f := range list {
stat, err := os.Stat(f)
if err != nil {
log.Printf("getting file information: %s", err)
continue
}
base := filepath.Base(f)
dest := filepath.Dir(f)
if stat.IsDir() {
exec.Command(sh, append(args, f, filepath.Join(dir.path, base))...).Run()
} else {
exec.Command(sh, append(args, dest, dir.path, base)...).Run()
}
}
// TODO: return 0 on success
return exec.Command(sh, args...)
}
func moveCursor(y, x int) {
// TODO: implement
return
}