Skip to content

Instantly share code, notes, and snippets.

@o6uoq
Last active August 22, 2025 12:14
Show Gist options
  • Save o6uoq/097ae67603bf944bb10addec5741b122 to your computer and use it in GitHub Desktop.
Save o6uoq/097ae67603bf944bb10addec5741b122 to your computer and use it in GitHub Desktop.
vaultfuz: Vault Namespaces, but Fuzzy.
#!/bin/bash
# vaultfuz: Vault Namespaces, but Fuzzy.
# ██╗ ██╗ █████╗ ██╗ ██╗██╗ ████████╗███████╗██╗ ██╗███████╗
# ██║ ██║██╔══██╗██║ ██║██║ ╚══██╔══╝██╔════╝██║ ██║╚══███╔╝
# ██║ ██║███████║██║ ██║██║ ██║ █████╗ ██║ ██║ ███╔╝
# ╚██╗ ██╔╝██╔══██║██║ ██║██║ ██║ ██╔══╝ ██║ ██║ ███╔╝
# ╚████╔╝ ██║ ██║╚██████╔╝███████╗██║ ██║ ╚██████╔╝███████╗
# ╚═══╝ ╚═╝ ╚═╝ ╚═════╝ ╚══════╝╚═╝ ╚═╝ ╚═════╝ ╚══════╝
# === How-To ===
# - Ensure brew, fzf, and vault are installed
# - Set VAULT_NAMESPACES env var as a comma-separated list of your Vault namespaces
# - Run this script and fuzzy select a Vault namespace from $VAULT_NAMESPACEs to export to $VAULT_NAMESPACE
set -euo pipefail
# === Check that required binaries are installed via brew ===
require_brew_bin() {
local bin="$1"
if ! command -v "$bin" >/dev/null 2>&1; then
echo "$bin not found. Install via: brew install $bin"
exit 1
fi
}
require_brew_bin fzf
require_brew_bin vault
# === Ensure VAULT_NAMESPACES env var is set and not empty ===
if [[ -z "${VAULT_NAMESPACES:-}" ]]; then
echo "❌ VAULT_NAMESPACES env var not set."
exit 1
fi
# === Split VAULT_NAMESPACES into an array by comma ===
IFS=',' read -r -a namespaces <<<"$VAULT_NAMESPACES"
if [[ "${#namespaces[@]}" -eq 0 ]]; then
echo "❌ No namespaces found in VAULT_NAMESPACES."
exit 1
fi
# === Use fzf for interactive selection ===
selected=$(printf '%s\n' "${namespaces[@]}" | fzf --prompt="Select Vault Namespace: ")
if [[ -z "$selected" ]]; then
echo "❌ No namespace selected."
exit 1
fi
export VAULT_NAMESPACE="$selected"
echo "✅ VAULT_NAMESPACE set to '$VAULT_NAMESPACE'"
# === Suggest how to persist the change ===
echo "ℹ️ To persist, add this to your shell: export VAULT_NAMESPACE='$VAULT_NAMESPACE'"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment