Skip to content

Commit

Permalink
Unbundle bash_env.sh as bash-env-json (#33)
Browse files Browse the repository at this point in the history
The backend Bash script is now shared by nu_plugin_bash_env and
bash-env-elvish.

It is fetched from the source repo by the Rust build script, so
migration should be seamless.
  • Loading branch information
tesujimath authored Oct 18, 2024
1 parent 7a07f34 commit 198554f
Show file tree
Hide file tree
Showing 9 changed files with 208 additions and 196 deletions.
8 changes: 7 additions & 1 deletion .github/workflows/test-suite.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
name: test suite
on: [push, pull_request]
on:
push:
branches:
- main
pull_request:
branches:
- main
env:
NU_VERSION: 0.98.0

Expand Down
130 changes: 1 addition & 129 deletions Cargo.lock

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

3 changes: 1 addition & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "nu_plugin_bash_env"
version = "0.14.2"
version = "0.15.0"
edition = "2021"
license = "MIT"
description = "Nu plugin bash-env"
Expand All @@ -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
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ The following versions are compatible.
| 0.96 | 0.12.1 |
| 0.97 | 0.13.0 |
| 0.98 | 0.14.2 |
| 0.98 | 0.15.0 |

If you find a new version of Nushell rejects this plugin as incompatible, please report an [issue](https://github.com/tesujimath/nu_plugin_bash_env/issues).

Expand All @@ -38,6 +39,8 @@ The script uses `jq` for output formatting. Previous versions required at least

Also I suspect at least Bash version `5.1`.

Since version `0.15.0`, this plugin uses [`bash-env-json`](https://github.com/tesujimath/bash-env-json) instead of the previously bundled `bash_env.sh` script. However, this is fetched and embedded at build time, so there is no difference at runtime.

## Examples

### Simple Usage
Expand Down Expand Up @@ -132,7 +135,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.1";

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(())
}
Loading

0 comments on commit 198554f

Please sign in to comment.