A concise cli launcher / project manager using env files.
The main goal it's readability and time saving with commands use in your project.
Short it's command-line tool that allow to run program (usually sh script) with environment variables mapping from .env files.
It is like to run eval $(.env_file) ./script.sh
with more options.
- It take care to synchronize and to check the format of all environment files to each other.
- Prompt infos : You always known which is your current setup and environment.
- Allow multiple setups in the same project.
- Allow to store example of no critical environment file in your source code with a public env directory.
- Allow to store prod/stage/etc.. and critical environment file in your source code with a private env directory 🔒.
- You can apply a mapping in order to select, group and add custom formats / cases on the fly on the environment variables.
- The result of mapping will be inject as environment variables in the output .sh script that will be executed.
Require for compilation : libgit2, openssl.
cargo install short
It's really recommended to configure the prompt.
That allow to known every time which setup and
environment are selected.
You can see the command show
for more details.
✨ PS1 (BASH/ZSH)
Example with PS1 configure by .bashrc
shell script
export PS1="$(sht show -f):\w\$ "
Example with PS1 configure by .zshrc
shell script
⚠️ TODO ...
✨ starship
Example with custom pre-prompt : starship.
Here the custom script that starship run before display prompt.
```shell script
function blastoff(){ sht show -f } starshipprecmduser_func=blastoff ```
Preview:
$> [my_setup:my_env] ~/your_project$
Generate a simply sh script who display variables. You can use this base
for what as you want. See generate
for more details.
sht generate <setup_name> <environment_name> <file_kind:sh|bash>
$> sht init
$> sht generate setup_1 test sh -d
$> sht run
-d
: create a sub directory (optional).
🌱 Example with Node && ExpressJs
Generate a simply aws sam project base on this template node-express.
See generate
for more details.
Requirement : You have installed node and npm.
$> sht init
$> sht generate node-express -d -t
$> sht run
-t
: generate from template.
-d
: create a sub directory (optional).
🌱 Example with AWS SAM
Generate a simply aws sam project base on this template aws-node-sam.
See generate
for more details.
Requirement : You have installed SAM and AWS_CLI.
$> sht init
$> sht generate aws-node-sam -d -t
$> sht run
-t
: generate from template.
-d
: create a sub directory (optional).
You can list all templates available with sht generate -l
and add a new one here.
init
project - create an empty projectgenerate
setup - generate a setup inside a project run
setup - 🚀rename
setup - rename a setupnew
env - create new env filesync
env - sync env filesedit
env - edit an env filedir
env directory - set/unset a public env directorypdir
env private directory - set/unset a private env directoryuse
select/switch your setup/environmentshow
your current setup / environmentls
list all setups and environmentsvars
display/compare mapping environment variablesenvs
display/compare environment variablesshort.yaml
init
project.Create an empty short.yaml
configuration file. This one define the your project directory.
All short
command inside of this folder and child's folders take for references this configuration file.
$> sht init
short.yaml (generated)
yaml
setups: {}
generate
setup.Generate an empty setup or a setup from a project templates repository, this command can be also list all available project templates.
✍ Generate an empty setup ️
| Arguments | Required | Description |
| ---------- | -------- | ----------- |
|
| Options | Allow empty* | Default | Description |
| ---------- | -------- | ------- | ----------- |
| -d , --directory | yes |
Example : create a setup named my_setup
with .test
environment file and bash
script.
$> sht generate my_setup test bash
short.yaml (generated) : Configuration file.
setups:
my_setup:
file: run.sh
array_vars:
all:
pattern: ".*"
case: CamelCase
format: "[{key}]='{value}'"
delimiter: " "
vars: []
.test (generated) : Environment file.
VAR1=VALUE1
VAR2=VALUE2
run.sh (generated) : Runnable file.
```
declare -A all && eval all=($ALL)
declare -p all
``
The seconds line
declare -A all && eval all=($ALL)` allow to use bash associative array.
🌱 List all project templates
$> sht generate -l
🌱 Generate setup from projects template
| Arguments | Required | Description |
| ---------- | -------- | ----------- |
|
| Options | Allow empty* | Default | Description |
| ---------- | -------- | ------- | ----------- |
| -t , --template | yes | -l
|
| -d , --directory | yes |
Example : create a setup node-express
with its associated envs.
$> sht generate node-express -t
👉 short.yaml (generated) and run.sh (generated) with generate from the following project template : node-express.
run
setupRun the runnable script.
📜 Details
| Arguments | Required | Description |
| ---------- | -------- | ----------- |
| \
$> sht run
rename
setupRename setup. e.g my_setup
-> another_setup
.
$> sht rename my_setup another_setup
new
envCreate new env. e.g dev
$> sht new dev
Or private env. e.g prod
$> sht new dev -p
🔒 -p
save the file in the private directory.
sync
envSync all environment and ask you for each diff what to do.
$> sht sync
edit
envEdit an environment file with your default text editor. You can choose different editor with --editor <editor>
or EDITOR
env vars.
$> sht edit
dir
env directorySet or unset env directory.
$> sht dir ./envs/
$> sht dir --unset
pdir
env private directorySet or unset env directory.
$> sht pdir ../private_envs/
$> sht pdir --unset
use
select/switch your setup/environment📜 Details
| Arguments | Required | Description |
| ---------- | -------- | ----------- |
|
In this example we have two setups named
my_setup_1
,my_setup_2
and two environment files nameddev
,prod
. We have to select the setup and the environmentdev
and we switch of toprod
environment.
e.g. Select my_setup_1
with dev
environment.
$> sht use my_setup_1 dev
e.g. Switch from dev
to prod
environment.
$> sht use prod
👉 If a setup and environment if already selected, you can avoid to provide the setup and just indicate the environment that you want.
Now we switch to the second setup
my_setup_2
. For that we must to specified the setup and the environment.
e.g. Switch from my_setup_1
to my_setup_2
keeping prod
environment.
$> sht use my_setup_2 prod
show
your current setup / environment📜 Details
| Options | Default | Description |
| ---------- | ------- | ----------- |
| -f, --format | [{setup}:{env}]
| Display format |
$> sht show
💁 your current setup is `my_setup`:`dev`
👉 This command can be use for display the current setup / env in prompt part of the shell.
So you can use the option -f
(format). This option remove the return line, and you can
format the format as you wanted. By default the value it's [{setup}:{env}]
.
- {setup}
will be replace by the current setup name.
- {env}
will be replace by the current environment name.
Full example
In this example we have one setup named
my_setup
and two environment files nameddev
andprod
. We have to select the setup and the environmentdev
and we switch of toprod
environment.
$> sht use my_setup dev
$> sht show
💁 your current setup is `my_setup`:`dev`
$> sht use prod
$> sht show
💁 your current setup is `my_setup`:`prod`
ls
list all setups and environmentsList all setups / environments and indicated the current one like sht show
.
```
$> sht ls
myproject (run.sh)
prod (.prod)
dev (.dev)
mysubproject1 (mysubproject1/run.sh)
prod (subenv/.prod)
staging (subenv/.staging)
test (subenv/.test)
mysubproject2 (mysubproject2/run.sh)
prod (subenv/.prod) staging (subenv/.staging) test (sub_env/.test) ```
vars
display/compare mapping environment variablesAs you can see with the variables explanation.
There is two displays environment variables (UPPERCASE) and variables (lowercase).
<variable> | <ENVIRONMENT_VARIABLE> | <value>
.. | .. | ..
When variable are an array this will be displayed like this.
<variable> | <ENVIRONMENT_VARIABLE> (<pattern>) `case`
| <IN_ARRAY_ENVIRONMENT_VARIABLE> | <value>
| .. | ..
e.g. Display variables mapping of test
current environment
$> sht vars
| test
all | ALL (.*)
| VAR1 | VALUE1
| VAR2 | VALUE2
var1 | VAR1 | VALUE1
var2 | VAR2 | VALUE2
short_setup | SHORT_SETUP | my_sub_project_2
short_env | SHORT_ENV | test
e.g Compare variables mapping of test
and prod
environment
$> sht vars -e prod test
| prod | test
all | ALL (.*)
| VAR1 | VALUE1 | VALUE1
| VAR2 | VALUE2_OF_PROD | VALUE2
var1 | VAR1 | VALUE1 | VALUE1
var2 | VAR2 | VALUE2_OF_PROD | VALUE2
short_setup | SHORT_SETUP | my_sub_project_2 | my_sub_project_2
short_env | SHORT_ENV | prod | test
envs
display/compare environment variablese.g. Display variables of test
current environment
$> sht vars
| test
VAR1 | VALUE1
VAR2 | VALUE2
e.g. Compare variables of test
and prod
environment
$> sht vars -e prod test
| prod | test
VAR1 | VALUE1 | VALUE1
VAR2 | VALUE2_OF_PROD | VALUE2
short.yaml
```yaml
setups:
```
<...>
means that you can put any attribute name as you want.
Setup name
Path to the a runnable script.
Path towards the project subdirectory.
This configuration allow to group and apply custom format and mapping in one environment variables.
Environment file
VAR1=VALUE1
VAR2=VALUE2
PREFIX_VAR1=P_VALUE1
PREFIX_VAR2=P_VALUE2
Environment variable will be injected, see ArrayVar.format for more details.
GROUP1 => VAR1:VALUE1,VAR2:VALUE2,PREFIX_VAR1:P_VALUE1,PREFIX_VAR2:P_VALUE2
GROUP2 => [PrefixVar1]='P_VALUE1' [PrefixVar2]='P_VALUE2'
All variables match with this pattern will be grouped.
For more indications see the lib(regex)* that it's used.
Apply a case for each variables.
| Available cases | | ------------------- | | CamelCase | | snakecase | | SHOUTYSNAKE_CASE | | mixedCase | | Title Case |
For more indications see the lib(heck)* that it's used.
Format that it's apply on each variables and that will be concatenated in a string.
There is two data who can used : {key}
and {value}
.
- key
it's the variables name that is specified in the environment file.
- value
it's the variables value that is specified in the environment file.
👉 By default (sh) the format {key}:{value}
it's applied.
👉 By default (bash) it apply a format bash associative array format [{key}]='{value}'
(doc).
A string that it's injected between each variables of the array.
👉 By default it's one space "".
Variables as set here, are selected for injection.
👉 Must match with environment variables.
👉 If it's no specified, all variables are selected.
👉 If it's empty like vars: []
, any variables are selected.
``` USAGE: sht [SUBCOMMAND]
FLAGS: -h, --help Prints help information -V, --version Prints version information
SUBCOMMANDS:
init Init project, create an empty "short.yaml" configuration file.
generate Generate empty setup or from project template repository.
run Run setup [ARGS...].
rename Rename setup.
new Create env file ".
short.yaml
It's a directory with the configuration file short.yaml
inside it : that defined the project root.
All short
commands inside of this folder and his child's folders take for references this configuration file.
init
command.Setup it's is main concept of short. The setup configuration is describe in short.yaml
and you can add more than once. It take a name, a runnable file, public env directory and mapping options.
This is how short gets an easily way to simplify run command.
👉 Each setup one and only one runnable file.
generate
ls
command.vars
command.These directories store .<env>
files.
Env files presents in this directories will be synchronised to each other.
if these set to the same setup.
This directory must be inside of your project (The default value it's the root folder of the project).
That can be a sub folder like ./env/
see setup configuration for more details.
So if you had configured git or another code versioning solution, public directory allow to save with your code
no critical configuration files like an example configuration file.
.
└── project
├── envs # public env directory
│ └── .dev
├── ...
└── short.yaml
dir
command. This directory must be outside of your project. The path of the private directory
will be not store in project configuration ✅ ! So if you had configured git or
another code versioning solution that will be never commit with your code and any
clues of your private directory will be appear to the short configuration short.yaml
.
.
├── envs # private env directory
│ └── .dev
└── project
├── run.sh
└── short.yaml
pdir
command. .<environment_name>
Each environment file define one environment in order to the environment name come from the file name like .<my_env>
environment file => my_env
environment name.
👉 The prefix .
is mandatory.
The file formatting must be follow the RFC 2 – .env file guide line. ```
VAR1=VALUE1 VAR2=VALUE2 ```
Each environment inside on the same setup (public environment directory/private environment directory), are synchronised to each other. So value can be changed but, variables,variables order,spaces, comments will be the sames.
new
command.ls
command.envs
command.edit
command.Variables can be come from the environment file or specified in the configuration file : array_vars and vars.
👉 Injected to script as an environment variables, variables name will be converted to UPPER_CASE. (See also vars
command).
👉 Represented as an variables, they always be converted to lower_case. (See also vars
command).
This display is used only for the cli output readability, like commands as vars
Option like -d
who can found in sht generate my_template my_env -d
can have three state.
1) Deactivate you not specified the option : e.g. sht generate my_template my_env
2) Activate; take the value by default : e.g. sht generate my_template my_env -d
The value of -d
is my_template
.
3) Activate with value : e.g. sht generate my_template my_env -d foo
.
The value of -d
is foo
.