Skip to content

Commit 946551f

Browse files
committed
feat: Add basic Rust impl
1 parent 018e517 commit 946551f

File tree

3 files changed

+312
-3
lines changed

3 files changed

+312
-3
lines changed

Cargo.lock

Lines changed: 201 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,5 @@ name = "choose"
33
version = "0.1.0"
44
edition = "2021"
55

6-
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
7-
86
[dependencies]
7+
clap = { version = "4.0.15", features = ["derive"] }

src/main.rs

Lines changed: 110 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,112 @@
1+
use std::process::Command;
2+
use std::str;
3+
4+
use clap::{Parser,Subcommand};
5+
6+
#[derive(Parser, Debug)]
7+
#[command(author, version, about, long_about = None)]
8+
struct Args {
9+
#[command(subcommand)]
10+
action: Action,
11+
12+
/// Whether or not to show the GUI
13+
#[arg(long, default_value_t = false)]
14+
gui: bool
15+
}
16+
17+
#[derive(Subcommand, Debug)]
18+
enum Action {
19+
Launch {
20+
category: String,
21+
},
22+
Set {
23+
category: String,
24+
value: String
25+
},
26+
Get {
27+
category: String
28+
}
29+
}
30+
31+
// EXECUTION PROVIDER
32+
// rust "inline exec"
33+
// shell script combo (putting together every application of a category in a single shell script to save space / times)
34+
// shell script
35+
// desktop file
36+
37+
fn run(args: &[&str]) {
38+
let output = Command::new("starship").args(["init", "bash", "--print-full-init"]).output().expect("Failed to execute child process");
39+
if output.status.success() {
40+
println!("{}", str::from_utf8(&output.stdout.clone()).unwrap())
41+
} {
42+
println!("{}", str::from_utf8(&output.stderr.clone()).unwrap());
43+
44+
}
45+
}
46+
147
fn main() {
2-
println!("Hello, world!");
48+
let cli = Args::parse();
49+
50+
match cli.action {
51+
Action::Launch { category } => {
52+
match category.as_str() {
53+
"shell-prompt-bash" => {
54+
let args = ["starship", "init", "bash", "--print-full-init"];
55+
run(args.as_slice());
56+
},
57+
"shell-prompt-zsh" => {
58+
let args = ["starship", "init", "zsh", "--print-full-init"];
59+
run(args.as_slice());
60+
},
61+
"menu-bar-text" => {
62+
let args = ["i3blocks"];
63+
run(args.as_slice());
64+
},
65+
"terminal-emulator" => {
66+
let args = ["kitty"];
67+
run(args.as_slice());
68+
},
69+
// brightness
70+
"brightness-increase" => {
71+
72+
},
73+
"brightness-decrease" => {
74+
75+
},
76+
"brightness-reset" => {
77+
78+
},
79+
// song
80+
"song-previous" => {
81+
82+
},
83+
"song-pause" => {
84+
85+
},
86+
"song-next" => {
87+
88+
},
89+
// volume
90+
"volume-lower" => {
91+
92+
},
93+
"volume-raise" => {
94+
95+
},
96+
"volume-mute" => {
97+
98+
},
99+
"window-manager" => {
100+
101+
}
102+
&_ => todo!()
103+
}
104+
},
105+
Action::Set { category, value } => {
106+
107+
},
108+
Action::Get { category } => {
109+
110+
}
111+
}
3112
}

0 commit comments

Comments
 (0)