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

@ -23,14 +23,41 @@ in {
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 {
path = ./screenshot.bash;
runtimeInputs = with pkgs; [
slurp
grim
satty
wl-clipboard
];
});
++ lib.optionals config.fireproof.desktop.enable [
(makeScript {
path = ./screenshot.bash;
runtimeInputs = with pkgs; [
slurp
grim
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
set -euo pipefail
# 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)

View file

@ -1,3 +1,5 @@
#!/usr/bin/env bash
set -euo pipefail
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

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