diff --git a/docs/reference/shell.md b/docs/reference/shell.md index 0a5b8bd..2b7ad84 100644 --- a/docs/reference/shell.md +++ b/docs/reference/shell.md @@ -13,8 +13,9 @@ The shell environment is modularized: - `jump.sh`: Directory navigation and quick jumping. - `pdf.sh`: PDF compilation, viewing, and OCR helpers. - `quicklinks.sh`: Shortcuts to primary project directories. + - `secrets.sh`: SOPS secret retrieval and Wayland clipboard extraction (`gh-token`). - `todo.sh`: Lightweight terminal task tracking. - - `wayland.sh`: Wayland session environment variables. + - `wayland.sh`: Wayland session environment variables and clipboard helpers. --- @@ -36,6 +37,7 @@ The shell environment is modularized: | `gs` | `git status` | Quick working tree status. | | `gd` | `git diff` | Syntax-highlighted git diff via Delta. | | `gl` | `git log --oneline --graph --decorate` | Compact visual commit graph. | +| `ght` | `gh-token` | Copy GitHub repo token from SOPS into Wayland clipboard. | ### Directory Navigation Jumps (`home/shell/jump.sh`) | 2-Letter | Word Alias | Target Directory | Description | diff --git a/home/shell.nix b/home/shell.nix index b31a6ef..f9c0ddf 100644 --- a/home/shell.nix +++ b/home/shell.nix @@ -244,6 +244,7 @@ in gfo = "git fetch origin"; gcheck = "git checkout"; gadc = "git add -A && git diff --staged | wl-copy"; + ght = "gh-token"; }; # Inject modular shell helper scripts directly into .bashrc @@ -256,6 +257,7 @@ in ${builtins.readFile ./shell/wayland.sh} # Wayland clipboard helper (wlc) ${builtins.readFile ./shell/git.sh} # Git workflow automations (gacp, gitignore) ${builtins.readFile ./shell/pdf.sh} # Command line PDF decryption helper + ${builtins.readFile ./shell/secrets.sh} # SOPS secret extraction helper (gh-token) ${builtins.readFile ./shell/quicklinks.sh} # Interactive fzf web launcher ${builtins.readFile ./shell/jump.sh} # Directory jumper & interactive fuzzy navigation ${builtins.readFile ./shell/todo.sh} # Todo.txt & tuxedo shortcuts and syntax highlighter diff --git a/home/shell/secrets.sh b/home/shell/secrets.sh new file mode 100644 index 0000000..e8234c2 --- /dev/null +++ b/home/shell/secrets.sh @@ -0,0 +1,39 @@ +# shellcheck shell=bash +# 🔐 Secret Extraction & Clipboard Utilities +# Sourced in .bashrc to provide quick, safe extraction of SOPS-managed secrets into the Wayland clipboard. + +# 1. gh-token: Extracts the GitHub repository token from Homelab secrets directly into the Wayland clipboard. +# Uses 'sops -d --extract' to decrypt only the required key in memory without persisting plaintext to disk. +# Uses 'wl-copy -n --sensitive' to strip trailing newlines and flag the content as sensitive for clipboard managers. +gh-token() { + local secrets_file="${HOMELAB_SECRETS_FILE:-$HOME/Homelab/Core/nixos/secrets.yaml}" + + if ! command -v sops >/dev/null 2>&1; then + echo "Error: 'sops' is not installed or not in PATH." >&2 + return 1 + fi + + if ! command -v wl-copy >/dev/null 2>&1; then + echo "Error: 'wl-copy' is not installed or not in PATH." >&2 + return 1 + fi + + if [[ ! -f "$secrets_file" ]]; then + echo "Error: Secrets file not found at '$secrets_file'." >&2 + return 1 + fi + + local token + token=$(sops -d --extract '["system"]["gh_repo_token"]' "$secrets_file" 2>/dev/null) + local status=$? + + if [[ $status -ne 0 || -z "$token" ]]; then + echo "Error: Failed to extract 'system.gh_repo_token' from sops." >&2 + return 1 + fi + + printf "%s" "$token" | wl-copy -n --sensitive + unset token + + echo "GitHub repo token copied to clipboard (marked sensitive)." +}