Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "srun"
name = "xrun"
version = "0.1.0"
edition = "2021"

Expand Down
30 changes: 15 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# srun
# xrun
A program to help manage scripts/alias with a flexible subcommand like
structure.

Expand All @@ -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.
Expand All @@ -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:
Expand All @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ enum Action {
Help,
}

const PROG_NAME: &str = "srun";
const PROG_NAME: &str = "xrun";

fn main() -> Result<(), Box<dyn std::error::Error>> {
let args: Vec<String> = env::args().skip(1).collect();
Expand Down Expand Up @@ -43,7 +43,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
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(|| {
Expand Down
14 changes: 7 additions & 7 deletions tests/integration_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand Down Expand Up @@ -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",
Expand All @@ -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",
Expand All @@ -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);
}

Expand Down