Combine scripts and custom packages
All checks were successful
/ check (push) Successful in 1m40s

This commit is contained in:
Oliver Davies 2025-07-10 22:50:41 +01:00
parent 7780eca7a9
commit 5341b761ad
15 changed files with 29 additions and 38 deletions

View file

@ -1,21 +0,0 @@
{ pkgs }:
pkgs.writeShellApplication {
name = "create-script";
text = ''
cat > "$1" << EOF
#!/usr/bin/env bash
set -o errexit
set -o nounset
set -o pipefail
EOF
chmod +x "$1"
$EDITOR "$1";
'';
}

View file

@ -1,19 +0,0 @@
{ pkgs, ... }:
{
# TODO: separate desktop-only scripts?
home.packages =
let
scriptNames = [
"create-script"
"mounter"
"move-firefox-screenshots"
"setbg"
"tag-release"
"todos-add"
"unmounter"
"update-all-git-repos"
];
in
map (name: pkgs.callPackage ./${name}.nix { }) scriptNames;
}

View file

@ -1,45 +0,0 @@
{ pkgs }:
pkgs.writeShellApplication {
name = "mounter";
runtimeInputs = with pkgs; [
cryptsetup
dmenu
gawk
libnotify
util-linux
];
text = ''
lsblk_output="$(lsblk -rpo "uuid,name,type,size,label,mountpoint,mountpoints,fstype" | grep "part" | grep -Ev "/(boot|nix/store)")"
partition_names="$(echo "$lsblk_output" | awk '{ printf "%s (%s)\n", $2, $4 }' )";
selected=$(echo "$partition_names" | dmenu -p "Select drive:" | awk '{ print $1 }')
test -n "$selected"
mount_device="$selected"
if sudo cryptsetup isLuks "$selected"; then
luks_name="usb"
${"TERMINAL:-st"} -n floatterm -g 60x1 -e sudo cryptsetup open "$selected" "$luks_name"
mount_device="/dev/mapper/$luks_name"
test -b "/dev/mapper/$luks_name"
fi
mount_point=$(echo -e "/mnt\n/media\n/run/media/$USER" | dmenu -p "Select mount point:")
test -n "$mount_point"
sudo mkdir -p "$mount_point"
if sudo mount "$mount_device" "$mount_point"; then
notify-send "Device mounted" "Mounted $selected at $mount_point."
else
notify-send "Mount failed" "Failed to mount $selected."
exit 1
fi
'';
}

View file

@ -1,15 +0,0 @@
{ pkgs }:
pkgs.writeShellApplication {
name = "move-firefox-screenshots";
runtimeInputs = with pkgs; [ findutils ];
text = ''
original_directory="''${HOME}/Downloads"
new_directory="''${HOME}/Pictures/Screenshots"
find "''${original_directory}" -mindepth 1 -maxdepth 1 -type f -name "Screenshot *" \
-exec mv {} "''${new_directory}" \;
'';
}

View file

@ -1,11 +0,0 @@
{ pkgs, writeShellApplication }:
writeShellApplication {
name = "setbg";
runtimeInputs = with pkgs; [ xwallpaper ];
text = ''
xwallpaper --zoom "''${XDG_REPOS_DIR}/personal/nix-config/wallpaper/wallpaper.jpg"
'';
}

View file

@ -1,17 +0,0 @@
{ git, writeShellApplication }:
writeShellApplication {
name = "tag-release";
runtimeInputs = [ git ];
text = ''
commit_sha="''${1:-HEAD}"
tag="$(date '+%Y-%m-%d-%H.%M.%S')"
echo "Tagging commit $(git rev-parse "''${commit_sha}") as ''${tag}."
echo ""
git tag "''${tag}" "''${commit_sha}"
'';
}

View file

@ -1,21 +0,0 @@
{ pkgs }:
pkgs.writeShellApplication {
name = "todos-add";
runtimeInputs = with pkgs; [ coreutils ];
text = ''
TODOS_PATH="$HOME/Documents/wiki/todo.txt"
if [ ''${#} -eq 0 ]; then
if [ -p "/dev/stdin" ]; then
(cat; printf "\n\n") >> "''${TODOS_PATH}"
else
eval "''${TODOS_EDITOR}" "''${TODOS_PATH}"
fi
else
printf "%s\n\n" "''${*}" >> "''${TODOS_PATH}"
fi
'';
}

View file

@ -1,36 +0,0 @@
{ pkgs }:
pkgs.writeShellApplication {
name = "unmounter";
runtimeInputs = with pkgs; [
cryptsetup
dmenu
gawk
libnotify
util-linux
];
text = ''
lsblk_output="$(lsblk -nrpo "name,type,size,mountpoint")"
mounted_drives="$(echo "$lsblk_output" | awk '($2=="part"||$2="crypt")&&$4!~/\/boot|\/home$|SWAP/&&length($4)>1{printf "%s (%s)\n",$4,$3}')"
all_unmountable="$(echo "$mounted_drives" | sed "/^$/d;s/ *$//")"
test -n "$all_unmountable"
selected="$(echo "$all_unmountable" | dmenu -i -p "Unmount which drive?")"
selected="''${selected%% *}"
test -n "$selected"
sudo -A umount -l "/''${selected#*/}"
notify-send "Device unmounted" "$selected has been unmounted."
# Close the selected drive if decrypted.
cryptid="$(echo "$lsblk_output" | grep "/''${selected#*/}$")"
cryptid="''${cryptid%% *}"
test -b /dev/mapper/"''${cryptid##*/}"
sudo -A cryptsetup close "$cryptid"
notify-send "Device dencryption closed" "Drive is now securely locked again."
'';
}

View file

@ -1,33 +0,0 @@
{ pkgs }:
pkgs.writeShellApplication {
name = "update-all-git-repos";
runtimeInputs = with pkgs; [
findutils
git
];
text = ''
# Update all top-level Git repository clones within my Code directories to their
# latest version.
dirs=$(find "$XDG_REPOS_DIR" -mindepth 2 -maxdepth 3 -type d -name .git -not -path '*/*.old/*')
for dir in $dirs; do
repo_path="''${dir%/.git}"
cd "''${repo_path}"
# If the repo is a bare clone, the commands need to be run within the
# worktree directory.
[[ -f .bare/worktrees/main/gitdir && -d main && -f main/.git ]] && cd main
echo "Updating $(pwd)"
# Update the repository.
git fetch --all --jobs=4 --progress --prune
git pull --rebase
done
'';
}

View file

@ -9,7 +9,6 @@
./cli/node.nix
./cli/notes.nix
./cli/ranger.nix
./cli/scripts
./cli/starship.nix
./cli/sxhkd.nix
./cli/tmux-sessionizer.nix