⚡️(cd with env) Is a configurable cd wrapper that lets you define your environment per directory.

Overview

⚡️cdwe (cd with env)

A simple configurable cd wrapper that provides powerful utilities for customizing your envionment per directory.
(For ZSH / BASH / FISH Shells)

InstallationUsageConfigurationUninstalling

usage

Features

  • Per Directory Environment Variables
  • Auto Load .env files in Directories
  • Auto Execute Commands in Directories
  • Per Directory Aliases
  • Works with any CD like Command

Installation

  1. Install binary
cargo install cdwe
  1. Init your shell
cdwe init zsh # zsh shells
cdwe init bash # bash shells
cdwe init fish # fish shells
  1. Reload your shell and start using!
# check that env var gets set
cdwe /Users/synoet/dev/projecta
echo $IS_DEBUG

# check that env var gets unset
cdwe ..
echo $IS_DEBUG

Usage

Defining Per Directory Env Variables


You can explicitly define environment variables in two ways:

[[directory]]
path = "/Users/synoet/dev/project"
vars = {"IS_DEBUG" = "true", "IS_PROD" = "false"}

path: the path to your directory you are configuring

vars: a map of env vars to set

By default env vars will also be loaded in subdirectories, in this example /Users/synoet/dev/project/src would also have IS_DEBUG and IS_PROD set

OR

[[env_variable]]
name = "IS_DEBUG"
value = "true"
dirs = [
  "/Users/synoet/dev/project1",
  "/Users/synoet/dev/project2"
]

Here you can define one env var for multiple directories.

name: Is the key of the env variable

value: is the value of the env variable

dirs: Is a list of directories to load this env var for

Loading From .env files


The directory object also takes a load_from field

[[directory]]
path = "/Users/synoet/dev/project"
vars = {"IS_DEBUG" = "true", "IS_PROD" = "false"}
load_from = [".env"]

load_from: List of .env file names to auto load in, these should be relative to the dir defined in path.

In this example we would try to load in a env file at /Users/synoet/dev/project/.env

Unlike per directory env vars, env files are only loaded in the exact matching directory not in subdirectories

OR

Similarly we can define a single env file for multiple directories

[[env_file]]
load_from = ".env"
dirs = [
  "/Users/synoet/dev/macro/macro-site/astro",
  "/Users/synoet/dev/macro/app-monorepo/packages/app"
]

Defining Aliases Per Directory


Here we can define aliases that will be set and unset as functions only in specific directories

[[directory]]
path = "/Users/synoet/dev/project"
vars = {"IS_DEBUG" = "true", "IS_PROD" = "false"}
load_from = [".env"]
aliases = [
    { name = "build", commands = ["yarn cache clean", "yarn build", "yarn package"] }
]

