Skip to content

Commit

Permalink
add a new --interactive switch to toolkit.nu run (#112)
Browse files Browse the repository at this point in the history
this allows to drop in an interactive shell and run `gm` commands.
`code: closure` is now optional but will throw an error when not given
in non-interactive mode.
  • Loading branch information
amtoine authored Nov 28, 2023
1 parent 30064ba commit e91ba6a
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions toolkit.nu
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@ export def "install" [] {
# clean the environment before running the code
# > toolkit run --clean { gm clone https://github.com/amtoine/nu-git-manager --depth 1 }
export def "run" [
code: closure, # the code to run in the environment
code?: closure, # the code to run in the environment (required without `--interactive`)
--clean, # raise this to clean the environment before running the code
--interactive, # run interactively
] {
const GM_ENV = {
GIT_REPOS_HOME: ($nu.temp-path | path join "nu-git-manager/repos/"),
Expand All @@ -51,5 +52,26 @@ export def "run" [
}
}

with-env $GM_ENV $code
if $interactive {
const CONFIG_FILE = ($GM_ENV.GIT_REPOS_HOME | path dirname | path join "config.nu")
const ENV_FILE = ($GM_ENV.GIT_REPOS_HOME | path dirname | path join "env.nu")

"$env.config = {show_banner: false}" | save --force $CONFIG_FILE
"" | save --force $ENV_FILE

with-env ($GM_ENV | merge {PROMPT_COMMAND: "NU-GIT-MANAGER"}) {
^$nu.current-exe [
--env-config $ENV_FILE
--config $CONFIG_FILE
--execute "use ./src/nu-git-manager *"
]
}
} else {
if $code == null {
error make --unspanned {
msg: "`toolkit.nu run requires a `$code` when `--interactive` is not used"
}
}
with-env $GM_ENV $code
}
}

0 comments on commit e91ba6a

Please sign in to comment.