From 780fd5a15be494622e6b895a5d041daad0d5380c Mon Sep 17 00:00:00 2001 From: KaranveerB <52545097+KaranveerB@users.noreply.github.com> Date: Sat, 30 Aug 2025 22:49:55 -0700 Subject: [PATCH] Rename the program to xrun Avoids conflicts with slurm. May change in the future. --- Cargo.lock | 24 ++++++++++++------------ Cargo.toml | 2 +- README.md | 30 +++++++++++++++--------------- src/main.rs | 4 ++-- tests/integration_test.rs | 14 +++++++------- 5 files changed, 37 insertions(+), 37 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d69d360..e0b8c06 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -390,18 +390,6 @@ version = "0.4.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7a2ae44ef20feb57a68b23d846850f861394c2e02dc425a50098ae8c90267589" -[[package]] -name = "srun" -version = "0.1.0" -dependencies = [ - "assert_cmd", - "rstest", - "tempfile", - "test-case", - "toml", - "xdg", -] - [[package]] name = "syn" version = "2.0.106" @@ -648,3 +636,15 @@ name = "xdg" version = "3.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2fb433233f2df9344722454bc7e96465c9d03bff9d77c248f9e7523fe79585b5" + +[[package]] +name = "xrun" +version = "0.1.0" +dependencies = [ + "assert_cmd", + "rstest", + "tempfile", + "test-case", + "toml", + "xdg", +] diff --git a/Cargo.toml b/Cargo.toml index fbb916d..11dc732 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "srun" +name = "xrun" version = "0.1.0" edition = "2021" diff --git a/README.md b/README.md index 3d0e1bf..f010db5 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# srun +# xrun A program to help manage scripts/alias with a flexible subcommand like structure. @@ -8,12 +8,12 @@ under a subcommand) and a more convenient place to store cool one liners. This program is in development and many features/changes may be made over time. -See my [dotfiles](https://github.com/KaranveerB/Dotfiles/blob/master/.config/srun/command.toml) +See my [dotfiles](https://github.com/KaranveerB/Dotfiles/blob/master/.config/xrun/command.toml) for a real-world example of its usage. ## Configuring -The program reads from `$XDG_CONFIG_HOME/srun/command.toml` for commands. This -is usually `~/.config/srun/command.toml`. +The program reads from `$XDG_CONFIG_HOME/xrun/command.toml` for commands. This +is usually `~/.config/xrun/command.toml`. Each command can have the following keys * `command`: (optional for subcommands) A string of the command to execute. @@ -29,28 +29,28 @@ bid-farewell = { command = "echo bye", desc = "says bye" } [msg.greet] desc = "greets the user" -command = "srun msg greet kind" +command = "xrun msg greet kind" casual = { command = "echo sup", desc = "says sup" } kind = { command = "echo hi", desc = "says hi" } ``` You can then use the program as follows ```sh -> srun msg greet +> xrun msg greet hi -> srun msg greet kind +> xrun msg greet kind hi -> srun msg greet casual +> xrun msg greet casual sup -> srun msg bid-farewell +> xrun msg bid-farewell bye -> srun msg --help -usage: srun msg [command] +> xrun msg --help +usage: xrun msg [command] commands: bid-farewell: says bye greet: greets the user -> srun msg greet --help -usage: srun msg greet [command] +> xrun msg greet --help +usage: xrun msg greet [command] greets the user commands: @@ -61,14 +61,14 @@ commands: ## Passthrough Using the `--passthrough` flag prints the shell commands to stdout. This can be used to run the command directly in the current shell and avoid any -weirdness/performance hits of spawning a new shell as a child of `srun`. +weirdness/performance hits of spawning a new shell as a child of `xrun`. An exit code of `125` is returned if a shell command was returned. This can be used in bash like shells (or whatever equivalent for your shell) as follows: ```bash -function srun() { +function xrun() { output=$("$@" 2>&1) if [ $? -eq 125 ]; then eval "$output" diff --git a/src/main.rs b/src/main.rs index 9f843a3..9dd6957 100644 --- a/src/main.rs +++ b/src/main.rs @@ -15,7 +15,7 @@ enum Action { Help, } -const PROG_NAME: &str = "srun"; +const PROG_NAME: &str = "xrun"; fn main() -> Result<(), Box> { let args: Vec = env::args().skip(1).collect(); @@ -43,7 +43,7 @@ fn main() -> Result<(), Box> { std::process::exit(1); } - let xdg_dirs = xdg::BaseDirectories::with_prefix("srun"); + let xdg_dirs = xdg::BaseDirectories::with_prefix(PROG_NAME); let path: std::path::PathBuf = xdg_dirs .find_config_file("command.toml") .unwrap_or_else(|| { diff --git a/tests/integration_test.rs b/tests/integration_test.rs index 271dbcb..a16e911 100644 --- a/tests/integration_test.rs +++ b/tests/integration_test.rs @@ -22,9 +22,9 @@ struct TestSetup { fn create_test_setup(config: &[u8]) -> TestSetup { let tmp_dir = TempDir::new().unwrap(); - let _ = fs::create_dir(tmp_dir.path().join("srun")); - let _ = fs::write(tmp_dir.path().join("srun/command.toml"), config); - let mut cmd = Command::cargo_bin("srun").unwrap(); + let _ = fs::create_dir(tmp_dir.path().join("xrun")); + let _ = fs::write(tmp_dir.path().join("xrun/command.toml"), config); + let mut cmd = Command::cargo_bin("xrun").unwrap(); cmd.env("XDG_CONFIG_HOME", tmp_dir.path()); cmd.env("SHELL", "sh"); @@ -127,7 +127,7 @@ fn test_exec_stdin() { #[rstest] fn test_help_subcommand(basic_cmd: TestSetup) { let stdout = concat!( - "usage: srun s [command]\n", + "usage: xrun s [command]\n", "s desc\n", "\n", "commands:\n", @@ -147,7 +147,7 @@ fn test_help_subcommand_no_desc() { "# .as_bytes(); let stdout = concat!( - "usage: srun s [command]\n", + "usage: xrun s [command]\n", "commands:\n", " c1: c1 desc\n", " c2\n", @@ -158,13 +158,13 @@ fn test_help_subcommand_no_desc() { #[rstest] fn test_help_command(basic_cmd: TestSetup) { - let stdout = concat!("usage: srun s c1\n", "c1 desc\n"); + let stdout = concat!("usage: xrun s c1\n", "c1 desc\n"); test_cmd(basic_cmd, "s c1 --help", stdout, "", 0); } #[rstest] fn test_help_command_no_desc(basic_cmd: TestSetup) { - let stdout = "usage: srun s c2\n"; + let stdout = "usage: xrun s c2\n"; test_cmd(basic_cmd, "s c2 --help", stdout, "", 0); }