add default file opener and more keybindings

Related #9 and #94
This commit is contained in:
Gokcehan committed 2018-03-02 23:21:52 +03:00
1 parent 61c8b588cd
commit c3f4aa58a7
6 files changed
+122 -37

No files matched your search

+33
View File
@@ -9,6 +9,13 @@ import (
"os/exec"
"os/user"
"path/filepath"
"runtime"
)
var (
envEditor = os.Getenv("EDITOR")
envPager = os.Getenv("PAGER")
envShell = os.Getenv("SHELL")
)
var (
@@ -85,6 +92,32 @@ func putCommand(list []string, dir *dir, copy bool) *exec.Cmd {
return exec.Command(sh, args...)
}
func setDefaults() {
if envEditor == "" {
gOpts.keys["e"] = &execExpr{"$", `vi "$f"`}
} else {
gOpts.keys["e"] = &execExpr{"$", envEditor + ` "$f"`}
}
if envPager == "" {
gOpts.keys["i"] = &execExpr{"$", `less "$f"`}
} else {
gOpts.keys["i"] = &execExpr{"$", envPager + ` "$f"`}
}
if envShell == "" {
gOpts.keys["w"] = &execExpr{"$", "sh"}
} else {
gOpts.keys["w"] = &execExpr{"$", envShell}
}
if runtime.GOOS == "darwin" {
gOpts.cmds["open-file"] = &execExpr{"&", `open "$f"`}
} else {
gOpts.cmds["open-file"] = &execExpr{"&", `xdg-open "$f"`}
}
}
func moveCursor(y, x int) {
fmt.Printf("\033[%d;%dH", y, x)
}