cleanup scripts

This commit is contained in:
Adithya 2024-05-18 10:24:28 +05:30
parent 5e0bfd0aa4
commit 5c5c3a4027
Signed by: adtya
GPG key ID: B8857BFBA2C47B9C
14 changed files with 153 additions and 61 deletions

View file

@ -83,10 +83,10 @@
inherit system; inherit system;
}; };
in in
with pkgs; { {
formatter = nixpkgs-fmt; formatter = pkgs.nixpkgs-fmt;
devShells.default = mkShell { devShells.default = pkgs.mkShell {
buildInputs = [ buildInputs = with pkgs; [
git git
git-crypt git-crypt
statix statix

View file

@ -1,8 +1,7 @@
{ config, pkgs, ... }: { pkgs, ... }:
let let
pictures = "${config.xdg.userDirs.pictures}"; change-wallpaper = "${pkgs.setpaper}/bin/setpaper";
change-wallpaper = "${pkgs.scripts}/bin/chpaper ${pictures}/Wallpapers"; wallpaper-downloader = "${pkgs.getpaper}/bin/getpaper";
wallpaper-downloader = "${pkgs.scripts}/bin/wallhaven ${pictures}/Wallpapers";
in in
{ {
systemd.user = { systemd.user = {

View file

@ -167,9 +167,9 @@ in
"SUPER,i, exec, ${firefox}" "SUPER,i, exec, ${firefox}"
"SUPER_SHIFT,i, exec, ${firefox} --private-window" "SUPER_SHIFT,i, exec, ${firefox} --private-window"
"SUPER_SHIFT,escape, exec, ${pkgs.scripts}/bin/power-menu" "SUPER_SHIFT,escape, exec, ${pkgs.misc-scripts}/bin/power-menu"
"SUPER,f11, exec, ${pkgs.scripts}/bin/tmux-sessions" "SUPER,f11, exec, ${pkgs.misc-scripts}/bin/tmux-sessions"
"SUPER_SHIFT,y, exec, ${pkgs.scripts}/bin/youtube" "SUPER_SHIFT,y, exec, ${pkgs.youtube}/bin/youtube"
"SUPER_SHIFT,b, exec, ${pkgs.rofi-bluetooth}/bin/rofi-bluetooth" "SUPER_SHIFT,b, exec, ${pkgs.rofi-bluetooth}/bin/rofi-bluetooth"
"SUPER,escape, exec, ${loginctl} lock-session" "SUPER,escape, exec, ${loginctl} lock-session"

View file

@ -1,6 +1,9 @@
final: prev: { final: prev: {
dracula-gtk = prev.callPackage ./dracula-gtk { }; dracula-gtk = prev.callPackage ./dracula-gtk { };
scripts = prev.callPackage ./scripts { }; misc-scripts = prev.callPackage ./scripts/misc { };
getpaper = prev.callPackage ./scripts/getpaper { };
setpaper = prev.callPackage ./scripts/setpaper { };
youtube = prev.callPackage ./scripts/youtube { };
rofi-bluetooth = prev.callPackage ./rofi-bluetooth { }; rofi-bluetooth = prev.callPackage ./rofi-bluetooth { };
smc-manjari = prev.callPackage ./smc-manjari { }; smc-manjari = prev.callPackage ./smc-manjari { };
smc-nupuram = prev.callPackage ./smc-nupuram { }; smc-nupuram = prev.callPackage ./smc-nupuram { };

View file

@ -1,24 +0,0 @@
#!/bin/sh
set -eu
DIR="${1:-}"
if [ -z "$DIR" ]; then
echo "Usage: $0 <path to directory containing wallpapers>"
exit 1
fi
random_paper() {
if [ -d "$DIR" ] ; then
find -L "${DIR}"/ -type f -regextype egrep -regex ".*\.(jpe?g|png)$" | shuf -n1 --random-source=/dev/urandom
elif [ -f "$DIR" ] ; then
echo "$DIR"
fi
}
swww img \
--transition-type any \
--transition-step 2 \
--transition-duration 2 \
"$(random_paper)"

View file

@ -0,0 +1,30 @@
{ lib
, stdenvNoCC
, makeWrapper
, curl
, envsubst
, jq
, libsecret
,
}:
stdenvNoCC.mkDerivation {
pname = "getpaper";
version = "0.1";
src = ./.;
nativeBuildInputs = [ makeWrapper ];
installPhase = ''
runHook preInstall
mkdir -p $out/bin
cp getpaper.sh $out/bin/getpaper
chmod +x $out/bin/getpaper
runHook postInstall
'';
postInstall = ''
wrapProgram $out/bin/getpaper --prefix PATH : ${lib.makeBinPath [envsubst jq curl libsecret]}
'';
}

View file

@ -11,17 +11,23 @@ fi
CURL_BASE_CMD="curl --silent ${API_KEY_HEADER}" CURL_BASE_CMD="curl --silent ${API_KEY_HEADER}"
DIR="${1:-/tmp}"
mkdir -p "${DIR}"
CONFIG_DIR="${XDG_CONFIG_HOME:-${HOME}/.config}" CONFIG_DIR="${XDG_CONFIG_HOME:-${HOME}/.config}"
CONFIG_FILE="${CONFIG_DIR}/wallpaper_config.json" CONFIG_FILE="${CONFIG_DIR}/wallpaper_config.json"
if [ ! -e "${CONFIG_FILE}" ]; then if [ ! -e "${CONFIG_FILE}" ]; then
echo '{"tags":null,"categories":"100","purity":"100", "sorting":"random", "size":null, "ratios":null, "colors":null, "ai_filter":1, "range": "1M"}' | jq > "${CONFIG_FILE}" echo '{"tags":null,"categories":"100","purity":"100", "sorting":"random", "size":null, "ratios":null, "colors":null, "ai_filter":1, "range": "1M", "dir":"~/Pictures/Wallpapers"}' | jq > "${CONFIG_FILE}"
fi fi
CONFIG="$(cat "${CONFIG_FILE}")" CONFIG="$(cat "${CONFIG_FILE}")"
DIR="$(echo "${CONFIG}" | jq -r '.dir // empty')"
if [ -z "${DIR}" ]; then
DIR="${XDG_PICTURES_DIR:-${HOME}/Pictures}/Wallpapers"
echo "Warning: wallpaper directory not set. using fallback directory ${DIR}" >&2
fi
DIR="$(echo "${DIR}" | envsubst)"
mkdir -p "${DIR}"
AI_FILTER="$(echo "${CONFIG}" | jq -r '.ai_filter // empty')" AI_FILTER="$(echo "${CONFIG}" | jq -r '.ai_filter // empty')"
if [ -n "${AI_FILTER}" ]; then if [ -n "${AI_FILTER}" ]; then
AI_FILTER="ai_art_filter=${AI_FILTER}&" AI_FILTER="ai_art_filter=${AI_FILTER}&"
@ -38,7 +44,7 @@ if [ -n "${CATEGORIES}" ]; then
fi fi
PURITY="$(echo "${CONFIG}" | jq -r '.purity // empty')" PURITY="$(echo "${CONFIG}" | jq -r '.purity // empty')"
if [ -n "${PURITY}" ]; then if [ -n "${PURITY}" ] && [ -n "${API_KEY_HEADER}" ]; then
PURITY="purity=${PURITY}&" PURITY="purity=${PURITY}&"
fi fi

View file

@ -1,22 +1,16 @@
{ lib { lib
, stdenvNoCC , stdenvNoCC
, makeWrapper , makeWrapper
, curl
, hyprland , hyprland
, jq
, kitty , kitty
, libnotify , libnotify
, libsecret
, rofi-wayland , rofi-wayland
, swww
, tmux , tmux
, ueberzugpp
, ytfzf
, ,
}: }:
stdenvNoCC.mkDerivation { stdenvNoCC.mkDerivation {
pname = "scripts"; pname = "misc-scripts";
version = "1.0"; version = "0.1";
src = ./.; src = ./.;
nativeBuildInputs = [ makeWrapper ]; nativeBuildInputs = [ makeWrapper ];
@ -32,23 +26,11 @@ stdenvNoCC.mkDerivation {
cp tmux-sessions.sh $out/bin/tmux-sessions cp tmux-sessions.sh $out/bin/tmux-sessions
chmod +x $out/bin/tmux-sessions chmod +x $out/bin/tmux-sessions
cp chpaper.sh $out/bin/chpaper
chmod +x $out/bin/chpaper
cp wallhaven.sh $out/bin/wallhaven
chmod +x $out/bin/wallhaven
cp youtube.sh $out/bin/youtube
chmod +x $out/bin/youtube
runHook postInstall runHook postInstall
''; '';
postInstall = '' postInstall = ''
wrapProgram $out/bin/power-menu --prefix PATH : ${lib.makeBinPath [libnotify rofi-wayland hyprland]} wrapProgram $out/bin/power-menu --prefix PATH : ${lib.makeBinPath [libnotify rofi-wayland hyprland]}
wrapProgram $out/bin/tmux-sessions --prefix PATH : ${lib.makeBinPath [tmux kitty rofi-wayland]} wrapProgram $out/bin/tmux-sessions --prefix PATH : ${lib.makeBinPath [tmux kitty rofi-wayland]}
wrapProgram $out/bin/chpaper --prefix PATH : ${lib.makeBinPath [swww]}
wrapProgram $out/bin/wallhaven --prefix PATH : ${lib.makeBinPath [jq curl libsecret]}
wrapProgram $out/bin/youtube --prefix PATH : ${lib.makeBinPath [kitty ytfzf rofi-wayland ueberzugpp]}
''; '';
} }

View file

@ -0,0 +1,29 @@
{ lib
, stdenvNoCC
, makeWrapper
, envsubst
, jq
, swww
,
}:
stdenvNoCC.mkDerivation {
pname = "setpaper";
version = "0.1";
src = ./.;
nativeBuildInputs = [ makeWrapper ];
installPhase = ''
runHook preInstall
mkdir -p $out/bin
cp setpaper.sh $out/bin/setpaper
chmod +x $out/bin/setpaper
runHook postInstall
'';
postInstall = ''
wrapProgram $out/bin/setpaper --prefix PATH : ${lib.makeBinPath [envsubst jq swww]}
'';
}

View file

@ -0,0 +1,36 @@
#!/bin/sh
set -eu
CONFIG_DIR="${XDG_CONFIG_HOME:-${HOME}/.config}"
CONFIG_FILE="${CONFIG_DIR}/wallpaper_config.json"
if [ ! -e "${CONFIG_FILE}" ]; then
echo "Wallpaper config file: ${CONFIG_FILE} missing." >&2
exit 1
fi
CONFIG="$(cat "${CONFIG_FILE}")"
DIR="$(echo "${CONFIG}" | jq -r '.dir // empty')"
if [ -z "${DIR}" ]; then
DIR="${XDG_PICTURES_DIR:-${HOME}/Pictures}/Wallpapers"
echo "Warning: wallpaper directory not set. using fallback directory ${DIR}" >&2
fi
DIR="$(echo "${DIR}" | envsubst)"
mkdir -p "${DIR}"
random_paper() {
if [ -d "$DIR" ] ; then
find -L "${DIR}"/ -type f -regextype egrep -regex ".*\.(jpe?g|png)$" | shuf -n1 --random-source=/dev/urandom
else
echo "${DIR} is not a directory" >&2
exit 1
fi
}
swww img \
--transition-type any \
--transition-step 2 \
--transition-duration 2 \
"$(random_paper)"

View file

@ -0,0 +1,31 @@
{ lib
, stdenvNoCC
, makeWrapper
, kitty
, rofi-wayland
, ueberzugpp
, ytfzf
,
}:
stdenvNoCC.mkDerivation {
pname = "youtube";
version = "0.1";
src = ./.;
nativeBuildInputs = [ makeWrapper ];
installPhase = ''
runHook preInstall
mkdir -p $out/bin
cp youtube.sh $out/bin/youtube
chmod +x $out/bin/youtube
runHook postInstall
'';
postInstall = ''
wrapProgram $out/bin/youtube --prefix PATH : ${lib.makeBinPath [kitty ytfzf rofi-wayland ueberzugpp]}
'';
}