Skip to content

Commit 4d74f99

Browse files
committed
improve customizability
1 parent 3c0790a commit 4d74f99

File tree

8 files changed

+227
-108
lines changed

8 files changed

+227
-108
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,5 @@ edition = "2021"
55

66
[dependencies]
77
clap = { version = "4.0.15", features = ["derive"] }
8+
serde = { version = "1.0.152", features = ["derive"] }
9+
serde_json = "1.0.91"

bake

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rustfmt.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
hard_tabs = true
2+
tab_spaces = 3

src/cli.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
use std::str;
2+
3+
use clap::{Parser, Subcommand};
4+
5+
#[derive(Parser, Debug)]
6+
#[command(author, version, about, long_about = None)]
7+
pub struct Args {
8+
#[command(subcommand)]
9+
pub action: Action,
10+
11+
/// Whether or not to show the GUI
12+
#[arg(long, default_value_t = false)]
13+
pub gui: bool,
14+
}
15+
16+
#[derive(Subcommand, Debug)]
17+
pub enum Action {
18+
Launch { category: String },
19+
Set { category: String, choice: String },
20+
Get { category: String },
21+
Install { category: String, choice: String },
22+
Uninstall { category: String, choice: String },
23+
Test { category: String, choice: String },
24+
}

src/launcher.sh

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/usr/bin/env bash
2+
3+
_die() {
4+
printf '%s\n' 'Error: ' "$1" 2>&1
5+
}
6+
7+
_main() {
8+
local file="$1"
9+
local action="$2"
10+
shift || _die 'Failed shift'
11+
shift || _die 'Failed shift'
12+
13+
# shellcheck disable=SC1090
14+
source "$file"
15+
if [ "$action" = 'install' ]; then
16+
install "$@"
17+
elif [ "$action" = 'uninstall' ]; then
18+
uninstall "$@"
19+
elif [ "$action" = 'test' ]; then
20+
test "$@"
21+
elif [ "$action" = 'launch' ]; then
22+
launch "$@"
23+
fi
24+
}
25+
26+
_main "$@"

src/main.rs

Lines changed: 47 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -1,124 +1,74 @@
1-
use std::process::Command;
2-
use std::str;
1+
use clap::Parser;
2+
use cli::{Action, Args};
33

4-
use clap::{Parser,Subcommand};
4+
mod cli;
55

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-
}
6+
mod util;
307

318
// EXECUTION PROVIDER
329
// rust "inline exec"
3310
// shell script combo (putting together every application of a category in a single shell script to save space / times)
3411
// shell script
3512
// desktop file
3613

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-
4714
fn main() {
4815
let cli = Args::parse();
16+
let mut data = util::get_data();
4917

5018
match cli.action {
5119
Action::Launch { category } => {
5220
match category.as_str() {
53-
"application-launcher" => {
54-
55-
},
56-
"file-manager" => {
57-
58-
},
59-
"image-viewer" => {
60-
61-
},
62-
"image-editor" => {
63-
64-
},
21+
"application-launcher" => {}
22+
"file-manager" => {}
23+
"image-viewer" => {}
24+
"image-editor" => {}
6525
"shell-prompt-bash" => {
66-
let args = ["starship", "init", "bash", "--print-full-init"];
67-
run(args.as_slice());
68-
},
26+
let choice = data
27+
.choices
28+
.shell_prompt_bash
29+
.unwrap_or(String::from("starship"));
30+
util::launch("shell-prompt-bash", choice);
31+
}
6932
"shell-prompt-zsh" => {
70-
let args = ["starship", "init", "zsh", "--print-full-init"];
71-
run(args.as_slice());
72-
},
33+
let _args = vec!["starship", "init", "zsh", "--print-full-init"];
34+
}
7335
"menu-bar-text" => {
74-
let args = ["i3blocks"];
75-
run(args.as_slice());
76-
},
36+
let _args = vec!["i3blocks"];
37+
}
7738
"terminal-emulator" => {
78-
let args = ["kitty"];
79-
run(args.as_slice());
80-
},
39+
let _args = vec!["kitty"];
40+
}
8141
// brightness
82-
"brightness-increase" => {
83-
84-
},
85-
"brightness-decrease" => {
86-
87-
},
88-
"brightness-reset" => {
89-
90-
},
42+
"brightness-increase" => {}
43+
"brightness-decrease" => {}
44+
"brightness-reset" => {}
9145
// song
92-
"song-previous" => {
93-
94-
},
95-
"song-pause" => {
96-
97-
},
98-
"song-next" => {
99-
100-
},
46+
"song-previous" => {}
47+
"song-pause" => {}
48+
"song-next" => {}
10149
// volume
102-
"volume-lower" => {
103-
104-
},
105-
"volume-raise" => {
106-
107-
},
108-
"volume-mute" => {
109-
110-
},
111-
"window-manager" => {
112-
113-
}
114-
&_ => todo!()
50+
"volume-lower" => {}
51+
"volume-raise" => {}
52+
"volume-mute" => {}
53+
"window-manager" => {}
54+
&_ => todo!(),
11555
}
116-
},
117-
Action::Set { category, value } => {
118-
119-
},
120-
Action::Get { category } => {
56+
}
57+
Action::Set { category, choice } => {
58+
match category.as_str() {
59+
"shell-prompt-bash" => data.choices.shell_prompt_bash = Some(String::from(choice)),
60+
_ => {}
61+
};
12162

63+
util::save_data(&data);
64+
}
65+
Action::Get { category: _ } => {}
66+
Action::Install { category, choice } => {
67+
util::run(category.as_str(), choice.as_str(), "install")
68+
}
69+
Action::Uninstall { category, choice } => {
70+
util::run(category.as_str(), choice.as_str(), "uninstall")
12271
}
72+
Action::Test { category, choice } => util::run(category.as_str(), choice.as_str(), "test"),
12373
}
12474
}

0 commit comments

Comments
 (0)