From 251787059e7548ba8b008fa450f66ee186235bca Mon Sep 17 00:00:00 2001 From: Benjamin Date: Sun, 29 Jan 2023 18:07:57 +0000 Subject: [PATCH] Add the autoenv plugin --- plugins/autoenv/README.md | 170 ++++++++++++++++++ plugins/autoenv/index.ts | 61 +++++++ plugins/zsh-history-substring-search/index.ts | 2 +- 3 files changed, 232 insertions(+), 1 deletion(-) create mode 100644 plugins/autoenv/README.md create mode 100644 plugins/autoenv/index.ts diff --git a/plugins/autoenv/README.md b/plugins/autoenv/README.md new file mode 100644 index 00000000..5f45f1ac --- /dev/null +++ b/plugins/autoenv/README.md @@ -0,0 +1,170 @@ +## What is it? + +If a directory contains a `.env` file, it will automatically be executed when you `cd` into it. When enabled (set `AUTOENV_ENABLE_LEAVE` to a non-empty string), if a directory contains a `.env.leave` file, it will automatically be executed when you leave it. + +This is great for... + +- auto-activating virtualenvs +- auto-deactivating virtualenvs +- project-specific environment variables +- making millions + +You can also nest envs within each other. How awesome is that!? + +When executing, autoenv, will walk up the directories until the mount +point and execute all `.env` files beginning at the top. + +## Usage + +Follow the white rabbit: + +```sh +$ echo "echo 'whoa'" > ./project/.env +$ cd ./project +whoa +``` + +![Mind blown GIF](http://media.tumblr.com/tumblr_ltuzjvbQ6L1qzgpx9.gif) + +## Installation (automated) + +```sh +# with cURL +curl -#fLo- 'https://raw.githubusercontent.com/hyperupcall/autoenv/master/scripts/install.sh' | sh + +# with wget +wget --show-progress -o /dev/null -O- 'https://raw.githubusercontent.com/hyperupcall/autoenv/master/scripts/install.sh' | sh +``` + +If you encounter some variant of a `curl: command not found` or `wget: command not found` error, please install either cURL or wget (with your package manager) and try again. + +## Installation (manual) + +When installing manually, you first install autoenv with either Homebrew, npm, or Git. Then, you run a command to ensure autoenv is loaded when you open a terminal (this command depends on your [default shell](https://askubuntu.com/a/590901)). + +### Installation Method + +Note that depending on your shell and operating system, you may need to write to `.zprofile` instead of `.zshrc`, or write to `.bash_profile` instead of `.bashrc` (or visa-versa). + +#### Using Homebrew + +Prefer this if you're running macOS. Homebrew [must be installed](https://brew.sh). + +
+Click to expand content + +First, download the [autoenv](https://formulae.brew.sh/formula/autoenv) homebrew formulae: + +```sh +$ brew install 'autoenv' +``` + +Then, execute run of the following to ensure autoenv is loaded when you open a terminal: + +```sh +# For Zsh shell (on Linux or macOS) +$ printf '%s\n' "source $(brew --prefix autoenv)/activate.sh" >> "${ZDOTDIR:-$HOME}/.zprofile" + +# For Bash shell (on Linux) +$ printf '%s\n' "source $(brew --prefix autoenv)/activate.sh" >> ~/.bashrc + +# For Bash shell (on macOS) +$ printf '%s\n' "source $(brew --prefix autoenv)/activate.sh" >> ~/.bash_profile +``` + +
+ +#### Using npm + +Prefer this if you're running Linux or an unsupported version of macOS. npm [must be installed](https://nodejs.org/en/download) (usually through NodeJS). + +
+Click to expand content + +First, download the [@hyperupcall/autoenv](https://www.npmjs.com/package/@hyperupcall/autoenv) npm package: + +```sh +$ npm install -g '@hyperupcall/autoenv' +``` + +Then, execute run of the following to ensure autoenv is loaded when you open a terminal: + +```sh +# For Zsh shell (on Linux or macOS) +$ printf '%s\n' "source $(npm root -g)/activate.sh" >> "${ZDOTDIR:-$HOME}/.zprofile" + +# For Bash shell (on Linux) +$ printf '%s\n' "source $(npm root -g)/activate.sh" >> ~/.bashrc + +# For Bash shell (on macOS) +$ printf '%s\n' "source $(npm root -g)/activate.sh" >> ~/.bash_profile +``` + +
+ +#### Using Git + +Use this if you cannot install with Homebrew or npm. + +
+Click to expand content + +First, clone this repository: + +```sh +$ git clone 'https://github.com/hyperupcall/autoenv' ~/.autoenv +``` + +Then, execute run of the following to ensure autoenv is loaded when you open a terminal: + +```sh +# For Zsh shell (on Linux or macOS) +$ printf '%s\n' "source ~/.autoenv/activate.sh" >> "${ZDOTDIR:-$HOME}/.zprofile" + +# For Bash shell (on Linux) +$ printf '%s\n' "source ~/.autoenv/activate.sh" >> ~/.bashrc + +# For Bash shell (on macOS) +$ printf '%s\n' "source ~/.autoenv/activate.sh" >> ~/.bash_profile +``` + +
+ +## Configuration + +_Before_ `source`ing `activate.sh`, you can set the following variables: + +- `AUTOENV_AUTH_FILE`: Authorized env files; defaults to `~/.autoenv_authorized` if it exists, otherwise, `~/.local/state/autoenv/authorized_list` +- `AUTOENV_ENV_FILENAME`: Name of the `.env` file; defaults to `.env` +- `AUTOENV_LOWER_FIRST`: Set this variable to a non-empty string to flip the order of `.env` files executed +- `AUTOENV_ENV_LEAVE_FILENAME`: Name of the `.env.leave` file; defaults to `.env.leave` +- `AUTOENV_ENABLE_LEAVE`: Set this to a non-empty string in order to enable source env when leaving +- `AUTOENV_ASSUME_YES`: Set this variable to a non-empty string to silently authorize the initialization of new environments +- `AUTOENV_VIEWER`: Program used to display env files prior to authorization; defaults to `cat` (`master` branch only) +- `AUTOENV_PRESERVE_CD`: Set this variable to a non-empty string to prevent the `cd` builtin from being overridden (to active autoenv, you must invoke `autoenv_init` within a `cd` function of your own) (`master` branch only) + +## Shells + +autoenv is tested on: + +- Bash +- Zsh +- Dash +- Fish is supported by [autoenv_fish](https://github.com/loopbit/autoenv_fish) +- More to come + +## Disclaimer + +Autoenv overrides `cd` (unless `AUTOENV_PRESERVE_CD` is set to a non-empty string). If you already do this, invoke `autoenv_init` within your custom `cd` after sourcing `activate.sh`. + +Autoenv can be disabled via `unset -f cd` if you experience I/O issues with certain file systems, particularly those that are FUSE-based (such as `smbnetfs`). + +## Other info + +To uninstall autoenv, see [`./docs/uninstall.md`](./docs/uninstall.md). + +To update autoenv, see [`./docs/updating.md`](./docs/updating.md). + +## Attributions + +Autoenv was originally created by [@kennethreitz](https://github.com/kennethreitz). Later, ownership was transfered to [@inishchith](https://github.com/inishchith). As of August 22nd, 2021, Edwin Kofler ([@hyperupcall](https://github.com/hyperupcall)) owns and maintains the project. diff --git a/plugins/autoenv/index.ts b/plugins/autoenv/index.ts new file mode 100644 index 00000000..7ffbfeb3 --- /dev/null +++ b/plugins/autoenv/index.ts @@ -0,0 +1,61 @@ +const plugin: Fig.Plugin = { + name: "autoenv", + displayName: "Autoenv", + description: ".env Directory-based shell environments", + icon: "🏕️", + type: "shell", + authors: [ + { + name: "hyperupcall", + github: "hyperupcall", + }, + ], + github: "hyperupcall/autoenv", + license: ["MIT"], + shells: ["zsh", "bash", "fish"], + categories: ["Other"], + keywords: [ + "dotenv", + "env", + ".env", + "environment", + "variables", + "config", + "settings", + ], + installation: { + origin: "github", + sourceFiles: ["activate.sh"], + }, + configuration: [ + { + displayName: "Always load .env", + name: "AUTOENV_ASSUME_YES", + description: + "Default to always loading the .env file. And not prompting the user.", + type: "environmentVariable", + interface: "toggle", + default: false, + }, + { + displayName: "Filename", + name: "AUTOENV_ENV_FILENAME", + description: + "Specify a filename to search the current path to the environment environment variables from.", + type: "environmentVariable", + interface: "text", + default: ".env", + }, + { + displayName: "Authorized .env paths", + name: "AUTOENV_AUTH_FILE", + description: + "Specify a path to a file containing a whitelist of authorized env files. Autoenv will automatically load env files from paths listed in this file.", + type: "environmentVariable", + interface: "text", + default: "~/.autoenv_authorized", + }, + ], +}; + +export default plugin; diff --git a/plugins/zsh-history-substring-search/index.ts b/plugins/zsh-history-substring-search/index.ts index 97e6cec6..62c6b55f 100644 --- a/plugins/zsh-history-substring-search/index.ts +++ b/plugins/zsh-history-substring-search/index.ts @@ -23,7 +23,7 @@ const plugin: Fig.Plugin = { name: "bind-keys", displayName: "Bind Keys", type: "script", - interface: "text", + interface: "textarea", default: `bindkey '...' history-substring-search-up\n` + `bindkey '...' history-substring-search-down`,