From 848a1b6ad385c6b63b38b714418a799076f753aa Mon Sep 17 00:00:00 2001 From: caandt Date: Fri, 18 Oct 2024 01:58:59 -0500 Subject: [PATCH] bin --- user/bin.nix | 19 +++++++++++++++++++ user/bin/bell | 7 +++++++ user/bin/nsxiv-rifle | 36 ++++++++++++++++++++++++++++++++++++ user/bin/screenshot | 2 ++ user/home.nix | 4 +--- 5 files changed, 65 insertions(+), 3 deletions(-) create mode 100644 user/bin.nix create mode 100755 user/bin/bell create mode 100755 user/bin/nsxiv-rifle create mode 100755 user/bin/screenshot diff --git a/user/bin.nix b/user/bin.nix new file mode 100644 index 0000000..62c629d --- /dev/null +++ b/user/bin.nix @@ -0,0 +1,19 @@ +{ config, pkgs, homeDirectory, ... }: + +let + deps = { + bell = [ pkgs.pipewire pkgs.libnotify ]; + nsxiv-rifle = [ pkgs.nsxiv ]; + screenshot = [ pkgs.maim pkgs.xclip ]; + }; + mkln = x: config.lib.file.mkOutOfStoreSymlink "${homeDirectory}/.local/nixos/user/bin/${x}"; +in { + home.file = builtins.listToAttrs (map + (x: { + name = ".local/bin/${x}"; + value = { source = mkln x; }; + }) + (builtins.attrNames (builtins.readDir ./bin)) + ); + home.packages = pkgs.lib.lists.flatten (builtins.attrValues deps); +} diff --git a/user/bin/bell b/user/bin/bell new file mode 100755 index 0000000..50c6145 --- /dev/null +++ b/user/bin/bell @@ -0,0 +1,7 @@ +#!/bin/sh +WAV="$XDG_DATA_HOME/bell.wav" +if [ -f $WAV ] && [ $(pgrep pw-play | wc -l) -le 10 ]; then + pw-play --volume 0.5 "$WAV" & +else + notify-send "Bell" +fi diff --git a/user/bin/nsxiv-rifle b/user/bin/nsxiv-rifle new file mode 100755 index 0000000..c161e29 --- /dev/null +++ b/user/bin/nsxiv-rifle @@ -0,0 +1,36 @@ +#!/bin/sh + +TMPDIR="${TMPDIR:-/tmp}" +tmp="$TMPDIR/nsxiv_rifle_$$" + +is_img_extension() { + grep -iE '\.(jpe?g|png|gif|svg|webp|tiff|heif|avif|ico|bmp)$' +} + +listfiles() { + find -L "///${1%/*}" -maxdepth 1 -type f -print | + is_img_extension | sort -V | tee "$tmp" +} + +open_img() { + # only go through listfiles() if the file has a valid img extension + if echo "$1" | is_img_extension >/dev/null 2>&1; then + trap 'rm -f $tmp' EXIT + count="$(listfiles "$1" | grep -nF "$1")" + fi + if [ -n "$count" ]; then + nsxiv -i -n "${count%%:*}" -a -p -- < "$tmp" + else + # fallback incase file didn't have a valid extension, or we couldn't + # find it inside the list + nsxiv -a -p -- "$@" + fi +} + +[ "$1" = '--' ] && shift +case "$1" in + "") echo "Usage: ${0##*/} PICTURES" >&2; exit 1 ;; + /*) open_img "$1" ;; + "~"/*) open_img "$HOME/${1#"~"/}" ;; + *) open_img "$PWD/$1" ;; +esac diff --git a/user/bin/screenshot b/user/bin/screenshot new file mode 100755 index 0000000..98ff888 --- /dev/null +++ b/user/bin/screenshot @@ -0,0 +1,2 @@ +#!/bin/sh +maim -su -f jpg -m 10 | xclip -selection clipboard -t image/png diff --git a/user/home.nix b/user/home.nix index b030290..41db78e 100644 --- a/user/home.nix +++ b/user/home.nix @@ -4,6 +4,7 @@ imports = [ ./xdg.nix ./theme.nix + ./bin.nix ]; home.username = username; @@ -57,9 +58,6 @@ killall file - alsa-utils - libnotify - (python311.withPackages (python-pkgs: [ python-pkgs.pwntools # python-pkgs.angr