Skip to content

Commit 985a335

Browse files
authored
Merge pull request #600 from as3ii/execute_current_path
feat: add option to use current working directory with the %d keyword
2 parents 8ce5290 + 5b80de0 commit 985a335

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

docs/configuration/keymap.toml.md

+8-1
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ function joshuto() {
120120
### `shell`: runs a shell command
121121

122122
- `%s` and `%p` are substituted by a list of all selected files or by the file under the cursor, if none is selected
123+
- `%d` is substituted with the current directory's absolute path
123124
- When running the external program, the directory shown in Joshuto is set as “working directory”,
124125
the file names substituted for `%s` are given without path. If you want the absolute path, use `%p`.
125126
- Example: `:shell touch file.txt` will create a file called `file.txt`
@@ -138,14 +139,20 @@ function joshuto() {
138139

139140
### `spawn`: runs a shell command in the background
140141

141-
- Supports `%s`and `%p`, just like the `shell` command.
142+
- Supports `%s`, `%p` and `%d`, just like the `shell` command.
142143
- Example for `keymap.toml`: To open all selected files or directories with `sxiv`,
143144
one can add a keybinding like this:
144145
```toml
145146
keymap = [ //..
146147
{ keys = [ "i" ], commands = ["spawn sxiv -t %s"] }
147148
]
148149
```
150+
- To open a new alacritty terminal in the current folder:
151+
```toml
152+
keymap = [ // ..
153+
{ keys = [ "O" ], commands = ["spawn alacritty --working-directory %d"] }
154+
]
155+
```
149156

150157
### `suspend`: suspends the current session
151158
can be mapped to Ctrl+z to behave similarly to other programs

src/commands/sub_process.rs

+7
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ pub fn current_files(app_state: &AppState) -> Vec<(&str, &Path)> {
3636
result
3737
}
3838

39+
fn current_dir(app_state: &AppState) -> &Path {
40+
app_state.state.tab_state_ref().curr_tab_ref().get_cwd()
41+
}
42+
3943
fn execute_sub_process(
4044
app_state: &mut AppState,
4145
words: &[String],
@@ -65,6 +69,9 @@ fn execute_sub_process(
6569
command.arg(file_path);
6670
}
6771
}
72+
"%d" => {
73+
command.arg(current_dir(app_state));
74+
}
6875
s => {
6976
command.arg(s);
7077
}

0 commit comments

Comments
 (0)