Move non-Nix bash scripts
This commit is contained in:
parent
7c9ffc116e
commit
f2eea2d397
21 changed files with 11 additions and 10 deletions
|
@ -1,9 +0,0 @@
|
|||
{ self, ... }:
|
||||
{
|
||||
home.sessionPath = [ "$HOME/bin" ];
|
||||
|
||||
home.file."bin" = {
|
||||
source = "${self}/bin";
|
||||
recursive = true;
|
||||
};
|
||||
}
|
10
modules/home-manager/cli/bin/default.nix
Normal file
10
modules/home-manager/cli/bin/default.nix
Normal file
|
@ -0,0 +1,10 @@
|
|||
{
|
||||
home = {
|
||||
sessionPath = [ "$HOME/.local/bin" ];
|
||||
|
||||
file.".local/bin" = {
|
||||
source = ./scripts;
|
||||
recursive = true;
|
||||
};
|
||||
};
|
||||
}
|
21
modules/home-manager/cli/bin/scripts/create-script
Executable file
21
modules/home-manager/cli/bin/scripts/create-script
Executable file
|
@ -0,0 +1,21 @@
|
|||
#!/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
|
||||
|
||||
echo "${1}"
|
||||
EOF
|
||||
|
||||
chmod +x "${1}"
|
20
modules/home-manager/cli/bin/scripts/git-abort
Executable file
20
modules/home-manager/cli/bin/scripts/git-abort
Executable file
|
@ -0,0 +1,20 @@
|
|||
#!/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
|
34
modules/home-manager/cli/bin/scripts/git-bare-clone
Executable file
34
modules/home-manager/cli/bin/scripts/git-bare-clone
Executable file
|
@ -0,0 +1,34 @@
|
|||
#!/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
|
16
modules/home-manager/cli/bin/scripts/git-continue
Executable file
16
modules/home-manager/cli/bin/scripts/git-continue
Executable file
|
@ -0,0 +1,16 @@
|
|||
#!/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
|
8
modules/home-manager/cli/bin/scripts/git-sync
Executable file
8
modules/home-manager/cli/bin/scripts/git-sync
Executable file
|
@ -0,0 +1,8 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
git fetch --all
|
||||
git stash
|
||||
git pull --rebase
|
||||
git stash pop
|
21
modules/home-manager/cli/bin/scripts/git-up
Executable file
21
modules/home-manager/cli/bin/scripts/git-up
Executable file
|
@ -0,0 +1,21 @@
|
|||
#!/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 -
|
17
modules/home-manager/cli/bin/scripts/import-gzip-database
Executable file
17
modules/home-manager/cli/bin/scripts/import-gzip-database
Executable file
|
@ -0,0 +1,17 @@
|
|||
#!/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}"
|
10
modules/home-manager/cli/bin/scripts/main-or-master-branch
Executable file
10
modules/home-manager/cli/bin/scripts/main-or-master-branch
Executable file
|
@ -0,0 +1,10 @@
|
|||
#!/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
|
36
modules/home-manager/cli/bin/scripts/mounter
Executable file
36
modules/home-manager/cli/bin/scripts/mounter
Executable file
|
@ -0,0 +1,36 @@
|
|||
#!/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
|
||||
|
11
modules/home-manager/cli/bin/scripts/move-firefox-screenshots
Executable file
11
modules/home-manager/cli/bin/scripts/move-firefox-screenshots
Executable file
|
@ -0,0 +1,11 @@
|
|||
#!/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}" \;
|
19
modules/home-manager/cli/bin/scripts/new-drupal-module
Executable file
19
modules/home-manager/cli/bin/scripts/new-drupal-module
Executable file
|
@ -0,0 +1,19 @@
|
|||
#!/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
|
3
modules/home-manager/cli/bin/scripts/setbg
Executable file
3
modules/home-manager/cli/bin/scripts/setbg
Executable file
|
@ -0,0 +1,3 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
xwallpaper --zoom ~/Code/dotfiles/wallpaper/wallpaper.jpg
|
9
modules/home-manager/cli/bin/scripts/start-traefik
Executable file
9
modules/home-manager/cli/bin/scripts/start-traefik
Executable file
|
@ -0,0 +1,9 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
set -o errexit
|
||||
set -o nounset
|
||||
|
||||
cd "${XDG_REPOS_DIR}/traefik-development"
|
||||
|
||||
docker compose up --detach
|
||||
docker container ps
|
19
modules/home-manager/cli/bin/scripts/stop-all-docker-containers
Executable file
19
modules/home-manager/cli/bin/scripts/stop-all-docker-containers
Executable file
|
@ -0,0 +1,19 @@
|
|||
#!/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
|
7
modules/home-manager/cli/bin/scripts/stop-traefik
Executable file
7
modules/home-manager/cli/bin/scripts/stop-traefik
Executable file
|
@ -0,0 +1,7 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
set -o errexit
|
||||
set -o nounset
|
||||
|
||||
docker container stop traefik-development-reverse-proxy-1
|
||||
docker container ps
|
13
modules/home-manager/cli/bin/scripts/tag-release
Executable file
13
modules/home-manager/cli/bin/scripts/tag-release
Executable file
|
@ -0,0 +1,13 @@
|
|||
#!/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 ""
|
||||
|
||||
# Tag the appropriate commit and push to the remote.
|
||||
git tag "${tag}" "${commit_sha}"
|
||||
git push origin "refs/tags/${tag}" --no-verify
|
26
modules/home-manager/cli/bin/scripts/unmounter
Executable file
26
modules/home-manager/cli/bin/scripts/unmounter
Executable file
|
@ -0,0 +1,26 @@
|
|||
#!/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."
|
25
modules/home-manager/cli/bin/scripts/update-all-git-repos
Executable file
25
modules/home-manager/cli/bin/scripts/update-all-git-repos
Executable file
|
@ -0,0 +1,25 @@
|
|||
#!/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
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
{
|
||||
imports = [
|
||||
./bin.nix
|
||||
./bin
|
||||
./bluetuith.nix
|
||||
./direnv.nix
|
||||
./fzf.nix
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue