mirror of
https://github.com/skywind3000/z.lua
synced 2026-03-12 02:39:48 +00:00
Fixes and docs for the ranger plugin
- Makes Ranger plugin use the standard `$ZLUA_LUAEXE` and `$ZLUA_SCRIPT` environment variables that `z.lua` itself uses. - Better error handling; errors loading plugin no longer cause `ranger` to quit entirely. - Briefly document the plugin
This commit is contained in:
@@ -420,6 +420,14 @@ At last, press `<enter>` to accept or `<ESC>` to give up.
|
||||
Remember to enable the [enhanced matching](#enhanced-matching) algorithm, the current working directory can be skipped with it.
|
||||
|
||||
|
||||
## Ranger integration
|
||||
To add a `:z` command to the [`ranger` file manager], copy the `ranger_zlua.py` file to `~/.config/ranger/plugins/`.
|
||||
You can then use `:z foo`, `:z -b foo`, etc. from ranger. Use `:z -h` for help.
|
||||
|
||||
[`ranger` file manager]: https://github.com/ranger/ranger
|
||||
|
||||
To define additional commands (`:zb` for example) in ranger, you can put `alias zb z -b` into `~/.config/ranger/rc.conf`.
|
||||
|
||||
|
||||
## Tips
|
||||
|
||||
|
||||
@@ -4,8 +4,9 @@ import subprocess
|
||||
|
||||
old_hook_init = ranger.api.hook_init
|
||||
|
||||
PATH_LUA = os.environ.get('RANGER_LUA')
|
||||
PATH_ZLUA = os.environ.get('RANGER_ZLUA')
|
||||
# $RANGER_LUA and $RANGER_ZLUA variables are deprecated, do not use them.
|
||||
PATH_LUA = os.environ.get('RANGER_LUA') or os.environ.get('ZLUA_LUAEXE')
|
||||
PATH_ZLUA = os.environ.get('RANGER_ZLUA') or os.environ.get('ZLUA_SCRIPT')
|
||||
|
||||
if not PATH_LUA:
|
||||
for path in os.environ.get('PATH', '').split(os.path.pathsep):
|
||||
@@ -16,13 +17,15 @@ if not PATH_LUA:
|
||||
PATH_LUA = test
|
||||
break
|
||||
|
||||
def _report_error(msg):
|
||||
sys.stderr.write('ranger_zlua: ' + msg)
|
||||
raise RuntimeError(msg)
|
||||
|
||||
if not PATH_LUA:
|
||||
sys.stderr.write('Please install lua or set $RANGER_LUA.\n')
|
||||
sys.exit()
|
||||
_report_error('Please install lua in $PATH or make sure $ZLUA_LUAEXE points to a lua executable.\n')
|
||||
|
||||
if (not PATH_ZLUA) or (not os.path.exists(PATH_ZLUA)):
|
||||
sys.stderr.write('Not find z.lua, please set $RANGER_ZLUA to absolute path of z.lua.\n')
|
||||
sys.exit()
|
||||
_report_error('Could not find z.lua, please make sure $ZLUA_SCRIPT is set to absolute path of z.lua.\n')
|
||||
|
||||
|
||||
def hook_init(fm):
|
||||
|
||||
Reference in New Issue
Block a user