Skip to content

Commit 9260cb9

Browse files
authored
Merge pull request #34 from unsecretised/variables-for-shell-commands
Variables for shell commands
2 parents a6dd02c + 95475a3 commit 9260cb9

5 files changed

Lines changed: 34 additions & 8 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ bit wonky, and will be fixed in the upcoming releases
6060
- [ ] Clipboard History 20/12/2025
6161
- [ ] Plugin Support 31/12/2025 (Partially implemented on 15/12/2025)
6262
- [ ] Blur / transparent background (Partially implemented on 13/12/2025)
63-
- [ ] Allow variables to be passed into custom shell scripts.
6463
- [ ] Hyperkey - Map CMD + OPT + CTRL + SHIFT to a physical key
6564
- [ ] Ability to pick between tabs in firefox / chromium browsers - using
6665
[Puppeteer](https://pptr.dev/)
@@ -77,6 +76,7 @@ bit wonky, and will be fixed in the upcoming releases
7776
- [x] Customisable themes (13/12/2025)
7877
- [x] Configurable colours
7978
- [x] Spotify control - Ability to control spotify via the app
79+
- [x] Allow variables to be passed into custom shell scripts.
8080
- [x] Google your query. Simply type your query, and then put a `?` at the end,
8181
and press enter
8282

docs/config.toml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,15 @@ background_opacity = 1.0
2828
blur = false
2929
show_icons = true
3030
show_scroll_bar = true
31+
32+
[[shells]]
33+
command = "echo $var1 > file.txt" # This will start with $var1
34+
icon_path = "" # optional
35+
alias = "Variables 1" # the name that will be displayed in the results
36+
alias_lc = "var" # the name used to search for it
37+
38+
[[shells]]
39+
command = "echo $var2 > file.txt" # This will start with $var2 as there is 1 space in the alias_lc
40+
icon_path = "" # optional
41+
alias = "Variables 2" # the name that will be displayed in the results
42+
alias_lc = "var again" # the name used to search for it

src/app.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ impl Tile {
315315
}
316316

317317
Message::RunFunction(command) => {
318-
command.execute(&self.config);
318+
command.execute(&self.config, &self.query);
319319

320320
if self.config.buffer_rules.clear_on_enter {
321321
window::latest()
@@ -430,13 +430,21 @@ impl Tile {
430430

431431
let mut exact: Vec<App> = filter_vec
432432
.par_iter()
433-
.filter(|x| x.name_lc == query)
433+
.filter(|x| match &x.open_command {
434+
Function::RunShellCommand(_) => x
435+
.name_lc
436+
.starts_with(query.split_once(" ").unwrap_or((&query, "")).0),
437+
_ => x.name_lc == query,
438+
})
434439
.cloned()
435440
.collect();
436441

437442
let mut prefix: Vec<App> = filter_vec
438443
.par_iter()
439-
.filter(|x| x.name_lc != query && x.name_lc.starts_with(&query))
444+
.filter(|x| match x.open_command {
445+
Function::RunShellCommand(_) => false,
446+
_ => x.name_lc != query && x.name_lc.starts_with(&query),
447+
})
440448
.cloned()
441449
.collect();
442450

src/commands.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,25 +9,31 @@ use crate::config::Config;
99
#[derive(Debug, Clone)]
1010
pub enum Function {
1111
OpenApp(String),
12-
RunShellCommand(Vec<String>),
12+
RunShellCommand(String),
1313
RandomVar(i32),
1414
GoogleSearch(String),
1515
OpenPrefPane,
1616
Quit,
1717
}
1818

1919
impl Function {
20-
pub fn execute(&self, config: &Config) {
20+
pub fn execute(&self, config: &Config, query: &str) {
2121
match self {
2222
Function::OpenApp(path) => {
2323
NSWorkspace::new().openURL(&NSURL::fileURLWithPath(
2424
&objc2_foundation::NSString::from_str(path),
2525
));
2626
}
2727
Function::RunShellCommand(shell_command) => {
28+
let mut final_command = shell_command.to_owned();
29+
30+
for (argument_num, argument) in query.split_whitespace().enumerate() {
31+
final_command =
32+
final_command.replace(&format!("$var{}", argument_num), argument);
33+
}
2834
Command::new("sh")
2935
.arg("-c")
30-
.arg(shell_command.join(" "))
36+
.arg(final_command)
3137
.status()
3238
.ok();
3339
}

src/config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ impl Default for Buffer {
122122
/// Alias is the text that is used to call this command / search for it
123123
#[derive(Debug, Clone, Deserialize, Serialize)]
124124
pub struct Shelly {
125-
command: Vec<String>,
125+
command: String,
126126
icon_path: Option<String>,
127127
alias: String,
128128
alias_lc: String,

0 commit comments

Comments
 (0)