Here we define a build alias which will live only in /User/synoet/dev/project/* and all subdirectories.

aliases: a list of aliases to define for the directory

OR

[[alias]]
name = "build"
commands = ["yarn cache clean", "yarn build", "yarn package"]
dirs = [
    "/Users/synoet/dev/projecta",
    "/Users/synoet/dev/projectb"
]

Here you are defining the same alias for multiple directories.

Defining Auto Commands


Here we can define commands that will automatically run anytime we cd into a specific directory

[[directory]]
path = "/Users/synoet/dev/project"
vars = {"IS_DEBUG" = "true", "IS_PROD" = "false"}
load_from = [".env"]
aliases = [
    { name = "build", commands = ["yarn cache clean", "yarn build", "yarn package"] }
]
run = ["git fetch -p", "ls"]

In this case every time we enter /Users/synoet/dev/project cdwe will automatically run git fetch -p and ls

Auto Commands also require an exact match and don't propogate to subdirectories

OR

[[command]]
run = "git fetch -p"
dirs = [
  "/Users/synoet/dev/cdwe",
  "/Users/synoet/dev/macro/macro-api"
]

Configuration

Global Configuration Options

[config]
# Shell (Created during cdwe init <shell>)
shell = "zsh"
# Custom CD Command (defaults to cd)
cd_command = "z"
# Show alias hints on cd
alias_hints = true
# Show env hints on cd
env_hints = true
# shoe run hints on cd
run_hints = true

Example Configuration

[config]
cd_command = "z"
alias_hints = true
env_hints = true
command_hints = true
run_hints = true
shell = "zsh"

# Defined a directory
# Will have env var "TEST" set in this directory
# Will auto run "git fetch -p" whenever you cd into this dir
# Exposes the following aliases in that directory and sub dirs
[[directory]]
path = "/Users/synoet/dev/cdwe"
vars = { "TEST" = "testing" }
runs = ["git fetch -p"]
aliases = [
  { name = "build", commands = ["cargo build --release"]},
  { name = "run", commands = ["cargo run"]},
  { name = "ci", commands = ["cargo fmt", "cargo test"]}
]

# sets the "ENV_VAR" env var in the following directories
[[env_variable]]
name = "ENV_VAR"
value = "THIS IS A TEST"
dirs = [
  "/Users/synoet/dev/cdwe",
  "/Users/synoet/dev/ballast"
]

# auto loads from .env file in following directories
[[env_file]]
load_from = ".env"
dirs = [
  "/Users/synoet/dev/cdwe",
  "/Users/synoet/dev/project-api"
]

# will auto run the command "git fetch -p" in the following directories
[[command]]
run = "git fetch -p"
dirs = [
  "/Users/synoet/dev/cdwe",
  "/Users/synoet/dev/project-api"
]

Uninstalling

  1. Run cdwe-remove to clean up all shell artifacts
cdwe-remove #removes the `source <output>` from your .zshrc/.bashrc/.fish

zsh #reload your shell, use bash or fish if you use those.
  1. Uninstall binary
cargo uninstall cdwe
You might also like...
Quickly setup your development environment on your Chromebook/ChromeOS  or any Linux distribution 🐧 ❄️ 💻 🚀 ✨
Quickly setup your development environment on your Chromebook/ChromeOS or any Linux distribution 🐧 ❄️ 💻 🚀 ✨

Crosup 🐧 💻 🚀 ✨ Crosup is a CLI tool to help you quickly setup your development environment on a new Chromebook (ChromeOS) or any Linux distribution

Jumpy is a tool that allows to quickly jump to one of the directory you've visited in the past

Jumpy Jumpy is a tool that allows to quickly jump to one of the directory you've visited in the past. It is heavily inspired by Zoxide but is more lig

Command line tool to convert env variables beginning with user to a htpasswd file

envhtp This command line tool converts environment variables whose keys start with "user_" into htpasswd compatible username/password pairs. The goal

Download pdbs from symbol servers and cache locally, parse symbol paths from env vars

symsrv This crate lets you download and cache pdb files from symbol servers, according to the rules from the _NT_SYMBOL_PATH environment variable. It

Env.exe for Windows

env.exe for Windows $ env {options} {NAME=VALUE}... COMMAND ARGS... -v, --debug print verbose information --version output version information -h, -

Convert your .NET dependencies to the Directory.Packages.props format

directory-packages-props-converter Converts your projects to use Central Package Management. PackageReference dependencies have their Version remove

Rbenv - Manage your app's Ruby environment

Seamlessly manage your app’s Ruby environment with rbenv. Use rbenv to pick a Ruby version for your application and guarantee that your development en

Run the right version of python, in the right environment, for your project

rpy Do you deal with lots of virtual python environments? rpy is for you! Before rpy: ~/dev/prj$ env PYTHONPATH=src/py path/to/my/interpreter src/py/m

Configurable, extensible, interactive line reader

linefeed linefeed is a configurable, concurrent, extensible, interactive input reader for Unix terminals and Windows console. API Documentation linefe

Releases(0.2.4)
  • 0.2.4(Aug 7, 2023)

    • Add ability to set aliases
    • Add ability to auto run commands
    • Add inverse configurability (dirs for vars... commands for vars etc..)
    • Add some basic tests
    Source code(tar.gz)
    Source code(zip)
Owner
teo
Software Engineer @ Macro
teo
Manage your dotfiles and packages with ease. Define your $HOME as Code 💻 🚀 ✨

EnvHub is a simple tool to manage dotfiles and packages accross multiple machines. Written in Rust, internally it uses nix/homebrew/pkgx/devbox to man

Tsiry Sandratraina 8 Oct 27, 2023
A Yocto setup and management tool that helps you keep your environment up-to-date and in-sync with your team

yb (Yocto Buddy) yb is designed to make it easy to setup and (perhaps more importantly) keep Yocto environments up-to-date and in-sync with your team.

null 13 Oct 31, 2022
koyo is a cli tool that lets you run commands as another user. It is similar to doas or sudo.

koyo is a cli tool that lets you run commands as another user. It is similar to doas or sudo.

null 3 Nov 27, 2021
A bit like tee, a bit like script, but all with a fake tty. Lets you remote control and watch a process

teetty teetty is a wrapper binary to execute a command in a pty while providing remote control facilities. This allows logging the stdout of a process

Armin Ronacher 259 Jan 3, 2023
ISG lets you use YouTube as cloud storage for ANY files, not just video

I was working on this instead of my finals, hope you appreciate it. I'll add all relevant executables when I can Infinite-Storage-Glitch AKA ISG (writ

HistidineDwarf 3.6k Feb 23, 2023
Terminal UI for leetcode. Lets you browse questions through different topics. View, solve, run and submit questions from TUI.

Leetcode TUI Use Leetcode in your terminal. Why this TUI: My motivation for creating leetcode-tui stemmed from my preference for tools that are lightw

Akarsh 8 Aug 10, 2023
An anyrun plugin that lets you search NixOS options.

anyrun-nixos-options An anyrun plugin that lets you search NixOS options. how 2 build? nix build ... or cargo build optionally :) Configuration This p

Michał 4 Aug 24, 2023
Lets you tweak Assassin's Creed Mirage in various ways.

Mirage Tweaks Lets you tweak Assassin's Creed Mirage in various ways. Currently supports adjusting the eject height and sprint speed. Usage Get the la

Assassin's Creed Community 3 Nov 3, 2023
Simple OpenAI CLI wrapper written in Rust, feat. configurable prompts and models

Quick Start git clone https://github.com/ryantinder/ask-rs cd ask cargo install --path . Example ask tell me about the Lockheed Martin SR71 >> The Loc

Ryan Tinder 3 Aug 9, 2023
By mirroring traffic to and from your machine, mirrord surrounds your local service with a mirror image of its cloud environment.

mirrord lets you easily mirror traffic from your Kubernetes cluster to your development environment. It comes as both Visual Studio Code extension and

MetalBear 2.1k Jan 3, 2023