Coder Social home page Coder Social logo

envr's Introduction

envr

Simple Development Environment Manager

envr is a self-contained cross-platform script (envr.ps1) that allows developers to specify environment variables, aliases, and additions to the system path.

Compatibility

envr can be used with bash, zsh, and PowerShell in Linux, Windows, and MacOS. See the github workflows for more information on the shells that are tested.

Usage

  • Activate the environment: . ./envr.ps1
    • You can alias envr to . ./envr.ps1 in your shell profile for convenience
  • Deactivate the environment: unsource
  • Upgrade to the latest version:
    wget -O envr.ps1 https://github.com/JPHutchins/envr/releases/latest/download/envr.ps1
    
  • Verify the integrity of your copy of envr:
    wget -O - https://github.com/JPHutchins/envr/releases/latest/download/sha256.sum | shasum --check
    
    Windows users may compare the SHA256s manually:
    (Invoke-WebRequest https://github.com/JPHutchins/envr/releases/latest/download/sha256.sum).RawContent 
    (Get-FileHash -Path envr.ps1 -Algorithm SHA256).hash
  • Verify the authenticity of your copy of envr with cosign:

    Note: you must install cosign.

    wget envr.ps1 https://github.com/JPHutchins/envr/releases/latest/download/envr.ps1.cosign.bundle
    cosign verify-blob envr.ps1 --bundle envr.ps1.cosign.bundle --certificate-identity https://github.com/JPHutchins/envr/.github/workflows/release.yml@refs/tags/0.5.7 --certificate-oidc-issuer https://token.actions.githubusercontent.com
    rm envr.ps1.cosign.bundle
    

    Note: the section release.yml@refs/tags/<TAG> must be updated with the version that you are verifying.

Adding envr to Your Repository

  • Download and commit envr.ps1 to the root of your repository. This routine is also a good way to upgrade your envr.ps1 to the latest version.
    • Linux/Mac/Windows using wget:
      wget -O envr.ps1 https://github.com/JPHutchins/envr/releases/latest/download/envr.ps1
      
    • Windows without wget:
      Invoke-WebRequest -OutFile envr.ps1 -Uri https://github.com/JPHutchins/envr/releases/latest/download/envr.ps1
  • Create, define and commit envr-default to the root of your repository.
  • Modify your .gitignore to ignore envr-local.

Define Your Environment in envr-default

envr-default (and envr-local) is a INI/TOML-ish text file of the following shape. Currently four categories are supported, marked by [ ]. Definitions are in the format KEY=VALUE.

Note: inline comments are not supported

[PROJECT_OPTIONS]
# This sets the environment variable ENVR_PROJECT_NAME for use by the environment
PROJECT_NAME=coolrepo
# If you have a python venv, envr can activate it along with the envr environment
PYTHON_VENV=venv

[VARIABLES]
FOO=bar
ANSWER=42
PLUGINS=~/chuck/ext/plugins
# Environment variables can use other environment variables
PATH_SNOOPY_TOOL=$PLUGINS/x86/v436.874/snoopy-ext/bin

[ADD_TO_PATH]
# Here, the key "TOOLCHAIN_PATH" is not exported to PATH but rather
# it is used internally to keep track of modifications to PATH
TOOLCHAIN_PATH=/opt/supercollider/system/arm32/bin
# ENVR_ROOT is an environment variable set by envr
# It is the full path to envr.ps1 (the root of your repo)
BINARIES=$ENVR_ROOT/build/bin

[ALIASES]
build=cmake -GNinja -Bbuild -DBOARD=hrv43 -DCMAKE_BUILD_TYPE=Debug -DLOG_LEVEL=INFO && cmake --build build
flash=cmake -GNinja -Bbuild -DBOARD=hrv43 -DCMAKE_BUILD_TYPE=Debug -DLOG_LEVEL=INFO && cmake --build build --target flash

Use the Environment Definition

  • . ./envr.ps1 from the root of your repository.

  • envr always reads envr-default first, followed by envr-local if it exists.

    envr-local is used to provide the necessary local modifications to environment variables, paths, and aliases. envr-default keys that are not overwritten by envr-local will be available as they were defined in envr-default. Users can add keys to their envr-local, though it would often be preferred to update envr-default as well so that everyone can be benefit from the definitions.

Restore Previous Shell Environment (deactivate)

  • unsource

Installation

envr does not need to be installed, but it can be nice to add the alias envr to your shell profile, allowing you to activate the environment of the current directory with envr instead of . ./envr.ps1.

PowerShell

Add-Content -Path $profile -Value "function envr { . ./envr.ps1 }"

bash

echo "alias envr='. ./envr.ps1'" >> ~/.bashrc

zsh

echo "alias envr='. ./envr.ps1'" >> ~/.zshrc

Why .ps1?

#$&*%^

Because PowerShell scripts don't run with any other extension.

Motivation

The goal of envr is to unify the development environment setup of any repository by providing a consistent interface for Windows, MacOS, and GNU/Linux shells.

envr testing and development

git clone [email protected]:JPHutchins/envr.git
cd envr
git checkout develop
git checkout -b feature/my-feature-branch-name

Unit Tests

  • Tests are run from this repository root.
    • Windows PS: .\tests\windows\ps.ps1
    • Windows WSL bash: bash tests/sh/bash.sh
    • Windows WSL bash with zsh installed: bash tests/sh/zsh.sh
    • Linux/macOS bash: tests/sh/bash.sh
    • Linux/macOS zsh: tests/sh/zsh.sh
    • Linux/macOS all shells: tests/sh/all.sh recommended to verify bash zsh compatibility.
  • Add tests for any new shell, feature, or compatibility update.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.