Skip to content

Commit

Permalink
[feat] add option to use file_path() with the %p keyword (#431)
Browse files Browse the repository at this point in the history
Use a absolute path where it is needed. like:
    { keys = ["m", "w"], commands = ["shell swaymsg output * bg %p fit"] },

Signed-off-by: luteran42 <[email protected]>
  • Loading branch information
luteran42 authored Nov 10, 2023
1 parent 960decf commit 9a75f05
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 5 deletions.
16 changes: 11 additions & 5 deletions docs/configuration/keymap.toml.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
]
```

Expand Down
17 changes: 17 additions & 0 deletions src/commands/sub_process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit 9a75f05

Please sign in to comment.