From 289556f452b0f95b5e86c82931f69860d6e9dd6f Mon Sep 17 00:00:00 2001 From: Arijit Basu Date: Thu, 27 Oct 2022 21:39:48 +0530 Subject: [PATCH] Add builtin vroot mode Also fix ResetVroot --- docs/en/src/default-key-bindings.md | 266 +++++++++++++++------------- src/app.rs | 3 +- src/init.lua | 54 ++++++ 3 files changed, 196 insertions(+), 127 deletions(-) diff --git a/docs/en/src/default-key-bindings.md b/docs/en/src/default-key-bindings.md index 7fcbd4c..fa20892 100644 --- a/docs/en/src/default-key-bindings.md +++ b/docs/en/src/default-key-bindings.md @@ -14,42 +14,106 @@ of [modes][4] and the key mappings for each mode. ### default -| key | remaps | action | -| ------ | ------ | ------------------- | -| . | | show hidden | -| / | ctrl-f | search | -| : | | action | -| ? | | global help menu | -| G | | go to bottom | -| V | ctrl-a | select/unselect all | -| ctrl-d | | duplicate as | -| ctrl-i | tab | next visited path | -| ctrl-o | | last visited path | -| ctrl-r | | refresh screen | -| ctrl-u | | clear selection | -| ctrl-w | | switch layout | -| d | | delete | -| down | j | down | -| enter | | quit with result | -| f | | filter | -| g | | go to | -| h | left | back | -| k | up | up | -| l | right | enter | -| q | | quit | -| r | | rename | -| s | | sort | -| space | v | toggle selection | -| ~ | | go home | -| [0-9] | | input | +| key | remaps | action | +| --------- | ------ | ------------------- | +| . | | show hidden | +| / | ctrl-f | search | +| : | | action | +| ? | | global help menu | +| G | | go to bottom | +| V | ctrl-a | select/unselect all | +| ctrl-d | | duplicate as | +| ctrl-i | tab | next visited path | +| ctrl-o | | last visited path | +| ctrl-r | | refresh screen | +| ctrl-u | | clear selection | +| ctrl-w | | switch layout | +| d | | delete | +| down | j | down | +| enter | | quit with result | +| f | | filter | +| g | | go to | +| h | left | back | +| k | up | up | +| l | right | enter | +| page-down | | scroll down | +| page-up | | scroll up | +| q | | quit | +| r | | rename | +| s | | sort | +| space | v | toggle selection | +| { | | scroll up half | +| } | | scroll down half | +| ~ | | go home | +| [0-9] | | input | -### go_to_path +### filter + +| key | remaps | action | +| --------- | ------ | ---------------------------------- | +| R | | relative path does not match regex | +| backspace | | remove last filter | +| ctrl-r | | reset filters | +| ctrl-u | | clear filters | +| r | | relative path does match regex | + +### vroot + +| key | remaps | action | +| ------ | ------ | ----------- | +| . | | vroot $PWD | +| / | | vroot / | +| ctrl-r | | reset vroot | +| ~ | | vroot ~ | + +### create_file | key | remaps | action | | ----- | ------ | ------------ | | enter | | submit | | tab | | try complete | +### selection_ops + +| key | remaps | action | +| --- | ------ | --------------- | +| c | | copy here | +| m | | move here | +| u | | clear selection | + +### create + +| key | remaps | action | +| --- | ------ | ---------------- | +| d | | create directory | +| f | | create file | + +### quit + +| key | remaps | action | +| ----- | ------ | ----------------------- | +| enter | | just quit | +| f | | quit printing focus | +| p | | quit printing pwd | +| r | | quit printing result | +| s | | quit printing selection | + +### switch_layout + +| key | remaps | action | +| --- | ------ | -------------------- | +| 1 | | default | +| 2 | | no help menu | +| 3 | | no selection panel | +| 4 | | no help or selection | + +### delete + +| key | remaps | action | +| --- | ------ | ------------ | +| D | | force delete | +| d | | delete | + ### relative_path_does_not_match_regex | key | remaps | action | @@ -65,13 +129,18 @@ of [modes][4] and the key mappings for each mode. | k | up | to up | | [0-9] | | input | -### selection_ops +### relative_path_does_match_regex + +| key | remaps | action | +| ----- | ------ | ------ | +| enter | | submit | -| key | remaps | action | -| --- | ------ | ----------- | -| c | | copy here | -| m | | move here | -| x | | open in gui | +### create_directory + +| key | remaps | action | +| ----- | ------ | ------------ | +| enter | | submit | +| tab | | try complete | ### duplicate_as @@ -80,27 +149,19 @@ of [modes][4] and the key mappings for each mode. | enter | | submit | | tab | | try complete | -### action +### rename -| key | remaps | action | -| ----- | ------ | -------------------- | -| ! | | shell | -| c | | create | -| e | | open in editor | -| l | | logs | -| m | | toggle mouse | -| q | | quit options | -| s | | selection operations | -| [0-9] | | go to index | +| key | remaps | action | +| ----- | ------ | ------------ | +| enter | | submit | +| tab | | try complete | -### go_to +### go_to_path -| key | remaps | action | -| --- | ------ | -------------- | -| f | | follow symlink | -| g | | top | -| p | | path | -| x | | open in gui | +| key | remaps | action | +| ----- | ------ | ------------ | +| enter | | submit | +| tab | | try complete | ### sort @@ -126,29 +187,6 @@ of [modes][4] and the key mappings for each mode. | r | | by relative path | | s | | by size | -### rename - -| key | remaps | action | -| ----- | ------ | ------------ | -| enter | | submit | -| tab | | try complete | - -### debug_error - -| key | remaps | action | -| ----- | ------ | ------------------- | -| enter | | open logs in editor | -| q | | quit | - -### switch_layout - -| key | remaps | action | -| --- | ------ | -------------------- | -| 1 | | default | -| 2 | | no help menu | -| 3 | | no selection panel | -| 4 | | no help or selection | - ### search | key | remaps | action | @@ -161,61 +199,37 @@ of [modes][4] and the key mappings for each mode. | right | | enter | | tab | | toggle selection | -### create_file +### debug_error -| key | remaps | action | -| ----- | ------ | ------------ | -| enter | | submit | -| tab | | try complete | +| key | remaps | action | +| ----- | ------ | ------------------- | +| enter | | open logs in editor | +| q | | quit | + +### action + +| key | remaps | action | +| ----- | ------ | -------------------- | +| ! | | shell | +| c | | create | +| e | | open in editor | +| l | | logs | +| m | | toggle mouse | +| q | | quit options | +| s | | selection operations | +| v | | vroot | +| [0-9] | | go to index | ### recover | key | remaps | action | | --- | ------ | ------ | -### create - -| key | remaps | action | -| --- | ------ | ---------------- | -| d | | create directory | -| f | | create file | - -### filter - -| key | remaps | action | -| --------- | ------ | ---------------------------------- | -| R | | relative path does not match regex | -| backspace | | remove last filter | -| ctrl-r | | reset filters | -| ctrl-u | | clear filters | -| r | | relative path does match regex | - -### delete - -| key | remaps | action | -| --- | ------ | ------------ | -| D | | force delete | -| d | | delete | - -### create_directory - -| key | remaps | action | -| ----- | ------ | ------------ | -| enter | | submit | -| tab | | try complete | - -### quit - -| key | remaps | action | -| ----- | ------ | ----------------------- | -| enter | | just quit | -| f | | quit printing focus | -| p | | quit printing pwd | -| r | | quit printing result | -| s | | quit printing selection | - -### relative_path_does_match_regex +### go_to -| key | remaps | action | -| ----- | ------ | ------ | -| enter | | submit | +| key | remaps | action | +| --- | ------ | -------------- | +| f | | follow symlink | +| g | | top | +| p | | path | +| x | | open in gui | diff --git a/src/app.rs b/src/app.rs index c493aee..feda99d 100644 --- a/src/app.rs +++ b/src/app.rs @@ -783,10 +783,11 @@ impl App { } } - fn reset_vroot(self) -> Result { + fn reset_vroot(mut self) -> Result { if let Some(vroot) = self.initial_vroot.clone() { self.set_vroot(&vroot) } else { + self.vroot = None; Ok(self) } } diff --git a/src/init.lua b/src/init.lua index 8b9e28e..9afd660 100644 --- a/src/init.lua +++ b/src/init.lua @@ -1876,6 +1876,13 @@ xplr.config.modes.builtin.action = { "ToggleMouse", }, }, + ["v"] = { + help = "vroot", + messages = { + "PopMode", + { SwitchModeBuiltin = "vroot" }, + }, + }, ["q"] = { help = "quit options", messages = { @@ -2311,6 +2318,53 @@ xplr.config.modes.builtin.switch_layout = { }, } +-- The builtin vroot mode. +-- +-- Type: [Mode](https://xplr.dev/en/mode) +xplr.config.modes.builtin.vroot = { + name = "vroot", + key_bindings = { + on_key = { + ["."] = { + help = "vroot $PWD", + messages = { + "PopMode", + { + BashExecSilently0 = [===[ + "$XPLR" -m 'SetVroot: %q' "${PWD:?}" + ]===], + }, + }, + }, + ["/"] = { + help = "vroot /", + messages = { + "PopMode", + { SetVroot = "/" }, + }, + }, + ["~"] = { + help = "vroot ~", + messages = { + "PopMode", + { + BashExecSilently0 = [===[ + "$XPLR" -m 'SetVroot: %q' "${HOME:?}" + ]===], + }, + }, + }, + ["ctrl-r"] = { + help = "reset vroot", + messages = { + "PopMode", + "ResetVroot", + }, + }, + }, + }, +} + -- This is where you define custom modes. -- -- Type: mapping of the following key-value pairs: