diff --git a/doc.go b/doc.go index db560aa5..26a95466 100644 --- a/doc.go +++ b/doc.go @@ -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 diff --git a/docstring.go b/docstring.go index 53f5442d..45bcf4f7 100644 --- a/docstring.go +++ b/docstring.go @@ -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 diff --git a/etc/lfrc.example b/etc/lfrc.example index 286a0d7c..b36badcf 100644 --- a/etc/lfrc.example +++ b/etc/lfrc.example @@ -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 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 diff --git a/opts.go b/opts.go index bdf356a4..4131ce99 100644 --- a/opts.go +++ b/opts.go @@ -85,6 +85,17 @@ func init() { gOpts.keys[""] = &callExpr{"cmd-hist-next", nil} gOpts.keys[""] = &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[""] = &callExpr{"cmd-transpose", nil} gOpts.cmds = make(map[string]expr) + + setDefaults() } diff --git a/os.go b/os.go index 0668027c..8beada81 100644 --- a/os.go +++ b/os.go @@ -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) } diff --git a/os_windows.go b/os_windows.go index b39d778d..f9fb9b67 100644 --- a/os_windows.go +++ b/os_windows.go @@ -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