shoka 0.1.0

A repository workspace manager — jj-aware, TUI-first successor to ghq / rhq.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
use crate::cli::{InitShellArgs, SupportedShell};

pub async fn run(args: InitShellArgs) -> anyhow::Result<()> {
    let name = &args.name;
    let script = match args.shell {
        SupportedShell::Powershell => format!(
            "function {name} {{\n    $dest = shoka cd @args\n    if ($LASTEXITCODE -eq 0 -and $dest) {{ Set-Location -LiteralPath $dest }}\n}}\n"
        ),
        SupportedShell::Bash | SupportedShell::Zsh => format!(
            "{name}() {{\n    local dest\n    dest=$(shoka cd \"$@\") && [ -n \"$dest\" ] && cd -- \"$dest\"\n}}\n"
        ),
        SupportedShell::Fish => format!(
            "function {name}\n    set dest (shoka cd $argv)\n    if test $status -eq 0; and test -n \"$dest\"\n        cd -- \"$dest\"\n    end\nend\n"
        ),
    };
    print!("{script}");
    Ok(())
}