Move downloads organizer to common configuration

This commit is contained in:
Andrew Kvalheim 2022-03-15 18:43:27 -07:00
parent bc075dce4d
commit df6db78f77
2 changed files with 31 additions and 32 deletions

View file

@ -117,6 +117,25 @@ let
${exiftool}/bin/exiftool -overwrite_original -TagsFromFile "$input" -all:all -ICC_Profile "$output"
'');
organize-downloads = pkgs.writeShellScriptBin "organize-downloads" (with pkgs; ''
set -Eeuo pipefail
shopt -s nullglob
mkdir --parents --verbose '/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
destination="/home/ak/screenshots/$(basename "$source")"
mv --no-clobber --verbose "$source" "$destination"
${oxipng}/bin/oxipng --opt 'max' --strip 'safe' --interlace '0' "$destination"
done
'');
palette = import ./palette.nix;
in
{
@ -134,6 +153,18 @@ in
# User
home.file.".face".source = ./andrew.jpg;
# Services
systemd.user.paths.organize-downloads = {
Unit.Description = "Watch downloads";
Path.PathExistsGlob = "%h/Downloads/Screen{s,\\ S}hot\\ *.png";
Install.WantedBy = [ "default.target" ];
};
systemd.user.services.organize-downloads = {
Unit.Description = "Organize downloads";
Service.ExecStart = "${organize-downloads}/bin/organize-downloads";
Service.Nice = 10;
};
# Applications
home.packages = with pkgs; [
darktable

View file

@ -1,25 +1,5 @@
{ config, lib, pkgs, ... }:
let
organize-downloads = pkgs.writeShellScriptBin "organize-downloads" (with pkgs; ''
set -Eeuo pipefail
shopt -s nullglob
mkdir --parents --verbose '/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
destination="/home/ak/screenshots/$(basename "$source")"
mv --no-clobber --verbose "$source" "$destination"
${oxipng}/bin/oxipng --opt 'max' --strip 'safe' --interlace '0' "$destination"
done
'');
in
{
imports = [
../../common/home.nix
@ -37,18 +17,6 @@ in
(builtins.readFile ../../common/Compose) +
(builtins.readFile ./local/Compose);
# Services
systemd.user.paths.organize-downloads = {
Unit.Description = "Watch downloads";
Path.PathExistsGlob = "%h/Downloads/Screen{s,\\ S}hot\\ *.png";
Install.WantedBy = [ "default.target" ];
};
systemd.user.services.organize-downloads = {
Unit.Description = "Organize downloads";
Service.ExecStart = "${organize-downloads}/bin/organize-downloads";
Service.Nice = 10;
};
# Applications
home.packages = with pkgs; [
awscli2