From 9a75f05a825e68e5295abf46e76d1810ee6e4deb Mon Sep 17 00:00:00 2001 From: lali Date: Fri, 10 Nov 2023 22:59:48 +0100 Subject: [feat] add option to use file_path() with the %p keyword (#431) Use a absolute path where it is needed. like: { keys = ["m", "w"], commands = ["shell swaymsg output * bg %p fit"] }, Signed-off-by: luteran42 --- docs/configuration/keymap.toml.md | 16 +++++++++++----- src/commands/sub_process.rs | 17 +++++++++++++++++ 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/docs/configuration/keymap.toml.md b/docs/configuration/keymap.toml.md index 0a3b791..d44660f 100644 --- a/docs/configuration/keymap.toml.md +++ b/docs/configuration/keymap.toml.md @@ -119,25 +119,31 @@ function joshuto() { ### `shell`: runs a shell command -- `%s` is substituted by a list of all selected files or by the file under the cursor, if none is selected +- `%s` and `%p` are substituted by a list of all selected files or by the file under the cursor, if none is selected - When running the external program, the directory shown in Joshuto is set as “working directory”, - the file names substituted for `%s` are given without path. + the file names substituted for `%s` are given without path. If you want the absolute path, use `%p`. - Example: `:shell touch file.txt` will create a file called `file.txt` - Example for `keymap.toml`: To open all selected files with `nvim`, one can add a keybinding like this: ```toml keymap = [ //.. - { keys = [ "e", "v" ], command = "shell nvim %s" } + { keys = [ "e", "v" ], commands = ["shell nvim %s"] } + ] + ``` +- To set a wallpaper on sway using the absolute path of an image file: + ```toml + keymap = [ //.. + { keys = ["m", "w"], commands = ["shell swaymsg output * bg %p fit"] } ] ``` ### `spawn`: runs a shell command in the background -- Supports `%s`, just like the `shell` command. +- Supports `%s`and `%p`, just like the `shell` command. - Example for `keymap.toml`: To open all selected files or directories with `sxiv`, one can add a keybinding like this: ```toml keymap = [ //.. - { keys = [ "i" ], command = "spawn sxiv -t %s" } + { keys = [ "i" ], commands = ["spawn sxiv -t %s"] } ] ``` diff --git a/src/commands/sub_process.rs b/src/commands/sub_process.rs index 9f97af1..437112e 100644 --- a/src/commands/sub_process.rs +++ b/src/commands/sub_process.rs @@ -39,6 +39,23 @@ fn execute_sub_process( command.arg(x); }); } + "%p" => { + if let Some(curr_list) = context.tab_context_ref().curr_tab_ref().curr_list_ref() { + let mut i = 0; + curr_list + .iter_selected() + .map(|e| e.file_path()) + .for_each(|file_path| { + command.arg(file_path); + i += 1; + }); + if i == 0 { + if let Some(entry) = curr_list.curr_entry_ref() { + command.arg(entry.file_path()); + } + } + } + } s => { command.arg(s); } -- cgit v1.2.3