From 3658941098d0a37baf20ab94dbe93b6d9a2b29ed Mon Sep 17 00:00:00 2001 From: Hamcha Date: Thu, 23 Jan 2020 09:40:00 +0100 Subject: [PATCH] Add wrappers --- Cargo.toml | 4 +++- README.md | 53 ++++++++++++++++++++++++++++++++++++++++------- scripts/osenv.ps1 | 9 ++++++++ scripts/osenv.sh | 12 +++++++++++ 4 files changed, 69 insertions(+), 9 deletions(-) create mode 100644 scripts/osenv.ps1 create mode 100644 scripts/osenv.sh diff --git a/Cargo.toml b/Cargo.toml index da8224f..3ec3750 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,7 +4,9 @@ version = "0.1.0" authors = ["Hamcha "] edition = "2018" -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html +[[bin]] +name = "osenv-bin" +path = "src/main.rs" [dependencies] clap = "2.33" diff --git a/README.md b/README.md index b0b2175..31338e7 100644 --- a/README.md +++ b/README.md @@ -22,12 +22,6 @@ $env:DB_USER = "admin" $env:DB_PASSWORD = "changeme" ``` -Use `osenv` like this: - -```ps1 -osenv -s ps1 | iex -``` - ### *nix shell Example output: @@ -37,8 +31,51 @@ export DB_USER=admin export DB_PASSWORD=changeme ``` -Run `osenv` like this: +## Installation + +### Requirements + +- Rust + Cargo (tested w/ 1.37) +- A compatible shell (powershell/bash/zsh) + +### Compilation ```sh -eval $(osenv) +cargo install --path . ``` + +This will install `osenv-bin` in your cargo bin folder (don't forget to add it to `PATH`!) +You can already use it, with some caveats (having to specify the full string, like `osenv-bin | iex`), but you should just make a function and add it to your shell's profile file. + +### Add to profile + +If you're using sh/bash/zsh, add this to your .bashrc/.zshrc/etc: + +```sh +osenv() { + RES=$(osenv-bin $@) + if [ $? -eq 0 ]; then + eval $RES + else + echo $RES + fi +} +``` + +If you're using Powershell, add this to your `$profile`: + +```ps1 +function osenv { + $cmd = osenv-bin @Args + if ($?) { + $cmd | Invoke-Expression + } + else { + Write-Output $cmd + } +} +``` + +If you rather have them as script to source, you can find them in `scripts` in this repo. + +If you want to enhance osenv to add a special "add to profile" command, or make some scripts that do (easy in powershell, not so much in the shell world), contributions are highly appreciated! diff --git a/scripts/osenv.ps1 b/scripts/osenv.ps1 new file mode 100644 index 0000000..8c66a81 --- /dev/null +++ b/scripts/osenv.ps1 @@ -0,0 +1,9 @@ +function osenv { + $cmd = osenv-bin @Args + if ($?) { + $cmd | Invoke-Expression + } + else { + Write-Output $cmd + } +} \ No newline at end of file diff --git a/scripts/osenv.sh b/scripts/osenv.sh new file mode 100644 index 0000000..cb022e4 --- /dev/null +++ b/scripts/osenv.sh @@ -0,0 +1,12 @@ +#!/bin/sh + +osenv() { + RES=$(osenv-bin $@) + if [ $? -eq 0 ]; then + eval $RES + else + echo $RES + fi +} + +osenv $@ \ No newline at end of file