From fef99c1d70af62b2835cbd0ee13b7573812f3222 Mon Sep 17 00:00:00 2001 From: Gokcehan Date: Thu, 28 Jun 2018 23:37:01 +0300 Subject: [PATCH] use env vars on windows --- doc.go | 25 +++++++++++++------------ docstring.go | 26 +++++++++++++------------- os_windows.go | 31 +++++++++++++++++++++++++++---- 3 files changed, 53 insertions(+), 29 deletions(-) diff --git a/doc.go b/doc.go index b68bee01..94dfb62b 100644 --- a/doc.go +++ b/doc.go @@ -123,6 +123,14 @@ when they are not set or empty: $PAGER less $SHELL sh +The following default values are set to the environmental variables on windows +when they are not set or empty: + + %OPENER% start + %EDITOR% notepad + %PAGER% more + %SHELL% cmd + The following additional keybindings are provided by default: map zh set hidden! @@ -136,18 +144,12 @@ The following additional keybindings are provided by default: map st :set sortby time; set info time map gh cd ~ -The following keybindings to applications are provided by default on unix: +The following keybindings to applications are provided by default: - map e $$EDITOR "$f" - map i $$PAGER "$f" + map e $$EDITOR $f + map i $$PAGER $f map w $$SHELL -The following keybindings to applications are provided by default on windows: - - map e $notepad %f% - map i $more %f% - map w $cmd - Configuration Configuration files should be located at: @@ -532,10 +534,9 @@ You may want to use either file extensions or mime types from 'file' command: esac }} -Following commands are provided by default: +Following command is provided by default: - cmd open &$OPENER "$f # unix - cmd open &start %f% # windows + cmd open &$OPENER $f 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 diff --git a/docstring.go b/docstring.go index cc211eb1..f77dc138 100644 --- a/docstring.go +++ b/docstring.go @@ -127,6 +127,14 @@ when they are not set or empty: $PAGER less $SHELL sh +The following default values are set to the environmental variables on windows +when they are not set or empty: + + %OPENER% start + %EDITOR% notepad + %PAGER% more + %SHELL% cmd + The following additional keybindings are provided by default: map zh set hidden! @@ -140,19 +148,12 @@ The following additional keybindings are provided by default: map st :set sortby time; set info time map gh cd ~ -The following keybindings to applications are provided by default on unix: +The following keybindings to applications are provided by default: - map e $$EDITOR "$f" - map i $$PAGER "$f" + map e $$EDITOR $f + map i $$PAGER $f map w $$SHELL -The following keybindings to applications are provided by default on -windows: - - map e $notepad %f% - map i $more %f% - map w $cmd - Configuration @@ -559,10 +560,9 @@ command: esac }} -Following commands are provided by default: +Following command is provided by default: - cmd open &$OPENER "$f # unix - cmd open &start %f% # windows + cmd open &$OPENER $f You may also use any other existing file openers as you like. Possible options are 'libfile-mimeinfo-perl' (executable name is 'mimeopen'), 'rifle' diff --git a/os_windows.go b/os_windows.go index d3accf48..ba658c7d 100644 --- a/os_windows.go +++ b/os_windows.go @@ -9,6 +9,13 @@ import ( "strings" ) +var ( + envOpener = os.Getenv("OPENER") + envEditor = os.Getenv("EDITOR") + envPager = os.Getenv("PAGER") + envShell = os.Getenv("SHELL") +) + var ( gDefaultShell = "cmd" gDefaultSocketProt = "tcp" @@ -21,6 +28,22 @@ var ( ) func init() { + if envOpener == "" { + envOpener = "start" + } + + if envEditor == "" { + envEditor = "notepad" + } + + if envPager == "" { + envPager = "more" + } + + if envShell == "" { + envShell = "cmd" + } + u, err := user.Current() if err != nil { log.Printf("user: %s", err) @@ -76,10 +99,10 @@ func pasteCommand(list []string, dir *dir, cp bool) *exec.Cmd { } func setDefaults() { - gOpts.cmds["open"] = &execExpr{"&", `start %f%`} - gOpts.keys["e"] = &execExpr{"$", `notepad %f%`} - gOpts.keys["i"] = &execExpr{"$", `more %f%`} - gOpts.keys["w"] = &execExpr{"$", "cmd"} + gOpts.cmds["open"] = &execExpr{"&", "%OPENER% %f%"} + gOpts.keys["e"] = &execExpr{"$", "%EDITOR% %f%"} + gOpts.keys["i"] = &execExpr{"!", "%PAGER% %f%"} + gOpts.keys["w"] = &execExpr{"$", "%SHELL%"} } func moveCursor(y, x int) {