mirror of
https://github.com/nickolaj-jepsen/nixos.git
synced 2026-01-23 00:26:48 +01:00
feat: add more scripts
This commit is contained in:
parent
cd289da742
commit
575db8e773
7 changed files with 99 additions and 9 deletions
1
.github/copilot-instructions.md
vendored
1
.github/copilot-instructions.md
vendored
|
|
@ -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
|
||||
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`
|
||||
4. **New script**: Always include `set -euo pipefail` at the start of bash scripts.
|
||||
|
||||
## Common Patterns
|
||||
|
||||
|
|
|
|||
|
|
@ -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
21
modules/scripts/kctx.bash
Normal 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
|
||||
25
modules/scripts/port-kill.bash
Normal file
25
modules/scripts/port-kill.bash
Normal 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
|
||||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
13
modules/scripts/ssh-select.bash
Normal file
13
modules/scripts/ssh-select.bash
Normal 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
|
||||
Loading…
Add table
Add a link
Reference in a new issue