Use resholve
This commit is contained in:
parent
bba500b13d
commit
b7eabca46a
11 changed files with 177 additions and 140 deletions
|
@ -453,6 +453,7 @@ reimagining
|
|||
reimplementing
|
||||
renamer
|
||||
resending
|
||||
resholve
|
||||
restrictor
|
||||
retryable
|
||||
RGB
|
||||
|
|
|
@ -1,36 +1,14 @@
|
|||
{ writeShellScriptBin
|
||||
{ resholve
|
||||
|
||||
# Dependencies
|
||||
, bash
|
||||
, coreutils
|
||||
, git
|
||||
, moreutils
|
||||
}:
|
||||
|
||||
writeShellScriptBin "add-words" ''
|
||||
set -Eeuo pipefail
|
||||
|
||||
cd "/home/ak/src/configuration"
|
||||
|
||||
message='Update spell check word list'
|
||||
txt='common/resources/words.txt'
|
||||
|
||||
if [[ -n "$(${git}/bin/git status --porcelain "$txt")" ]]; then
|
||||
echo "Error: Existing uncommitted changes to $txt" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [[ -n "$(${git}/bin/git diff --cached --name-only)" ]]; then
|
||||
echo "Error: Existing staged changes" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
printf '%s\n' "$@" | sort "$txt" - | uniq | ${moreutils}/bin/sponge "$txt"
|
||||
${git}/bin/git add "$txt"
|
||||
|
||||
if [[ "$(${git}/bin/git log -1 --pretty='%s')" == "$message" ]] && ! ${git}/bin/git merge-base --is-ancestor 'HEAD' '@{u}'; then
|
||||
${git}/bin/git commit --amend --no-edit
|
||||
else
|
||||
${git}/bin/git commit --message "$message"
|
||||
fi
|
||||
|
||||
${git}/bin/git show HEAD
|
||||
''
|
||||
resholve.writeScriptBin "add-words" {
|
||||
interpreter = "${bash}/bin/bash";
|
||||
inputs = [ coreutils git moreutils ];
|
||||
execer = [ "cannot:${git}/bin/git" ];
|
||||
} (builtins.readFile ./resources/add-words)
|
||||
|
|
|
@ -1,40 +1,13 @@
|
|||
{ writeShellScriptBin
|
||||
{ resholve
|
||||
|
||||
# Dependencies
|
||||
, bash
|
||||
, git
|
||||
, gnugrep
|
||||
}:
|
||||
|
||||
writeShellScriptBin "gh" ''
|
||||
set -Eeuo pipefail
|
||||
|
||||
if [[ ! ( "''${1-}" =~ ^([-_[:alnum:]]+)/([-_.[:alnum:]]+)$ ) ]]; then
|
||||
echo "Usage: ''${0##*/} <owner>/<repo>" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
owner="''${BASH_REMATCH[1]}"
|
||||
repo="''${BASH_REMATCH[2]}"
|
||||
|
||||
https="https://github.com/$owner/$repo.git"
|
||||
ssh="git@github.com:$owner/$repo.git"
|
||||
|
||||
if ${git}/bin/git rev-parse --is-inside-work-tree >/dev/null 2>&1; then
|
||||
if ${git}/bin/git remote | grep --quiet "^$owner$"; then
|
||||
echo "Configuring GitHub remote $owner/$repo for HTTPS fetch and SSH push" >&2
|
||||
|
||||
${git}/bin/git remote set-url "$owner" "$https"
|
||||
${git}/bin/git remote set-url --push "$owner" "$ssh"
|
||||
else
|
||||
echo "Adding GitHub remote $owner/$repo with HTTPS fetch and SSH push" >&2
|
||||
|
||||
${git}/bin/git remote add -f "$owner" "$https"
|
||||
${git}/bin/git remote set-url --push "$owner" "$ssh"
|
||||
fi
|
||||
else
|
||||
echo "Cloning from GitHub remote $owner/$repo with HTTPS fetch and SSH push" >&2
|
||||
|
||||
${git}/bin/git clone --origin "$owner" "$https" "$repo"
|
||||
cd "$repo"
|
||||
${git}/bin/git remote set-url --push "$owner" "$ssh"
|
||||
fi
|
||||
''
|
||||
resholve.writeScriptBin "gh" {
|
||||
interpreter = "${bash}/bin/bash";
|
||||
inputs = [ git gnugrep ];
|
||||
execer = [ "cannot:${git}/bin/git" ];
|
||||
} (builtins.readFile ./resources/gh)
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
{ writeShellScriptBin
|
||||
{ resholve
|
||||
|
||||
# Dependencies
|
||||
, bash
|
||||
, coreutils
|
||||
, exiftool
|
||||
, file
|
||||
, imagemagick
|
||||
|
@ -8,28 +10,8 @@
|
|||
, mozjpeg
|
||||
}:
|
||||
|
||||
writeShellScriptBin "mozjpeg" ''
|
||||
set -Eeuo pipefail
|
||||
|
||||
input="$1"
|
||||
shift
|
||||
|
||||
mime="$(${file}/bin/file --brief --mime "$input")"
|
||||
output="''${input%.*}.jpg"
|
||||
|
||||
if [[ "$mime" == 'image/heic'* ]]; then
|
||||
png="$(mktemp --suffix=.png)"; trap 'rm -f "$png"' EXIT
|
||||
|
||||
${libheif}/bin/heif-convert "$input" "$png"
|
||||
|
||||
from="png:$png"
|
||||
else
|
||||
from="$input"
|
||||
fi
|
||||
|
||||
${imagemagick}/bin/convert -flatten "$from" "ppm:-" \
|
||||
| ${mozjpeg}/bin/cjpeg -optimize -quality 90 "$@" \
|
||||
> "$output"
|
||||
|
||||
${exiftool}/bin/exiftool -overwrite_original -TagsFromFile "$input" -all:all -ICC_Profile "$output"
|
||||
''
|
||||
resholve.writeScriptBin "mozjpeg" {
|
||||
interpreter = "${bash}/bin/bash";
|
||||
inputs = [ coreutils exiftool file imagemagick libheif mozjpeg ];
|
||||
execer = [ "cannot:${exiftool}/bin/exiftool" ];
|
||||
} (builtins.readFile ./resources/mozjpeg)
|
||||
|
|
|
@ -1,26 +1,18 @@
|
|||
{ writeShellScriptBin }:
|
||||
{ resholve
|
||||
|
||||
writeShellScriptBin "off" ''
|
||||
set -Eeuxo pipefail
|
||||
# Dependencies
|
||||
, bash
|
||||
}:
|
||||
|
||||
# Containers
|
||||
podman system prune --force --volumes
|
||||
docker system prune --force --volumes
|
||||
|
||||
# Channels
|
||||
sudo nix-channel --update
|
||||
nix-channel --update
|
||||
|
||||
# User packages
|
||||
home-manager expire-generations '-7 days'
|
||||
home-manager switch
|
||||
|
||||
# System packages
|
||||
sudo nixos-rebuild boot
|
||||
|
||||
# Filesystem
|
||||
btrfs filesystem df /
|
||||
sudo btrfs balance start --enqueue -dusage=50 -musage=50 /
|
||||
|
||||
sudo poweroff
|
||||
''
|
||||
resholve.writeScriptBin "off" {
|
||||
interpreter = "${bash}/bin/bash";
|
||||
inputs = [ ];
|
||||
fake.external = [
|
||||
"btrfs"
|
||||
"docker"
|
||||
"home-manager"
|
||||
"nix-channel"
|
||||
"podman"
|
||||
"sudo" # Pending https://github.com/abathur/resholve/issues/29
|
||||
];
|
||||
} (builtins.readFile ./resources/off)
|
||||
|
|
|
@ -1,31 +1,10 @@
|
|||
{ config, lib, pkgs, ... }:
|
||||
|
||||
let
|
||||
handler = with pkgs; writeShellScriptBin "organize-downloads" ''
|
||||
set -Eeuo pipefail
|
||||
shopt -s nullglob
|
||||
|
||||
intermediate_dir='/home/ak/screenshots/.unoptimized'
|
||||
screenshots_dir='/home/ak/screenshots'
|
||||
|
||||
for source in /home/ak/Downloads/Screen{s,\ S}hot\ *.png; do
|
||||
while (( $(date +%s) - $(date '+%s' --reference "$source") <= 1 )); do
|
||||
echo "Waiting for file to settle: $source"
|
||||
sleep 1s
|
||||
done
|
||||
|
||||
intermediates+=( "$intermediate_dir/''${source##*/}" )
|
||||
mkdir --parents --verbose "$intermediate_dir"
|
||||
mv --no-clobber --verbose "$source" "''${intermediates[-1]}"
|
||||
done
|
||||
|
||||
[[ "$(< /sys/class/power_supply/AC/online)" == '1' ]] && o='8' || o='3'
|
||||
${efficient-compression-tool}/bin/ect -"$o" -keep --mt-file "''${intermediates[@]}"
|
||||
|
||||
mkdir --parents --verbose "$screenshots_dir"
|
||||
mv --no-clobber --verbose --target-directory "$screenshots_dir" "''${intermediates[@]}"
|
||||
rmdir --ignore-fail-on-non-empty "$intermediate_dir"
|
||||
'';
|
||||
handler = with pkgs; resholve.writeScriptBin "organize-downloads" {
|
||||
interpreter = "${bash}/bin/bash";
|
||||
inputs = [ coreutils efficient-compression-tool ];
|
||||
} (builtins.readFile ./resources/organize-downloads);
|
||||
in
|
||||
{
|
||||
config = {
|
||||
|
|
28
packages/resources/add-words
Normal file
28
packages/resources/add-words
Normal file
|
@ -0,0 +1,28 @@
|
|||
#!/usr/bin/env bash
|
||||
set -Eeuo pipefail
|
||||
|
||||
cd '/home/ak/src/configuration'
|
||||
|
||||
message='Update spell check word list'
|
||||
txt='common/resources/words.txt'
|
||||
|
||||
if [[ -n "$(git status --porcelain "$txt")" ]]; then
|
||||
echo "Error: Existing uncommitted changes to $txt" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [[ -n "$(git diff --cached --name-only)" ]]; then
|
||||
echo "Error: Existing staged changes" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
printf '%s\n' "$@" | sort "$txt" - | uniq | sponge "$txt"
|
||||
git add "$txt"
|
||||
|
||||
if [[ "$(git log -1 --pretty='%s')" == "$message" ]] && ! git merge-base --is-ancestor 'HEAD' '@{u}'; then
|
||||
git commit --amend --no-edit
|
||||
else
|
||||
git commit --message "$message"
|
||||
fi
|
||||
|
||||
git show HEAD
|
33
packages/resources/gh
Normal file
33
packages/resources/gh
Normal file
|
@ -0,0 +1,33 @@
|
|||
#!/usr/bin/env bash
|
||||
set -Eeuo pipefail
|
||||
|
||||
if [[ ! ( "${1-}" =~ ^([-_[:alnum:]]+)/([-_.[:alnum:]]+)$ ) ]]; then
|
||||
echo "Usage: ${0##*/} <owner>/<repo>" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
owner="${BASH_REMATCH[1]}"
|
||||
repo="${BASH_REMATCH[2]}"
|
||||
|
||||
https="https://github.com/$owner/$repo.git"
|
||||
ssh="git@github.com:$owner/$repo.git"
|
||||
|
||||
if git rev-parse --is-inside-work-tree >/dev/null 2>&1; then
|
||||
if git remote | grep --quiet "^$owner$"; then
|
||||
echo "Configuring GitHub remote $owner/$repo for HTTPS fetch and SSH push" >&2
|
||||
|
||||
git remote set-url "$owner" "$https"
|
||||
git remote set-url --push "$owner" "$ssh"
|
||||
else
|
||||
echo "Adding GitHub remote $owner/$repo with HTTPS fetch and SSH push" >&2
|
||||
|
||||
git remote add -f "$owner" "$https"
|
||||
git remote set-url --push "$owner" "$ssh"
|
||||
fi
|
||||
else
|
||||
echo "Cloning from GitHub remote $owner/$repo with HTTPS fetch and SSH push" >&2
|
||||
|
||||
git clone --origin "$owner" "$https" "$repo"
|
||||
cd "$repo"
|
||||
git remote set-url --push "$owner" "$ssh"
|
||||
fi
|
24
packages/resources/mozjpeg
Normal file
24
packages/resources/mozjpeg
Normal file
|
@ -0,0 +1,24 @@
|
|||
#!/usr/bin/env bash
|
||||
set -Eeuo pipefail
|
||||
|
||||
input="$1"
|
||||
shift
|
||||
|
||||
mime="$(file --brief --mime "$input")"
|
||||
output="${input%.*}.jpg"
|
||||
|
||||
if [[ "$mime" == 'image/heic'* ]]; then
|
||||
png="$(mktemp --suffix=.png)"; trap 'rm -f "$png"' EXIT
|
||||
|
||||
heif-convert "$input" "$png"
|
||||
|
||||
from="png:$png"
|
||||
else
|
||||
from="$input"
|
||||
fi
|
||||
|
||||
convert -flatten "$from" "ppm:-" \
|
||||
| cjpeg -optimize -quality 90 "$@" \
|
||||
> "$output"
|
||||
|
||||
exiftool -overwrite_original -TagsFromFile "$input" -all:all -ICC_Profile "$output"
|
23
packages/resources/off
Normal file
23
packages/resources/off
Normal file
|
@ -0,0 +1,23 @@
|
|||
#!/usr/bin/env bash
|
||||
set -Eeuxo pipefail
|
||||
|
||||
# Containers
|
||||
podman system prune --force --volumes
|
||||
docker system prune --force --volumes
|
||||
|
||||
# Channels
|
||||
sudo nix-channel --update
|
||||
nix-channel --update
|
||||
|
||||
# User packages
|
||||
home-manager expire-generations '-7 days'
|
||||
home-manager switch
|
||||
|
||||
# System packages
|
||||
sudo nixos-rebuild boot
|
||||
|
||||
# Filesystem
|
||||
btrfs filesystem df /
|
||||
sudo btrfs balance start --enqueue -dusage=50 -musage=50 /
|
||||
|
||||
sudo poweroff
|
24
packages/resources/organize-downloads
Normal file
24
packages/resources/organize-downloads
Normal file
|
@ -0,0 +1,24 @@
|
|||
#!/usr/bin/env bash
|
||||
set -Eeuo pipefail
|
||||
shopt -s nullglob
|
||||
|
||||
intermediate_dir='/home/ak/screenshots/.unoptimized'
|
||||
screenshots_dir='/home/ak/screenshots'
|
||||
|
||||
for source in /home/ak/Downloads/Screen{s,\ S}hot\ *.png; do
|
||||
while (( $(date +%s) - $(date '+%s' --reference "$source") <= 1 )); do
|
||||
echo "Waiting for file to settle: $source"
|
||||
sleep 1s
|
||||
done
|
||||
|
||||
intermediates+=( "$intermediate_dir/${source##*/}" )
|
||||
mkdir --parents --verbose "$intermediate_dir"
|
||||
mv --no-clobber --verbose "$source" "${intermediates[-1]}"
|
||||
done
|
||||
|
||||
[[ "$(< /sys/class/power_supply/AC/online)" == '1' ]] && o='8' || o='3'
|
||||
ect -"$o" -keep --mt-file "${intermediates[@]}"
|
||||
|
||||
mkdir --parents --verbose "$screenshots_dir"
|
||||
mv --no-clobber --verbose --target-directory "$screenshots_dir" "${intermediates[@]}"
|
||||
rmdir --ignore-fail-on-non-empty "$intermediate_dir"
|
Loading…
Reference in a new issue