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

+34 -5
View File
@@ -98,6 +98,31 @@ The following variables are exported for shell commands:
$fx current file or marked file(s) if any
$id id number of the client
The following additional keybindings are provided by default:
map zh set hidden!
map zr set reverse!
map zn set info
map zs set info size
map zt set info time
map za set info size:time
map sn :set sortby natural; set info
map ss :set sortby size; set info size
map st :set sortby time; set info time
map gh cd ~
The following keybindings to applications are provided by default on unix:
map e $$EDITOR $f ('vi' if empty)
map i $$PAGER $f ('less' if empty)
map w $$SHELL ('sh' if empty)
The following keybindings to applications are provided by default on windows:
map e $notepad "%f%"
map i $more "%f%"
map w $cmd
Configuration
The configuration file should be located at:
@@ -390,11 +415,15 @@ You may want to use either file extensions or mime types from 'file' command:
esac
}}
lf does not come bundled with a file opener. You can use any of the existing
file openers as you like. Possible options are 'open' (for Mac OS X only),
'xdg-utils' (executable name is 'xdg-open'), 'libfile-mimeinfo-perl'
(executable name is 'mimeopen'), 'rifle' (ranger's default file opener), or
'mimeo' to name a few.
Following commands are provided by default:
cmd open-file &start "" "%f%" # windows
cmd open-file &open "$f" # mac
cmd open-file &xdg-open "$f" # others
You may also use any other existing file openers as you like. Possible options
are 'libfile-mimeinfo-perl' (executable name is 'mimeopen'), 'rifle' (ranger's
default file opener), or 'mimeo' to name a few.
Previewing Files
+35 -5
View File
@@ -102,6 +102,32 @@ The following variables are exported for shell commands:
$fx current file or marked file(s) if any
$id id number of the client
The following additional keybindings are provided by default:
map zh set hidden!
map zr set reverse!
map zn set info
map zs set info size
map zt set info time
map za set info size:time
map sn :set sortby natural; set info
map ss :set sortby size; set info size
map st :set sortby time; set info time
map gh cd ~
The following keybindings to applications are provided by default on unix:
map e $$EDITOR $f ('vi' if empty)
map i $$PAGER $f ('less' if empty)
map w $$SHELL ('sh' if empty)
The following keybindings to applications are provided by default on
windows:
map e $notepad "%f%"
map i $more "%f%"
map w $cmd
Configuration
@@ -408,11 +434,15 @@ command:
esac
}}
lf does not come bundled with a file opener. You can use any of the existing
file openers as you like. Possible options are 'open' (for Mac OS X only),
'xdg-utils' (executable name is 'xdg-open'), 'libfile-mimeinfo-perl'
(executable name is 'mimeopen'), 'rifle' (ranger's default file opener), or
'mimeo' to name a few.
Following commands are provided by default:
cmd open-file &start "" "%f%" # windows
cmd open-file &open "$f" # mac
cmd open-file &xdg-open "$f" # others
You may also use any other existing file openers as you like. Possible
options are 'libfile-mimeinfo-perl' (executable name is 'mimeopen'), 'rifle'
(ranger's default file opener), or 'mimeo' to name a few.
Previewing Files
-27
View File
@@ -11,36 +11,9 @@ set ifs "\n"
# leave some space at the top and the bottom of the screen
set scrolloff 10
# toggle options
map zp set preview!
map zh set hidden!
# select what information to show
map zn set info
map zs set info size
map zt set info time
map za set info size:time
# sort files and show the corresponding info
map sn :set sortby natural; set info
map ss :set sortby size; set info size
map st :set sortby time; set info time
# common directories
map gh cd ~
map gr cd /
# use enter for shell commands
map <enter> read-shell
# mappings for pager and editor (change as you like)
map i $less $f
map e $vi $f
# mapping to spawn a shell in working directory
# (see also etc/lfcd.sh as an alternative workflow)
map w $$SHELL
# execute current file (must be executable)
map x $$f
map X !$f
+13
View File
@@ -85,6 +85,17 @@ func init() {
gOpts.keys["<c-n>"] = &callExpr{"cmd-hist-next", nil}
gOpts.keys["<c-p>"] = &callExpr{"cmd-hist-prev", nil}
gOpts.keys["zh"] = &setExpr{"hidden!", ""}
gOpts.keys["zr"] = &setExpr{"reverse!", ""}
gOpts.keys["zn"] = &setExpr{"info", ""}
gOpts.keys["zs"] = &setExpr{"info", "size"}
gOpts.keys["zt"] = &setExpr{"info", "time"}
gOpts.keys["za"] = &setExpr{"info", "size:time"}
gOpts.keys["sn"] = &listExpr{[]expr{&setExpr{"sortby", "natural"}, &setExpr{"info", ""}}}
gOpts.keys["ss"] = &listExpr{[]expr{&setExpr{"sortby", "size"}, &setExpr{"info", "size"}}}
gOpts.keys["st"] = &listExpr{[]expr{&setExpr{"sortby", "time"}, &setExpr{"info", "time"}}}
gOpts.keys["gh"] = &callExpr{"cd", []string{"~"}}
gOpts.cmdkeys = make(map[string]expr)
// TODO: rest of the keys
@@ -114,4 +125,6 @@ func init() {
gOpts.cmdkeys["<c-t>"] = &callExpr{"cmd-transpose", nil}
gOpts.cmds = make(map[string]expr)
setDefaults()
}
+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)
}
+7
View File
@@ -69,6 +69,13 @@ func putCommand(list []string, dir *dir, copy bool) *exec.Cmd {
return exec.Command(sh, args...)
}
func setDefaults() {
gOpts.keys["e"] = &execExpr{"$", `notepad "%f%"`}
gOpts.keys["i"] = &execExpr{"$", `more "%f%"`}
gOpts.keys["w"] = &execExpr{"$", "cmd"}
gOpts.cmds["open-file"] = &execExpr{"&", `start "" "%f%"`}
}
func moveCursor(y, x int) {
// TODO: implement
return