Movatterモバイル変換


[0]ホーム

URL:


Search

Lib.rs

Configuration|Development tools
#env-var#shell#shell-environment#direnv#hook#envrc

appquickenv

An unintrusive environment manager

16 releases

new0.4.2Mar 19, 2025
0.4.1Jan 27, 2025
0.3.10Jun 12, 2023
0.3.9Apr 30, 2023
0.1.0Jul 21, 2022

#19 inConfiguration

Download history19/week @ 2024-12-07184/week @ 2025-01-2541/week @ 2025-02-0158/week @ 2025-02-0830/week @ 2025-02-15107/week @ 2025-03-15

107 downloads per month

MITlicense

42KB
861lines

quickenv: An unintrusive environment manager

direnv is a manager for loading/unloading environmentvariables per-project. It achieves this by hooking into your shell andexecuting a shellscript called.envrc uponcd, loading environmentvariables generated by that shellscript into your current shell. It is usefulfor automatically activatingvirtualenvs, for example.

Unfortunatelydirenv can be a little bit "intrusive" to use. For a start, itruns its own code in your shell. This alone is not noticeable in terms ofterminal responsiveness, but the various.envrcs that people end up writingsometimes are.direnv does not have a reliable, out-of-the-box way to cachethe execution of.envrcs, as it is arbitrary code, and so it runs everytimeyoucd in and out of a project.

quickenv is a replacement fordirenv. It works with existing.envrcs, andas such is a drop-in replacement, but how you interact withquickenv and howit loads environment variables is fundamentally different.

  • quickenv does not hook into your shell. It only requires an addition toyourPATH.
  • quickenv does not load.envrc when changing directories. Instead you needto initializequickenv per-project usingquickenv reload, and rerun thatcommand everytime the.envrc changes.
  • quickenv does not even load environment variables into your shell. Insteadit creates shim binaries that dispatch to the right executable.

quickenv is heavily inspired byvolta which achievesversion management for nodejs by also providing "shim" binaries for the mostcommon commands (yarn,npm,node).

Installation

Install quickenv:

Then set it up in your shell:

# Into your bashrc/zshrc. This should be at the front of your PATH, such that# quickenv can shim/shadow binaries effectively.export PATH=$HOME/.quickenv/bin/:$PATH# You can remove "direnv hook" from your bashrc/zshrc, but the tool needs to# stay installed.

Some notes:

  • quickenv currently assumesdirenv is in your path, in order to load its"standard library".

  • quickenv also currently does not have pre-built binaries. You need toinstall Rust and install it using Rust's packagemanager, Cargo.

  • quickenv assumes a POSIX environment.

Building from source

cargo install quickenv# latest stable releasecargo install --git https://github.com/untitaker/quickenv  # latest git SHA

Usage

We're going to check outsentry, becausethat's one of the.envrcs I use. Note that Sentry's.envrc only works onMacOS.

git clone https://github.com/getsentry/sentrycd sentry# Execute the .envrc and cache the resulting environment variables in ~/.quickenv/envs/.# Sentry will prompt you to create a virtualenv, install dependencies via homebrew, etc.# Re-run this command manually everytime the .envrc changes.quickenv reload# As part of executing the .envrc, a virtualenv has been created at './.venv/'.# There are multiple commands available in '.venv/bin/', such as 'pytest' (a test# runner), or 'sentry' (the main application).# 'quickenv shim' makes those commands available in your shell.quickenv shim# These commands will now run with the virtualenv enabled.sentry devserver --workerspytest tests/sentry/

Advanced usage

# Alternatively you can shim commands explicitly. Be careful: Any command you# missed (such as 'python' or 'pip') would run outside of the virtualenv!quickenv shim sentry pytest# You can also run commands within the current .envrc without shimming them.quickenv exec -- pytest# Your git hooks don't execute in the virtualenv for some reason? Just replace# git with a binary that itself loads the virtualenv.quickenv shim git# Actually activate the virtualenv in your current shell. `quickenv vars`# prints all the extra environment variables with which each shimmed binary runs.set -o allexporteval "$(quickenv vars)"set +o allexport# Or alternatively, substitute your shell with one where your .envrc is loadedexec quickenv exec $SHELL# Or shim 'bash', so that when you open a subshell, the virtualenv is activated.quickenv shim bash# Or shim 'make', so your Makefile runs in the virtualenv.quickenv shim make# Curious which binary is actually being executed?which make# --> /home/user/.quickenv/bin/makequickenv which make# --> /usr/bin/makequickenv exec which make# --> /usr/bin/make# Or for general debugging, increase the log level:QUICKENV_LOG=debug make# [DEBUG quickenv] argv[0] is "make"# [DEBUG quickenv] attempting to launch shim# [DEBUG quickenv] abspath of self is /home/user/.quickenv/bin/make# [DEBUG quickenv] removing own entry from PATH: /home/user/.quickenv/bin# [DEBUG quickenv] execvp /usr/bin/make# ...

License

Licensed underMIT, seeLICENSE.

Dependencies

~8–18MB
~286KSLoC


[8]ページ先頭

©2009-2025 Movatter.jp