Skip to content

Instantly share code, notes, and snippets.

@soderlind
Last active November 10, 2025 21:48
Show Gist options
  • Select an option

  • Save soderlind/a470af7652a61ee07e302ea815d786df to your computer and use it in GitHub Desktop.

Select an option

Save soderlind/a470af7652a61ee07e302ea815d786df to your computer and use it in GitHub Desktop.

Revisions

  1. soderlind revised this gist Sep 14, 2025. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion local-direnv-vscode-setup.md
    Original file line number Diff line number Diff line change
    @@ -23,7 +23,7 @@ This guide wires up **Local** (localwp.com) with **direnv** so your terminal & V
    When vibe coding in VS Code or similar, AI tends to want to do `wp` cli commands, direnv and a correct .envrc will make this possible.
    <figure>
    <img width="1116" height="914" alt="image" src="https://gist.github.com/user-attachments/assets/991126ce-25d6-49f3-b7a4-4d5e2083e942" />
    <figcaption>Debugging <a href="https://github.com/soderlind/read-offline?tab=readme-ov-file#-read-offline---transform-your-wordpress-content">Read Offline</a></figcaption>
    <figcaption>Screenshot from debugging <a href="https://github.com/soderlind/read-offline?tab=readme-ov-file#-read-offline---transform-your-wordpress-content">Read Offline</a></figcaption>
    </figure>

    ---
  2. soderlind revised this gist Sep 14, 2025. No changes.
  3. soderlind revised this gist Sep 7, 2025. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions local-direnv-vscode-setup.md
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,5 @@
    > To make this the default in Local, [please vote](https://community.localwp.com/t/add-envrc-to-the-site-app-folder/51197)
    # Local (localwp.com) + direnv + VS Code

    This guide wires up **Local** (localwp.com) with **direnv** so your terminal & VS Code always use the correct WordPress environment for each Local site. It includes:
  4. soderlind revised this gist Sep 7, 2025. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion local-direnv-vscode-setup.md
    Original file line number Diff line number Diff line change
    @@ -3,7 +3,7 @@
    This guide wires up **Local** (localwp.com) with **direnv** so your terminal & VS Code always use the correct WordPress environment for each Local site. It includes:
    - Installing the Local direnv add‑on from the **1.0.0 release tarball**.
    - Shell hook instructions for **macOS, Windows, and Linux**.
    - Configure VS Code to inherit environment variables from the current LocalWP shell session
    - Configure VS Code to inherit environment variables from the current Local shell session

    ## Contents
    - [Why do you need this?](#why-do-you-need-this)
  5. soderlind revised this gist Sep 7, 2025. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion local-direnv-vscode-setup.md
    Original file line number Diff line number Diff line change
    @@ -3,7 +3,7 @@
    This guide wires up **Local** (localwp.com) with **direnv** so your terminal & VS Code always use the correct WordPress environment for each Local site. It includes:
    - Installing the Local direnv add‑on from the **1.0.0 release tarball**.
    - Shell hook instructions for **macOS, Windows, and Linux**.
    - Configure VS Code to inherit environment variables from the current shell session
    - Configure VS Code to inherit environment variables from the current LocalWP shell session

    ## Contents
    - [Why do you need this?](#why-do-you-need-this)
  6. soderlind revised this gist Sep 7, 2025. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions local-direnv-vscode-setup.md
    Original file line number Diff line number Diff line change
    @@ -3,6 +3,7 @@
    This guide wires up **Local** (localwp.com) with **direnv** so your terminal & VS Code always use the correct WordPress environment for each Local site. It includes:
    - Installing the Local direnv add‑on from the **1.0.0 release tarball**.
    - Shell hook instructions for **macOS, Windows, and Linux**.
    - Configure VS Code to inherit environment variables from the current shell session

    ## Contents
    - [Why do you need this?](#why-do-you-need-this)
  7. soderlind revised this gist Sep 7, 2025. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion local-direnv-vscode-setup.md
    Original file line number Diff line number Diff line change
    @@ -182,7 +182,7 @@ If the URL matches your Local site, everything is wired up.
    cd "/path/to/Local Sites/<site>/app"
    code .
    ```
    **${\color{red}VS\ Code\ will\ inherit\ the\ environment\ from\ the\ current\ shell.}$** :tada:
    ${\bf\large\color{red}VS\ Code\ will\ inherit\ the\ environment\ from\ the\ current\ shell.}$ :tada:

    **Windows tip:** In VS Code, set your default Integrated Terminal shell to **Git Bash** for the best direnv experience on Windows.

  8. soderlind revised this gist Sep 7, 2025. 1 changed file with 3 additions and 2 deletions.
    5 changes: 3 additions & 2 deletions local-direnv-vscode-setup.md
    Original file line number Diff line number Diff line change
    @@ -18,9 +18,10 @@ This guide wires up **Local** (localwp.com) with **direnv** so your terminal & V
    ## Why do you need this?

    When vibe coding in VS Code or similar, AI tends to want to do `wp` cli commands, direnv and a correct .envrc will make this possible.

    <figure>
    <img width="1116" height="914" alt="image" src="https://gist.github.com/user-attachments/assets/991126ce-25d6-49f3-b7a4-4d5e2083e942" />

    <figcaption>Debugging <a href="https://github.com/soderlind/read-offline?tab=readme-ov-file#-read-offline---transform-your-wordpress-content">Read Offline</a></figcaption>
    </figure>

    ---

  9. soderlind revised this gist Sep 5, 2025. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion local-direnv-vscode-setup.md
    Original file line number Diff line number Diff line change
    @@ -7,7 +7,7 @@ This guide wires up **Local** (localwp.com) with **direnv** so your terminal & V
    ## Contents
    - [Why do you need this?](#why-do-you-need-this)
    - [Prereqs](#1-prereqs)
    - [Install the Local direnv add‑on from the release tarball](#2-install-the-local-direnv-add-on-from-the-release-tarball)
    - [Install the Local direnv add‑on from the release tarball](#2-install-the-local-direnv-addon-from-the-release-tarball)
    - [Hook direnv into your shell (per OS) — if not already done](#3-hook-direnv-into-your-shell-per-os--if-not-already-done)
    - [Start your Local site and allow the `.envrc`](#4-start-your-local-site-and-allow-the-envrc)
    - [Make VS Code pick up the same environment](#5-make-vs-code-pick-up-the-same-environment)
  10. soderlind revised this gist Sep 5, 2025. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion local-direnv-vscode-setup.md
    Original file line number Diff line number Diff line change
    @@ -12,7 +12,7 @@ This guide wires up **Local** (localwp.com) with **direnv** so your terminal & V
    - [Start your Local site and allow the `.envrc`](#4-start-your-local-site-and-allow-the-envrc)
    - [Make VS Code pick up the same environment](#5-make-vs-code-pick-up-the-same-environment)
    - [Day‑to‑day usage](#6-daytoday-usage)
    - [Optional: extend per plugin/theme (keep the add‑on as source of truth)](7-optional-extend-per-plugintheme-keep-the-addon-as-source-of-truth)
    - [Optional: extend per plugin/theme (keep the add‑on as source of truth)](#7-optional-extend-per-plugintheme-keep-the-addon-as-source-of-truth)
    - [Troubleshooting tips](#8-troubleshooting-tips)

    ## Why do you need this?
  11. soderlind revised this gist Sep 5, 2025. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion local-direnv-vscode-setup.md
    Original file line number Diff line number Diff line change
    @@ -12,7 +12,7 @@ This guide wires up **Local** (localwp.com) with **direnv** so your terminal & V
    - [Start your Local site and allow the `.envrc`](#4-start-your-local-site-and-allow-the-envrc)
    - [Make VS Code pick up the same environment](#5-make-vs-code-pick-up-the-same-environment)
    - [Day‑to‑day usage](#6-daytoday-usage)
    - [Optional: extend per plugin/theme (keep the add‑on as source of truth)](#7-optional-extend-per-plugin-theme-keep-the-add-on-as-source-of-truth)
    - [Optional: extend per plugin/theme (keep the add‑on as source of truth)](7-optional-extend-per-plugintheme-keep-the-addon-as-source-of-truth)
    - [Troubleshooting tips](#8-troubleshooting-tips)

    ## Why do you need this?
  12. soderlind revised this gist Sep 5, 2025. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion local-direnv-vscode-setup.md
    Original file line number Diff line number Diff line change
    @@ -11,7 +11,7 @@ This guide wires up **Local** (localwp.com) with **direnv** so your terminal & V
    - [Hook direnv into your shell (per OS) — if not already done](#3-hook-direnv-into-your-shell-per-os--if-not-already-done)
    - [Start your Local site and allow the `.envrc`](#4-start-your-local-site-and-allow-the-envrc)
    - [Make VS Code pick up the same environment](#5-make-vs-code-pick-up-the-same-environment)
    - [Day‑to‑day usage](#6-day-to-day-usage)
    - [Day‑to‑day usage](#6-daytoday-usage)
    - [Optional: extend per plugin/theme (keep the add‑on as source of truth)](#7-optional-extend-per-plugin-theme-keep-the-add-on-as-source-of-truth)
    - [Troubleshooting tips](#8-troubleshooting-tips)

  13. soderlind revised this gist Sep 5, 2025. 1 changed file with 10 additions and 0 deletions.
    10 changes: 10 additions & 0 deletions local-direnv-vscode-setup.md
    Original file line number Diff line number Diff line change
    @@ -4,6 +4,16 @@ This guide wires up **Local** (localwp.com) with **direnv** so your terminal & V
    - Installing the Local direnv add‑on from the **1.0.0 release tarball**.
    - Shell hook instructions for **macOS, Windows, and Linux**.

    ## Contents
    - [Why do you need this?](#why-do-you-need-this)
    - [Prereqs](#1-prereqs)
    - [Install the Local direnv add‑on from the release tarball](#2-install-the-local-direnv-add-on-from-the-release-tarball)
    - [Hook direnv into your shell (per OS) — if not already done](#3-hook-direnv-into-your-shell-per-os--if-not-already-done)
    - [Start your Local site and allow the `.envrc`](#4-start-your-local-site-and-allow-the-envrc)
    - [Make VS Code pick up the same environment](#5-make-vs-code-pick-up-the-same-environment)
    - [Day‑to‑day usage](#6-day-to-day-usage)
    - [Optional: extend per plugin/theme (keep the add‑on as source of truth)](#7-optional-extend-per-plugin-theme-keep-the-add-on-as-source-of-truth)
    - [Troubleshooting tips](#8-troubleshooting-tips)

    ## Why do you need this?

  14. soderlind revised this gist Sep 5, 2025. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion local-direnv-vscode-setup.md
    Original file line number Diff line number Diff line change
    @@ -171,7 +171,7 @@ If the URL matches your Local site, everything is wired up.
    cd "/path/to/Local Sites/<site>/app"
    code .
    ```
    VS Code will inherit the environment from the current shell.
    **${\color{red}VS\ Code\ will\ inherit\ the\ environment\ from\ the\ current\ shell.}$** :tada:

    **Windows tip:** In VS Code, set your default Integrated Terminal shell to **Git Bash** for the best direnv experience on Windows.

  15. soderlind revised this gist Aug 21, 2025. 1 changed file with 8 additions and 0 deletions.
    8 changes: 8 additions & 0 deletions local-direnv-vscode-setup.md
    Original file line number Diff line number Diff line change
    @@ -4,6 +4,14 @@ This guide wires up **Local** (localwp.com) with **direnv** so your terminal & V
    - Installing the Local direnv add‑on from the **1.0.0 release tarball**.
    - Shell hook instructions for **macOS, Windows, and Linux**.


    ## Why do you need this?

    When vibe coding in VS Code or similar, AI tends to want to do `wp` cli commands, direnv and a correct .envrc will make this possible.

    <img width="1116" height="914" alt="image" src="https://gist.github.com/user-attachments/assets/991126ce-25d6-49f3-b7a4-4d5e2083e942" />


    ---

    ## 1) Prereqs
  16. soderlind created this gist Aug 14, 2025.
    209 changes: 209 additions & 0 deletions local-direnv-vscode-setup.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,209 @@
    # Local (localwp.com) + direnv + VS Code

    This guide wires up **Local** (localwp.com) with **direnv** so your terminal & VS Code always use the correct WordPress environment for each Local site. It includes:
    - Installing the Local direnv add‑on from the **1.0.0 release tarball**.
    - Shell hook instructions for **macOS, Windows, and Linux**.

    ---

    ## 1) Prereqs

    - **Local** v5+ installed.
    - **direnv** installed:
    - **macOS (Homebrew)**: `brew install direnv`
    - **Linux**: use your distro package manager (e.g., `sudo apt install direnv`, `sudo dnf install direnv`, or `sudo pacman -S direnv`)
    - **Windows (recommended: Git Bash or PowerShell)**:
    - **Scoop**: `scoop install direnv`
    - **Chocolatey**: `choco install direnv`

    > After installing, you must **hook** direnv into your shell (next sections).
    ---

    ## 2) Install the **Local direnv** add‑on from the release tarball

    You should **download** the packaged add‑on and place it in Local’s add‑ons folder. When extracted, the archive creates a **`packages`** folder — **rename it to `local-addon-direnv`**.

    ### 2.1. Find your Local add‑ons folder
    - **macOS:** `~/Library/Application Support/Local/addons`
    - **Windows:** `%APPDATA%\Local\addons` (typically `C:\Users\<you>\AppData\Roaming\Local\addons`)
    - **Linux:** `~/.config/Local/addons`

    If the `addons` folder does not exist yet, create it.

    ### 2.2. Download the release tarball
    **URL:** `https://github.com/gravitywiz/local-addon-direnv/releases/download/1.0.0/direnv-1.0.0.tgz`

    - **macOS / Linux (terminal):**
    ```sh
    # Choose a download location, e.g. ~/Downloads
    cd ~/Downloads
    curl -LO https://github.com/gravitywiz/local-addon-direnv/releases/download/1.0.0/direnv-1.0.0.tgz
    ```

    - **Windows:**
    - Easiest: download with your browser to `Downloads`.
    - Or PowerShell:
    ```powershell
    cd $env:USERPROFILE\Downloads
    Invoke-WebRequest -Uri https://github.com/gravitywiz/local-addon-direnv/releases/download/1.0.0/direnv-1.0.0.tgz -OutFile direnv-1.0.0.tgz
    ```
    ### 2.3. Extract and **rename** to `local-addon-direnv`
    > The archive extracts to a folder named **`packages`**. You **must** rename it to **`local-addon-direnv`** before installing/enabling in Local.
    - **macOS (Terminal):**
    ```sh
    cd ~/Downloads
    tar -xzf direnv-1.0.0.tgz
    # A folder named "packages" appears; move it into Local's add-ons and rename:
    mv packages ~/Library/Application\ Support/Local/addons/local-addon-direnv
    ```

    - **Linux (Terminal):**
    ```sh
    cd ~/Downloads
    tar -xzf direnv-1.0.0.tgz
    mv packages ~/.config/Local/addons/local-addon-direnv
    ```

    - **Windows (PowerShell):**
    ```powershell
    cd $env:USERPROFILE\Downloads
    # If 'tar' is available (Win10/11 usually has bsdtar):
    tar -xzf direnv-1.0.0.tgz
    # Move & rename into Local's add-ons folder:
    Move-Item -Force .\packages "$env:APPDATA\Local\addons\local-addon-direnv"
    ```
    If `tar` is unavailable, extract with **7‑Zip** (GUI) or File Explorer (using a helper like 7‑Zip). After extracting, manually move the resulting `packages` folder into `%APPDATA%\Local\addons\` and rename it to **`local-addon-direnv`**.

    ### 2.4. Enable the add‑on in Local
    Open **Local → Add‑ons → Install from disk**, select the `local-addon-direnv` folder you just placed, and **Enable** it.

    **What it does:** On site **create/start**, the add‑on generates a site‑specific `.envrc` in `<site>/app/` that sets environment variables so WP‑CLI and other tools automatically target that Local site (even outside “Open Site Shell”).

    ---

    ## 3) Hook direnv into your shell (per OS) — if not already done

    Pick your shell and add the corresponding hook line to your shell config. Then **restart** the shell.

    ### macOS
    - **zsh (default on macOS):** add to `~/.zshrc`
    ```sh
    eval "$(direnv hook zsh)"
    ```
    - **bash:** add to `~/.bashrc`
    ```sh
    eval "$(direnv hook bash)"
    ```
    - **fish:** add to `~/.config/fish/config.fish`
    ```fish
    direnv hook fish | source
    ```

    ### Linux
    - **bash:** add to `~/.bashrc`
    ```sh
    eval "$(direnv hook bash)"
    ```
    - **zsh:** add to `~/.zshrc`
    ```sh
    eval "$(direnv hook zsh)"
    ```
    - **fish:** add to `~/.config/fish/config.fish`
    ```fish
    direnv hook fish | source
    ```

    ### Windows
    You have a few good options. Choose one:

    - **Git Bash (recommended on Windows):** edit `~/.bashrc`
    ```sh
    eval "$(direnv hook bash)"
    ```

    - **PowerShell (advanced/experimental):** add a hook to your PowerShell profile so it loads for every session. In **PowerShell**, run:
    ```powershell
    if (!(Test-Path -LiteralPath $PROFILE)) { New-Item -ItemType File -Path $PROFILE -Force | Out-Null }
    Add-Content -Path $PROFILE -Value 'Invoke-Expression (direnv hook powershell)'
    # Then restart PowerShell
    ```
    > Notes:
    > - direnv evaluates `.envrc` with a bash sub-shell. Ensure **Git Bash** or **WSL** is installed and available if your `.envrc` uses bash syntax (most do).
    > - If you hit issues with PowerShell hooks, use **Git Bash** as your VS Code terminal for best compatibility.
    ---

    ## 4) Start your Local site and allow the `.envrc`

    ```sh
    cd "/path/to/Local Sites/<site>/app"
    direnv status # expect: ".envrc is blocked"
    direnv allow
    wp option get home # should print your Local site URL
    ```

    If the URL matches your Local site, everything is wired up.

    ---

    ## 5) Make VS Code pick up the same environment

    **Option A — VS Code “direnv” extension**
    - Install the [direnv extension](https://marketplace.visualstudio.com/items?itemName=mkhl.direnv).
    - Open `<site>/app` in VS Code; when prompted, **Allow** the `.envrc`.
    - Optional, in direnv settings: `"direnv.restart.automatic": true` // Automatically restart the direnv process when changes are detected
    - The **Integrated Terminal** (and shell-type tasks) inherit the environment.

    **Option B — Launch VS Code from a direnv-enabled shell**
    ```sh
    cd "/path/to/Local Sites/<site>/app"
    code .
    ```
    VS Code will inherit the environment from the current shell.

    **Windows tip:** In VS Code, set your default Integrated Terminal shell to **Git Bash** for the best direnv experience on Windows.

    ---

    ## 6) Day‑to‑day usage

    From anywhere under `<site>/app` (theme, plugin, etc.):
    ```sh
    wp option get siteurl
    wp plugin list
    ```
    No need to use “Open Site Shell”—the environment is already wired up by direnv.

    ---

    ## 7) Optional: extend per plugin/theme (keep the add‑on as source of truth)

    If you work inside a plugin/theme folder, **layer** a local `.envrc` that sources the site‑level one:

    ```sh
    # <site>/app/public/wp-content/plugins/my-plugin/.envrc
    source_up # pull in the site-level .envrc from app/
    export WP_ENV=local
    ```

    Then:
    ```sh
    direnv allow
    ```

    ---

    ## 8) Troubleshooting tips

    - Edited a `.envrc`? Run `direnv allow` again (or VS Code: “Direnv: Allow/Reload environment”).
    - VS Code not picking it up? Ensure you installed the “direnv” extension and clicked **Allow** for the workspace’s `.envrc`; or reopen VS Code from `<site>/app` after `direnv allow`.
    - On Windows PowerShell, if variables don’t load, switch the VS Code terminal to **Git Bash** or use **WSL** for full compatibility.
    - Need to re-run the zsh fix? Return to Step 1.

    ---

    **That’s it!** Your shell and VS Code should now “just know” which Local WordPress site you’re in, so `wp`, PHP tools, and scripts behave correctly per-site.