chore: refactor user modules

This commit is contained in:
2025-07-27 22:50:25 +02:00
parent af1a606c1a
commit d200079cdb
94 changed files with 832 additions and 665 deletions

View File

@@ -0,0 +1,3 @@
{pkgs, ...}:
pkgs.writeShellScriptBin "askpass" ''
${pkgs.wofi}/bin/wofi -d -P -L 1 -p "$(printf $1 | sed s/://)"''

View File

@@ -0,0 +1,3 @@
{pkgs, ...}:
pkgs.writeShellScriptBin "backup" ''
cp -r "$1" "$1.bak.$(date +%Y%m%d%H%M%S)"''

View File

@@ -0,0 +1,15 @@
{
pkgs,
lib,
config,
...
}:
with lib; let
cfg = config.home.cli.scripts;
files = filesystem.listFilesRecursive ./.;
scriptFiles = builtins.filter (path: baseNameOf path != "default.nix") files;
scripts = map (file: (import file {inherit pkgs config;})) scriptFiles;
in {
options.home.cli.scripts.enable = mkEnableOption "Add custom scripts to PATH";
config.home.packages = mkIf cfg.enable scripts;
}

View File

@@ -0,0 +1,3 @@
{pkgs, ...}:
pkgs.writeShellScriptBin "keygen"
"tr -cd '[:alnum:]' < /dev/urandom | fold -w 64 | head -n 1 | tr -d '\n'"

View File

@@ -0,0 +1,10 @@
{
pkgs,
config,
...
}:
pkgs.writeShellScriptBin "launch-with-emacsclient" ''
filename="$1"
line="$2"
column="$3"
${config.home.dev.editors.emacs.package}/bin/emacsclient +$line:$column "$filename"''

View File

@@ -0,0 +1,3 @@
{pkgs, ...}:
pkgs.writeShellScriptBin "mp42webm" ''
${pkgs.ffmpeg}/bin/ffmpeg -i "$1" -c:v libvpx -crf 10 -b:v 1M -c:a libvorbis "$1".webm''

View File

@@ -0,0 +1,16 @@
{pkgs, ...}:
pkgs.writeShellScriptBin "plock" ''
TMPBG="/tmp/screen.png"
if [ "$XDG_SESSION_TYPE" = "wayland" ]; then
SCREENER=${pkgs.grim}/bin/grim
LOCKER="${pkgs.swaylock}/bin/swaylock -feF"
else
SCREENER=${pkgs.scrot}/bin/scrot
LOCKER="${pkgs.i3lock}/bin/i3lock -ef"
fi
$SCREENER "$TMPBG"
${pkgs.corrupter}/bin/corrupter -add 0 "$TMPBG" "$TMPBG"
$LOCKER -ti "$TMPBG"
rm "$TMPBG"
''

View File

@@ -0,0 +1,18 @@
{pkgs, ...}:
pkgs.writeShellScriptBin "rofi-emoji" ''
SELECTED_EMOJI=$(grep -v "#" ~/.config/emoji | ${pkgs.wofi}/bin/wofi --dmenu -p "Select emoji" -i | awk '{print $1}' | tr -d '\n')
if [ "$XDG_SESSION_TYPE" = "wayland" ]; then
printf "%s" "$SELECTED_EMOJI" | ${pkgs.wl-clipboard-rs}/bin/wl-copy
else
printf "%s" "$SELECTED_EMOJI" | ${pkgs.xclip}/bin/xclip -sel clip
fi
if [ "$XDG_SESSION_TYPE" = "wayland" ]
then EMOJI=$(${pkgs.wl-clipboard-rs}/bin/wl-paste)
else EMOJI=$(${pkgs.xclip}/bin/xclip -o)
fi
test -z "$EMOJI" && notify-send "No emoji copied" -u low && exit
EMOJI="$EMOJI copied to clipboard"
${pkgs.libnotify}/bin/notify-send -u low "$EMOJI"
''

View File

@@ -0,0 +1,56 @@
{pkgs, ...}:
pkgs.writeShellScriptBin "screenshot" ''
OUTFILE_BASE="$HOME/Pictures/Screenshots/Screenshot_$(date +%Y-%m-%d_%H.%M.%S)"
OUTFILE="$OUTFILE_BASE.png"
SUFFIX=0
while getopts ':cd:egs' OPTION; do
case "$OPTION" in
c )
COPY="yes"
;;
d )
DELAY="$OPTARG"
;;
e )
EDIT="yes"
;;
g )
GIMP="yes"
;;
s )
SELECT="yes"
;;
? )
echo "Usage: $(basename "$0") [-c] [-d DELAY] [-e] [-g] [-s]"
exit 1
;;
esac
done
if [ "$SELECT" = "yes" ]; then
AREA="$(${pkgs.slurp}/bin/slurp)"
fi
if [ -n "$DELAY" ]; then
sleep "$DELAY"
fi
if [ "$SELECT" = "yes" ]; then
${pkgs.grim}/bin/grim -g "$AREA" "$OUTFILE"
else
${pkgs.grim}/bin/grim "$OUTFILE"
fi
if [ "$EDIT" = "yes" ];then
${pkgs.swappy}/bin/swappy -f "$OUTFILE" -o "$OUTFILE"
fi
if [ "$GIMP" = "yes" ]; then
${pkgs.gimp}/bin/gimp "$OUTFILE"
fi
if [ "$COPY" = "yes" ]; then
${pkgs.wl-clipboard-rs}/bin/wl-copy < "$OUTFILE"
fi
''

View File

@@ -0,0 +1,3 @@
{pkgs, ...}:
pkgs.writeShellScriptBin "sshbind" ''
ssh -L "$1:$3:$1" "$2" -N''

View File

@@ -0,0 +1,16 @@
{pkgs, ...}:
pkgs.writeShellScriptBin "ytplay" ''
URL=$(${pkgs.wofi}/bin/wofi --dmenu -i -p "Video URL")
if [ -z "$URL" ]; then
echo "You need to provide a URL"
exit 1
fi
RESOLUTION_CHOICE=$(${pkgs.yt-dlp}/bin/yt-dlp --list-formats "$URL" | \
grep -E "webm.*[0-9]+x[0-9]" | \
awk '{print $3 " " $1}' | \
sort -gu | \
${pkgs.wofi}/bin/wofi --dmenu -i -p "Resolution")
mapfile -t RESOLUTION <<< "$RESOLUTION_CHOICE"
RESOLUTION_CODE=''${RESOLUTION[0]}
${pkgs.mpv}/bin/mpv --ytdl-format="''${RESOLUTION_CODE}+bestaudio/best" "$URL"
''