Skip to content

Commit

Permalink
Environment variables correctly exported, shell vars not yet
Browse files Browse the repository at this point in the history
  • Loading branch information
tesujimath committed Oct 18, 2024
1 parent 7a07f34 commit cd86b9a
Show file tree
Hide file tree
Showing 7 changed files with 175 additions and 175 deletions.
128 changes: 0 additions & 128 deletions Cargo.lock

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

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ itertools = "0.13.0"
nu-plugin = "0.98.0"
nu-protocol = "0.98.0"
once_cell = "1.19.0"
rust-embed = "8.5.0"
serde = "1.0.208"
serde_json = "1.0.125"
shellexpand = "3.1.0"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ Prior to 0.13.0 this plugin was written in Bash, with the Nu plugin protocol don

Since 0.13.0, the plugin is written in Rust, with the much simplified Bash script embedded.

By default the embedded Bash script is extracted at runtime into a temporary directory. This behaviour may be overridden by setting the ``NU_PLUGIN_BASH_ENV_SCRIPT` environment variable, which is then expected to resolve to the path of the pre-installed script.
By default the embedded Bash script is extracted at runtime into a temporary directory. This behaviour may be overridden by setting the ``NU_PLUGIN_BASH_ENV_JSON` environment variable, which is then expected to resolve to the path of the pre-installed script.

## Logging

Expand Down
54 changes: 54 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
use std::{
env,
path::{Path, PathBuf},
};

const BASH_ENV_JSON_VERSION: &str = "0.6.0";

fn fetch_bash_env_json() -> Option<PathBuf> {
let out_dir: PathBuf = env::var("OUT_DIR").unwrap().into();
let bash_env_json_repo_dir = PathBuf::from("bash-env-json");
let bash_env_json_repo_path = out_dir.join(bash_env_json_repo_dir.as_path());

if Path::exists(&bash_env_json_repo_path) {
Some(bash_env_json_repo_path)
} else {
let bash_env_json_repo_path_str = bash_env_json_repo_path.to_string_lossy();
let git_args = [
"clone",
"--filter=blob:none",
"--branch",
BASH_ENV_JSON_VERSION,
"https://github.com/tesujimath/bash-env-json.git",
bash_env_json_repo_path_str.as_ref(),
];
println!("cargo:warning=git {}", &git_args.join(" "));
match std::process::Command::new("git").args(git_args).output() {
Ok(output) => {
if output.status.success() {
Some(bash_env_json_repo_path)
} else {
println!(
"cargo:warning=git {:?} failed: {}",
&git_args, output.status
);

None
}
}
Err(e) => {
println!("cargo:warning=git clone failed: {}", e);

None
}
}
}
}

fn main() -> std::io::Result<()> {
if let Some(_bash_env_json_repo_path) = fetch_bash_env_json() {
// TODO what now?
}

Ok(())
}
58 changes: 57 additions & 1 deletion flake.lock

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

Loading

0 comments on commit cd86b9a

Please sign in to comment.