Add wrappers
This commit is contained in:
parent
cb65dcd72a
commit
3658941098
4 changed files with 69 additions and 9 deletions
|
@ -4,7 +4,9 @@ version = "0.1.0"
|
||||||
authors = ["Hamcha <hamcha@crunchy.rocks>"]
|
authors = ["Hamcha <hamcha@crunchy.rocks>"]
|
||||||
edition = "2018"
|
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]
|
[dependencies]
|
||||||
clap = "2.33"
|
clap = "2.33"
|
||||||
|
|
53
README.md
53
README.md
|
@ -22,12 +22,6 @@ $env:DB_USER = "admin"
|
||||||
$env:DB_PASSWORD = "changeme"
|
$env:DB_PASSWORD = "changeme"
|
||||||
```
|
```
|
||||||
|
|
||||||
Use `osenv` like this:
|
|
||||||
|
|
||||||
```ps1
|
|
||||||
osenv -s ps1 | iex
|
|
||||||
```
|
|
||||||
|
|
||||||
### *nix shell
|
### *nix shell
|
||||||
|
|
||||||
Example output:
|
Example output:
|
||||||
|
@ -37,8 +31,51 @@ export DB_USER=admin
|
||||||
export DB_PASSWORD=changeme
|
export DB_PASSWORD=changeme
|
||||||
```
|
```
|
||||||
|
|
||||||
Run `osenv` like this:
|
## Installation
|
||||||
|
|
||||||
|
### Requirements
|
||||||
|
|
||||||
|
- Rust + Cargo (tested w/ 1.37)
|
||||||
|
- A compatible shell (powershell/bash/zsh)
|
||||||
|
|
||||||
|
### Compilation
|
||||||
|
|
||||||
```sh
|
```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!
|
||||||
|
|
9
scripts/osenv.ps1
Normal file
9
scripts/osenv.ps1
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
function osenv {
|
||||||
|
$cmd = osenv-bin @Args
|
||||||
|
if ($?) {
|
||||||
|
$cmd | Invoke-Expression
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Write-Output $cmd
|
||||||
|
}
|
||||||
|
}
|
12
scripts/osenv.sh
Normal file
12
scripts/osenv.sh
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
osenv() {
|
||||||
|
RES=$(osenv-bin $@)
|
||||||
|
if [ $? -eq 0 ]; then
|
||||||
|
eval $RES
|
||||||
|
else
|
||||||
|
echo $RES
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
osenv $@
|
Loading…
Reference in a new issue