diff --git a/docs/en/src/default-key-bindings.md b/docs/en/src/default-key-bindings.md index 6cd00bf..871722b 100644 --- a/docs/en/src/default-key-bindings.md +++ b/docs/en/src/default-key-bindings.md @@ -233,5 +233,6 @@ of [modes][4] and the key mappings for each mode. | --- | ------ | -------------- | | f | | follow symlink | | g | | top | +| i | | initial $PWD | | p | | path | | x | | open in gui | diff --git a/docs/en/src/environment-variables-and-pipes.md b/docs/en/src/environment-variables-and-pipes.md index 2019c21..2456f56 100644 --- a/docs/en/src/environment-variables-and-pipes.md +++ b/docs/en/src/environment-variables-and-pipes.md @@ -49,6 +49,7 @@ The other variables are single-line variables containing simple information: - [XPLR_FOCUS_INDEX][31] - [XPLR_FOCUS_PATH][32] - [XPLR_INPUT_BUFFER][33] +- [XPLR_INITIAL_PWD][40] - [XPLR_MODE][34] - [XPLR_PID][35] - [XPLR_SESSION_PATH][36] @@ -73,6 +74,10 @@ Contains the index of the currently focused item, as seen in Contains the full path of the currently focused node. +#### XPLR_INITIAL_PWD + +The $PWD then xplr started. + #### XPLR_INPUT_BUFFER The line currently in displaying in the xplr input buffer. For e.g. the search @@ -220,3 +225,4 @@ xplr.config.modes.builtin.default.key_bindings.on_key.X = { [37]: messages.md#reading-input [38]: #xplr [39]: #xplr_vroot +[40]: #xplr_initial_pwd diff --git a/docs/en/src/layout.md b/docs/en/src/layout.md index 7818cfe..25b3733 100644 --- a/docs/en/src/layout.md +++ b/docs/en/src/layout.md @@ -384,6 +384,7 @@ Hence, only the following fields are avilable. - [version][40] - [pwd][41] +- [initial_pwd][53] - [vroot][52] - [focused_node][42] - [selection][43] @@ -449,4 +450,5 @@ Hence, only the following fields are avilable. [49]: lua-function-calls.md#explorer_config [50]: lua-function-calls.md#directory_buffer [51]: layouts.md -[52]: #vroot +[52]: lua-function-calls#vroot +[53]: lua-function-calls#initial_pwd diff --git a/docs/en/src/lua-function-calls.md b/docs/en/src/lua-function-calls.md index 75fe004..14c45b5 100644 --- a/docs/en/src/lua-function-calls.md +++ b/docs/en/src/lua-function-calls.md @@ -17,6 +17,7 @@ It contains the following information: - [version][29] - [pwd][31] +- [initial_pwd][76] - [vroot][75] - [focused_node][32] - [directory_buffer][33] @@ -42,6 +43,12 @@ Type: string The present working directory. +### initial_pwd + +Type: string + +The initial working directory when xplr started. + ### vroot Type: nullable string @@ -392,3 +399,4 @@ xplr.config.modes.builtin.default.key_bindings.on_key.space = { [73]: #uid [74]: #gid [75]: #vroot +[76]: #initial_pwd diff --git a/src/app.rs b/src/app.rs index 6b6769b..48c4811 100644 --- a/src/app.rs +++ b/src/app.rs @@ -128,6 +128,7 @@ impl History { pub struct LuaContextHeavy { pub version: String, pub pwd: String, + pub initial_pwd: String, pub vroot: Option, pub focused_node: Option, pub directory_buffer: Option, @@ -146,6 +147,7 @@ pub struct LuaContextHeavy { pub struct LuaContextLight { pub version: String, pub pwd: String, + pub initial_pwd: String, pub vroot: Option, pub focused_node: Option, pub selection: IndexSet, @@ -172,6 +174,7 @@ pub struct App { pub vroot: Option, pub initial_vroot: Option, pub pwd: String, + pub initial_pwd: String, pub directory_buffer: Option, pub last_focus: HashMap>, pub selection: IndexSet, @@ -316,6 +319,8 @@ impl App { let initial_vroot = vroot.clone(); env::set_current_dir(&pwd)?; + let initial_pwd = pwd.clone(); + let input = InputBuffer { buffer: Default::default(), prompt: config.general.prompt.format.clone().unwrap_or_default(), @@ -328,6 +333,7 @@ impl App { vroot, initial_vroot, pwd, + initial_pwd, directory_buffer: Default::default(), last_focus: Default::default(), selection: Default::default(), @@ -1780,6 +1786,7 @@ impl App { LuaContextHeavy { version: self.version.clone(), pwd: self.pwd.clone(), + initial_pwd: self.initial_pwd.clone(), vroot: self.vroot.clone(), focused_node: self.focused_node().cloned(), directory_buffer: self.directory_buffer.clone(), @@ -1799,6 +1806,7 @@ impl App { LuaContextLight { version: self.version.clone(), pwd: self.pwd.clone(), + initial_pwd: self.initial_pwd.clone(), vroot: self.vroot.clone(), focused_node: self.focused_node().cloned(), selection: self.selection.clone(), diff --git a/src/init.lua b/src/init.lua index e5d2ac2..2fd6263 100644 --- a/src/init.lua +++ b/src/init.lua @@ -1641,7 +1641,17 @@ xplr.config.modes.builtin.go_to = { { SetInputBuffer = "" }, }, }, - + ["i"] = { + help = "initial $PWD", + messages = { + "PopMode", + { + BashExecSilently0 = [===[ + "$XPLR" -m 'ChangeDirectory: %q' "${XPLR_INITIAL_PWD:?}" + ]===], + }, + }, + }, ["x"] = { help = "open in gui", messages = { diff --git a/src/runner.rs b/src/runner.rs index fb9d119..e4705d1 100644 --- a/src/runner.rs +++ b/src/runner.rs @@ -113,6 +113,7 @@ fn call( .env("XPLR_APP_VERSION", &app.version) .env("XPLR_PID", &app.pid.to_string()) .env("XPLR_INPUT_BUFFER", input_buffer) + .env("XPLR_INITIAL_PWD", &app.initial_pwd) .env("XPLR_FOCUS_PATH", app.focused_node_str()) .env("XPLR_FOCUS_INDEX", focus_index) .env("XPLR_SESSION_PATH", &app.session_path)