feat: add more scripts
Some checks failed
CI / fmt (push) Failing after 2s
CI / check (push) Failing after 2s

This commit is contained in:
Nickolaj Jepsen 2026-01-22 23:12:42 +01:00
parent cd289da742
commit 575db8e773
7 changed files with 99 additions and 9 deletions

View file

@ -88,6 +88,7 @@ Secrets use agenix + agenix-rekey with YubiKey master identity:
1. **New program**: Create `modules/programs/<name>.nix`, guard with `lib.mkIf config.fireproof.desktop.enable` or similar 1. **New program**: Create `modules/programs/<name>.nix`, guard with `lib.mkIf config.fireproof.desktop.enable` or similar
2. **New homelab service**: Create `modules/homelab/<name>.nix`, add to `modules/homelab/default.nix` imports, and **add a link to the dashboard in `modules/homelab/glance.nix`** 2. **New homelab service**: Create `modules/homelab/<name>.nix`, add to `modules/homelab/default.nix` imports, and **add a link to the dashboard in `modules/homelab/glance.nix`**
3. **New host**: Run `just new-host <hostname> <username>`, then add to `hosts/default.nix` 3. **New host**: Run `just new-host <hostname> <username>`, then add to `hosts/default.nix`
4. **New script**: Always include `set -euo pipefail` at the start of bash scripts.
## Common Patterns ## Common Patterns

View file

@ -23,14 +23,41 @@ in {
systemd # for bootctl and systemctl systemd # for bootctl and systemctl
]; ];
}) })
(makeScript {
path = ./port-kill.bash;
runtimeInputs = with pkgs; [
lsof
procps
coreutils
];
})
(makeScript {
path = ./ssh-select.bash;
runtimeInputs = with pkgs; [
fzf
openssh
gawk
gnused
coreutils
];
})
(makeScript {
path = ./kctx.bash;
runtimeInputs = with pkgs; [
kubectl
fzf
];
})
] ]
++ lib.optional config.fireproof.desktop.enable (makeScript { ++ lib.optionals config.fireproof.desktop.enable [
path = ./screenshot.bash; (makeScript {
runtimeInputs = with pkgs; [ path = ./screenshot.bash;
slurp runtimeInputs = with pkgs; [
grim slurp
satty grim
wl-clipboard satty
]; wl-clipboard
}); ];
})
];
} }

21
modules/scripts/kctx.bash Normal file
View file

@ -0,0 +1,21 @@
#!/usr/bin/env bash
set -euo pipefail
if ! command -v kubectl &> /dev/null; then
echo "kubectl not found"
exit 1
fi
CONTEXTS=$(kubectl config get-contexts -o name)
if [ -z "$CONTEXTS" ]; then
echo "No kubernetes contexts found"
exit 1
fi
SELECTED=$(echo "$CONTEXTS" | fzf --prompt="Kube Context > " --height=20% --layout=reverse)
if [ -n "$SELECTED" ]; then
kubectl config use-context "$SELECTED"
echo "Switched to context: $SELECTED"
fi

View file

@ -0,0 +1,25 @@
#!/usr/bin/env bash
set -euo pipefail
PORT=$1
if [ -z "$PORT" ]; then
echo "Usage: port-kill <port>"
exit 1
fi
# lsof returns exit code 1 if no files found
PID=$(lsof -t -i:"$PORT" || true)
if [ -z "$PID" ]; then
echo "No process found on port $PORT"
exit 1
fi
COMMAND=$(ps -p "$PID" -o comm=)
echo "Process '$COMMAND' (PID $PID) is using port $PORT."
read -p "Kill? [y/N] " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
kill "$PID"
echo "Killed."
fi

View file

@ -1,4 +1,5 @@
#!/usr/bin/env bash #!/usr/bin/env bash
set -euo pipefail
# Find windows entry id using bootctl # Find windows entry id using bootctl
WINDOWS_ID=$(bootctl list --json=short | jq -r '.[] | select(.title != null) | select(.title | ascii_downcase | contains("windows")) | .id' | head -n 1) WINDOWS_ID=$(bootctl list --json=short | jq -r '.[] | select(.title != null) | select(.title | ascii_downcase | contains("windows")) | .id' | head -n 1)

View file

@ -1,3 +1,5 @@
#!/usr/bin/env bash #!/usr/bin/env bash
set -euo pipefail
AREA=$(slurp -d) AREA=$(slurp -d)
grim -t ppm -g "$AREA" - | satty -f - --initial-tool=arrow --early-exit --copy-command="wl-copy" --action-on-enter="save-to-clipboard" --disable-notifications grim -t ppm -g "$AREA" - | satty -f - --initial-tool=arrow --early-exit --copy-command="wl-copy" --action-on-enter="save-to-clipboard" --disable-notifications

View file

@ -0,0 +1,13 @@
#!/usr/bin/env bash
set -euo pipefail
# Extract hosts from config and known_hosts
# shellcheck disable=SC2002
hosts=$(cat ~/.ssh/config ~/.ssh/config.d/* 2>/dev/null | grep -P "^Host ([^*]+)$" | awk '{print $2}' ; cat ~/.ssh/known_hosts 2>/dev/null | cut -f 1 -d ' ' | sed -e 's/,.*//g' | sort -u)
selected=$(echo "$hosts" | fzf --prompt="SSH > " --height=20% --layout=reverse)
if [ -n "$selected" ]; then
echo "Connecting to $selected..."
ssh "$selected"
fi