Move scripts to Nix files
Move the scripts I commonly use into Nix files managed by Home Manager. Some, like `mounter` and `unmounter` are desktop-only, but this can be addressed in a future commit to create per-host scripts or desktop/non-desktop scripts. This commit also removes a number of unused scripts that are either included in packages like `git-extras` or aren't used.
This commit is contained in:
parent
0b437adccc
commit
dfebe131a6
26 changed files with 194 additions and 323 deletions
21
modules/home-manager/cli/scripts/create-script.nix
Executable file
21
modules/home-manager/cli/scripts/create-script.nix
Executable file
|
@ -0,0 +1,21 @@
|
||||||
|
{ 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";
|
||||||
|
'';
|
||||||
|
}
|
|
@ -1,10 +1,18 @@
|
||||||
{
|
{ pkgs, ... }:
|
||||||
home = {
|
|
||||||
sessionPath = [ "$HOME/.local/bin" ];
|
|
||||||
|
|
||||||
file.".local/bin" = {
|
{
|
||||||
source = ./scripts;
|
# TODO: separate desktop-only scripts?
|
||||||
recursive = true;
|
home.packages =
|
||||||
};
|
let
|
||||||
};
|
scriptNames = [
|
||||||
|
"create-script"
|
||||||
|
"mounter"
|
||||||
|
"move-firefox-screenshots"
|
||||||
|
"setbg"
|
||||||
|
"tag-release"
|
||||||
|
"unmounter"
|
||||||
|
"update-all-git-repos"
|
||||||
|
];
|
||||||
|
in
|
||||||
|
map (name: pkgs.callPackage ./${name}.nix { }) scriptNames;
|
||||||
}
|
}
|
||||||
|
|
45
modules/home-manager/cli/scripts/mounter.nix
Executable file
45
modules/home-manager/cli/scripts/mounter.nix
Executable file
|
@ -0,0 +1,45 @@
|
||||||
|
{ 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
|
||||||
|
'';
|
||||||
|
}
|
15
modules/home-manager/cli/scripts/move-firefox-screenshots.nix
Executable file
15
modules/home-manager/cli/scripts/move-firefox-screenshots.nix
Executable file
|
@ -0,0 +1,15 @@
|
||||||
|
{ 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}" \;
|
||||||
|
'';
|
||||||
|
}
|
|
@ -1,23 +0,0 @@
|
||||||
#!/usr/bin/env bash
|
|
||||||
|
|
||||||
if [[ "$1" == "" ]]; then
|
|
||||||
echo "Usage: ${0##*/} <script-name>"; exit 2
|
|
||||||
fi
|
|
||||||
|
|
||||||
set -o errexit
|
|
||||||
set -o nounset
|
|
||||||
set -o pipefail
|
|
||||||
|
|
||||||
cat > "$1" << EOF
|
|
||||||
#!/usr/bin/env bash
|
|
||||||
|
|
||||||
set -o errexit
|
|
||||||
set -o nounset
|
|
||||||
set -o pipefail
|
|
||||||
|
|
||||||
|
|
||||||
EOF
|
|
||||||
|
|
||||||
chmod +x "$1"
|
|
||||||
|
|
||||||
$EDITOR "$1";
|
|
|
@ -1,20 +0,0 @@
|
||||||
#!/usr/bin/env bash
|
|
||||||
|
|
||||||
# Abort a rebase, merge, `am`, a cherry-pick or a revert, depending on the situation.
|
|
||||||
|
|
||||||
if [[ -e .git/CHERRY_PICK_HEAD ]] ; then
|
|
||||||
exec git cherry-pick --abort "$@"
|
|
||||||
elif [[ -e .git/REVERT_HEAD ]] ; then
|
|
||||||
exec git revert --abort "$@"
|
|
||||||
elif [[ -e .git/rebase-apply/applying ]] ; then
|
|
||||||
exec git am --abort "$@"
|
|
||||||
elif [[ -e .git/rebase-apply ]] ; then
|
|
||||||
exec git rebase --abort "$@"
|
|
||||||
elif [[ -e .git/rebase-merge ]] ; then
|
|
||||||
exec git rebase --abort "$@"
|
|
||||||
elif [[ -e .git/MERGE_MODE ]] ; then
|
|
||||||
exec git merge --abort "$@"
|
|
||||||
else
|
|
||||||
echo git-abort: unknown state
|
|
||||||
exit 1
|
|
||||||
fi
|
|
|
@ -1,34 +0,0 @@
|
||||||
#!/usr/bin/env bash
|
|
||||||
|
|
||||||
# Creates a new bare clone of a repository with the bare files within a `.bare`
|
|
||||||
# directory. It also sets the origin URL so push and pull work as expected.
|
|
||||||
|
|
||||||
if [[ "$1" == "" ]]; then
|
|
||||||
echo "Usage: ${0##*/} <repository> [<directory>]"
|
|
||||||
exit 2
|
|
||||||
fi
|
|
||||||
|
|
||||||
set -euo pipefail
|
|
||||||
|
|
||||||
repository_url="${1}"
|
|
||||||
directory="${2:-}"
|
|
||||||
location=".bare"
|
|
||||||
|
|
||||||
# If no destination directory is specified, get it from the repository URL - the same as "git clone".
|
|
||||||
if [ -z "${directory}" ]; then
|
|
||||||
directory="$(basename -s .git "${repository_url}")"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Create the parent directory if needed.
|
|
||||||
mkdir -pv "${directory}"
|
|
||||||
cd "${directory}"
|
|
||||||
|
|
||||||
git clone --bare "${repository_url}" "${location}"
|
|
||||||
|
|
||||||
# Adjust origin fetch locations.
|
|
||||||
cd "${location}"
|
|
||||||
git config remote.origin.fetch "+refs/heads/*:refs/remotes/origin/*"
|
|
||||||
|
|
||||||
# Set .git file contents.
|
|
||||||
cd ..
|
|
||||||
echo "gitdir: ./${location}" > .git
|
|
|
@ -1,16 +0,0 @@
|
||||||
#!/usr/bin/env bash
|
|
||||||
|
|
||||||
# Continue a rebase or cherry-pick in the event of conflicts.
|
|
||||||
|
|
||||||
if [[ -e .git/CHERRY_PICK_HEAD ]] ; then
|
|
||||||
exec git cherry-pick --continue "$@"
|
|
||||||
elif [[ -e .git/rebase-apply/applying ]] ; then
|
|
||||||
exec git rebase --continue "$@"
|
|
||||||
elif [[ -e .git/rebase-apply ]] ; then
|
|
||||||
exec git rebase --continue "$@"
|
|
||||||
elif [[ -e .git/rebase-merge ]] ; then
|
|
||||||
exec git rebase --continue "$@"
|
|
||||||
else
|
|
||||||
echo git-abort: unknown state
|
|
||||||
exit 1
|
|
||||||
fi
|
|
|
@ -1,8 +0,0 @@
|
||||||
#!/usr/bin/env bash
|
|
||||||
|
|
||||||
set -euo pipefail
|
|
||||||
|
|
||||||
git fetch --all
|
|
||||||
git stash
|
|
||||||
git pull --rebase
|
|
||||||
git stash pop
|
|
|
@ -1,21 +0,0 @@
|
||||||
#!/usr/bin/env bash
|
|
||||||
|
|
||||||
# Usage: git up {branch} {remote}
|
|
||||||
|
|
||||||
set -e
|
|
||||||
|
|
||||||
if [[ $# < 1 ]]; then
|
|
||||||
echo "You must specify a branch name to update"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
BRANCH=$1
|
|
||||||
REMOTE=${2:-origin}
|
|
||||||
|
|
||||||
git checkout ${BRANCH} && \
|
|
||||||
git fetch ${REMOTE} && \
|
|
||||||
echo && \
|
|
||||||
git sl ${BRANCH}..${REMOTE}/${BRANCH} && \
|
|
||||||
echo && \
|
|
||||||
git pull --quiet && \
|
|
||||||
git checkout -
|
|
|
@ -1,17 +0,0 @@
|
||||||
#!/usr/bin/env bash
|
|
||||||
|
|
||||||
if [[ "$1" == "" ]]; then
|
|
||||||
echo "Usage: ${0##*/} <filename>"; exit 2
|
|
||||||
fi
|
|
||||||
|
|
||||||
set -euo pipefail
|
|
||||||
|
|
||||||
filename="${1}"
|
|
||||||
shift 1
|
|
||||||
|
|
||||||
pv "${filename}" \
|
|
||||||
| zcat \
|
|
||||||
| docker compose exec -T "${SERVICE_NAME:-database}" mysql \
|
|
||||||
-p"${DB_PASSWORD:-app}" \
|
|
||||||
-u"${DB_USER:-app}" \
|
|
||||||
"${DB_NAME:-app}"
|
|
|
@ -1,10 +0,0 @@
|
||||||
#!/bin/zsh
|
|
||||||
|
|
||||||
# Check if we should use the `main` or `master` branch for this repo.
|
|
||||||
# Prefer `main` to `master`.
|
|
||||||
|
|
||||||
if git show-ref --quiet origin/main || git rev-parse main &>/dev/null; then
|
|
||||||
echo main
|
|
||||||
else
|
|
||||||
echo master
|
|
||||||
fi
|
|
|
@ -1,36 +0,0 @@
|
||||||
#!/usr/bin/env bash
|
|
||||||
|
|
||||||
set -o errexit
|
|
||||||
set -o nounset
|
|
||||||
set -o pipefail
|
|
||||||
|
|
||||||
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
|
|
||||||
|
|
|
@ -1,11 +0,0 @@
|
||||||
#!/usr/bin/env bash
|
|
||||||
|
|
||||||
set -o errexit
|
|
||||||
set -o nounset
|
|
||||||
set -o pipefail
|
|
||||||
|
|
||||||
original_directory="${HOME}/Downloads"
|
|
||||||
new_directory="${HOME}/Pictures/Screenshots"
|
|
||||||
|
|
||||||
find "${original_directory}" -mindepth 1 -maxdepth 1 -type f -name "Screenshot *" \
|
|
||||||
-exec mv {} "${new_directory}" \;
|
|
|
@ -1,19 +0,0 @@
|
||||||
#!/usr/bin/env bash
|
|
||||||
|
|
||||||
if [[ "$1" == "" || "$2" == "" ]]; then
|
|
||||||
echo "Usage: ${0##*/} <machine-name> <module-name>"; exit 2
|
|
||||||
fi
|
|
||||||
|
|
||||||
set -euo pipefail
|
|
||||||
|
|
||||||
machine_name=$1
|
|
||||||
module_name=$2
|
|
||||||
|
|
||||||
git clone https://github.com/opdavies/drupal-module-template \
|
|
||||||
--depth=1 \
|
|
||||||
"${machine_name}"
|
|
||||||
|
|
||||||
pushd "${machine_name}"
|
|
||||||
just rename "${module_name}"
|
|
||||||
rm -fr .git .github justfile phpcs.xml.dist
|
|
||||||
popd
|
|
|
@ -1,3 +0,0 @@
|
||||||
#!/usr/bin/env bash
|
|
||||||
|
|
||||||
xwallpaper --zoom ${XDG_REPOS_DIR}/personal/nix-config/wallpaper/wallpaper.jpg
|
|
|
@ -1,9 +0,0 @@
|
||||||
#!/usr/bin/env bash
|
|
||||||
|
|
||||||
set -o errexit
|
|
||||||
set -o nounset
|
|
||||||
|
|
||||||
cd "${XDG_REPOS_DIR}/traefik-development"
|
|
||||||
|
|
||||||
docker compose up --detach
|
|
||||||
docker container ps
|
|
|
@ -1,19 +0,0 @@
|
||||||
#!/usr/bin/env bash
|
|
||||||
|
|
||||||
# Stops all running Docker containers except for the global Traefik proxy.
|
|
||||||
|
|
||||||
set -euo pipefail
|
|
||||||
|
|
||||||
# Show the running containers.
|
|
||||||
docker container ps
|
|
||||||
|
|
||||||
echo ""
|
|
||||||
|
|
||||||
# Stop the running containers and show any that are still running.
|
|
||||||
docker container ls |
|
|
||||||
tail -n +2 |
|
|
||||||
grep -v traefik-development-reverse-proxy-1 |
|
|
||||||
awk '{print $1}' |
|
|
||||||
xargs docker container stop
|
|
||||||
echo ""
|
|
||||||
docker container ps
|
|
|
@ -1,7 +0,0 @@
|
||||||
#!/usr/bin/env bash
|
|
||||||
|
|
||||||
set -o errexit
|
|
||||||
set -o nounset
|
|
||||||
|
|
||||||
docker container stop traefik-development-reverse-proxy-1
|
|
||||||
docker container ps
|
|
|
@ -1,11 +0,0 @@
|
||||||
#!/usr/bin/env bash
|
|
||||||
|
|
||||||
set -euo pipefail
|
|
||||||
|
|
||||||
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}"
|
|
|
@ -1,26 +0,0 @@
|
||||||
#!/usr/bin/env bash
|
|
||||||
|
|
||||||
set -o errexit
|
|
||||||
set -o nounset
|
|
||||||
set -o pipefail
|
|
||||||
|
|
||||||
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."
|
|
|
@ -1,25 +0,0 @@
|
||||||
#!/usr/bin/env bash
|
|
||||||
|
|
||||||
# Update all top-level Git repository clones within my Code directories to their
|
|
||||||
# latest version.
|
|
||||||
|
|
||||||
set -o errexit
|
|
||||||
set -o nounset
|
|
||||||
|
|
||||||
dirs=$(find "$XDG_REPOS_DIR" -mindepth 1 -maxdepth 2 -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 || true
|
|
||||||
git pull --rebase || true
|
|
||||||
done
|
|
11
modules/home-manager/cli/scripts/setbg.nix
Normal file
11
modules/home-manager/cli/scripts/setbg.nix
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
{ pkgs, writeShellApplication }:
|
||||||
|
|
||||||
|
writeShellApplication {
|
||||||
|
name = "setbg";
|
||||||
|
|
||||||
|
runtimeInputs = with pkgs; [ xwallpaper ];
|
||||||
|
|
||||||
|
text = ''
|
||||||
|
xwallpaper --zoom "''${XDG_REPOS_DIR}/personal/nix-config/wallpaper/wallpaper.jpg"
|
||||||
|
'';
|
||||||
|
}
|
17
modules/home-manager/cli/scripts/tag-release.nix
Normal file
17
modules/home-manager/cli/scripts/tag-release.nix
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
{ 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}"
|
||||||
|
'';
|
||||||
|
}
|
36
modules/home-manager/cli/scripts/unmounter.nix
Executable file
36
modules/home-manager/cli/scripts/unmounter.nix
Executable file
|
@ -0,0 +1,36 @@
|
||||||
|
{ 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."
|
||||||
|
'';
|
||||||
|
}
|
33
modules/home-manager/cli/scripts/update-all-git-repos.nix
Executable file
33
modules/home-manager/cli/scripts/update-all-git-repos.nix
Executable file
|
@ -0,0 +1,33 @@
|
||||||
|
{ 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
|
||||||
|
'';
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue