diff options
Diffstat (limited to 'modules/scripts')
| -rw-r--r-- | modules/scripts/default.nix | 54 | ||||
| -rw-r--r-- | modules/scripts/file-preview-clean.sh | 2 | ||||
| -rw-r--r-- | modules/scripts/file-preview.sh | 22 | ||||
| -rw-r--r-- | modules/scripts/fzf-launcher.sh | 2 | ||||
| -rw-r--r-- | modules/scripts/screen-recording.sh | 6 | ||||
| -rw-r--r-- | modules/scripts/system-monitor.sh | 24 | ||||
| -rw-r--r-- | modules/scripts/vpn-connect.sh | 13 |
7 files changed, 45 insertions, 78 deletions
diff --git a/modules/scripts/default.nix b/modules/scripts/default.nix index c75d2b2..ac84849 100644 --- a/modules/scripts/default.nix +++ b/modules/scripts/default.nix @@ -34,32 +34,20 @@ let meta.mainProgram = name; }; - # Script definitions: { path, env, deps, condition } + # Script definitions: { path, env?, deps?, conditions? } # condition: attrset of { option (string path), value (expected value) } scriptDefs = { deep-clean = { path = ./deep-clean.sh; - env = { }; - deps = [ ]; - conditions = [ ]; }; file-preview = { path = ./file-preview.sh; - env = { - KITTEN = lib.getExe' config.programs.kitty.package "kitten"; - BAT = lib.getExe config.programs.bat.package; - FILE = lib.getExe pkgs.file; - FFMPEG = lib.getExe' config.programs.ffmpeg.package "ffmpeg"; - FFPROBE = lib.getExe' config.programs.ffmpeg.package "ffprobe"; - OUCH = lib.getExe config.programs.ouch.package; - PDFTOPPM = lib.getExe' pkgs.poppler-utils "pdftoppm"; - }; deps = [ config.programs.kitty.package config.programs.bat.package - pkgs.file config.programs.ffmpeg.package config.programs.ouch.package + pkgs.file pkgs.poppler-utils ]; conditions = [ @@ -84,9 +72,6 @@ let }; file-preview-clean = { path = ./file-preview-clean.sh; - env = { - KITTEN = lib.getExe' config.programs.kitty.package "kitten"; - }; deps = [ config.programs.kitty.package ]; @@ -99,10 +84,6 @@ let }; fzf-launcher = { path = ./fzf-launcher.sh; - env = { - FZF = lib.getExe config.programs.fzf.package; - SETSID = lib.getExe' pkgs.util-linux "setsid"; - }; deps = [ config.programs.fzf.package pkgs.util-linux @@ -116,8 +97,6 @@ let }; i3-keybindings = { path = ./i3-keybindings.sh; - env = { }; - deps = [ ]; conditions = [ { option = "desktop.enable"; @@ -127,10 +106,6 @@ let }; screen-recording = { path = ./screen-recording.sh; - env = { - FFMPEG = lib.getExe config.programs.ffmpeg.package; - SLOP = lib.getExe config.programs.slop.package; - }; deps = [ config.programs.ffmpeg.package config.programs.slop.package @@ -148,12 +123,6 @@ let }; system-monitor = { path = ./system-monitor.sh; - env = { - BTM = lib.getExe config.programs.bottom.package; - NVTOP = lib.getExe config.programs.nvtop.package; - TMUX = lib.getExe config.programs.tmux.package; - KITTY = lib.getExe config.programs.kitty.package; - }; deps = [ config.programs.bottom.package config.programs.nvtop.package @@ -181,11 +150,6 @@ let }; vpn-connect = { path = ./vpn-connect.sh; - env = { - FZF = lib.getExe config.programs.fzf.package; - OPENVPN = lib.getExe config.programs.openvpn.package; - SYSTEMD_RESOLVED = "${config.programs.openvpn.package}/libexec/update-systemd-resolved"; - }; deps = [ config.programs.fzf.package config.programs.openvpn.package @@ -203,8 +167,6 @@ let }; vpn-disconnect = { path = ./vpn-disconnect.sh; - env = { }; - deps = [ ]; conditions = [ { option = "scripts.vpn-connect.enable"; @@ -217,9 +179,9 @@ let # Check whether all conditions for a script are satisfied conditionsMet = name: def: - lib.all ( - cond: lib.attrByPath (lib.splitString "." cond.option) false config == cond.value - ) def.conditions; + lib.all (cond: lib.attrByPath (lib.splitString "." cond.option) false config == cond.value) ( + def.conditions or [ ] + ); in { @@ -243,7 +205,9 @@ in config = { # Wire up .package for each enabled script, with assertions for unmet conditions scripts = lib.mapAttrs (name: def: { - package = lib.mkIf config.scripts.${name}.enable (mkScript name def.path def.env def.deps); + package = lib.mkIf config.scripts.${name}.enable ( + mkScript name def.path (def.env or { }) (def.deps or [ ]) + ); }) scriptDefs; assertions = lib.concatLists ( @@ -254,7 +218,7 @@ in !config.scripts.${name}.enable || lib.attrByPath (lib.splitString "." cond.option) false config == cond.value; message = "scripts.${name} is enabled but requires `${cond.option} = ${builtins.toJSON cond.value}`."; - }) def.conditions + }) (def.conditions or [ ]) ) scriptDefs ); diff --git a/modules/scripts/file-preview-clean.sh b/modules/scripts/file-preview-clean.sh index fdabe2f..ee8ca73 100644 --- a/modules/scripts/file-preview-clean.sh +++ b/modules/scripts/file-preview-clean.sh @@ -1 +1 @@ -exec "$KITTEN" icat --clear --stdin no --transfer-mode file </dev/null >/dev/tty +exec kitten icat --clear --stdin no --transfer-mode file </dev/null >/dev/tty diff --git a/modules/scripts/file-preview.sh b/modules/scripts/file-preview.sh index 71cebd4..b03b995 100644 --- a/modules/scripts/file-preview.sh +++ b/modules/scripts/file-preview.sh @@ -28,7 +28,7 @@ render_image() { tries=$((tries + 1)) done [ ! -s "$file" ] && exit 0 - "$KITTEN" icat --stdin no --transfer-mode file --place "${w}x${h}@${x}x${y}" "$file" </dev/null >/dev/tty + kitten icat --stdin no --transfer-mode file --place "${w}x${h}@${x}x${y}" "$file" </dev/null >/dev/tty exit 1 } @@ -41,7 +41,7 @@ y="$5" # Ensure file exists [ ! -r "$FILE_PATH" ] && exit 0 -MIMETYPE=$("$FILE" --dereference --brief --mime-type "$FILE_PATH") +MIMETYPE=$(file --dereference --brief --mime-type "$FILE_PATH") case "$MIMETYPE" in # --- IMAGES --- image/svg+xml) @@ -65,7 +65,7 @@ case "$MIMETYPE" in if command -v ffmpegthumbnailer >/dev/null; then ffmpegthumbnailer -i "$FILE_PATH" -o "$TMP_IMG" -s 0 -q 5 >/dev/null 2>&1 else - "$FFMPEG" -y -i "$FILE_PATH" -ss 00:00:01 -vframes 1 "$TMP_IMG" >/dev/null 2>&1 + ffmpeg -y -i "$FILE_PATH" -ss 00:00:01 -vframes 1 "$TMP_IMG" >/dev/null 2>&1 fi fi render_image "$TMP_IMG" @@ -75,11 +75,11 @@ case "$MIMETYPE" in audio/*) TMP_IMG="$TMP_DIR/aud-${INODE}.png" if [ ! -f "$TMP_IMG" ]; then - "$FFMPEG" -y -i "$FILE_PATH" \ + ffmpeg -y -i "$FILE_PATH" \ -filter_complex "showwavespic=s=${WIDTH}x${HEIGHT}:colors=white" \ -frames:v 1 "$TMP_IMG" >/dev/null 2>&1 fi - "$FFPROBE" -hide_banner -v quiet -show_format -show_streams "$FILE_PATH" + ffprobe -hide_banner -v quiet -show_format -show_streams "$FILE_PATH" render_image "$TMP_IMG" exit 0 ;; @@ -88,7 +88,7 @@ case "$MIMETYPE" in application/pdf) TMP_IMG="$TMP_DIR/pdf-${INODE}.png" if [ ! -f "$TMP_IMG" ]; then - "$PDFTOPPM" -f 1 -l 1 -png -singlefile \ + pdftoppm -f 1 -l 1 -png -singlefile \ -scale-to $((WIDTH * 8)) \ -r 72 \ "$FILE_PATH" "${TMP_IMG%.png}" >/dev/null 2>&1 @@ -100,7 +100,7 @@ case "$MIMETYPE" in application/epub+zip|application/x-mobipocket-ebook) TMP_IMG="$TMP_DIR/epub-${INODE}.png" if [ ! -f "$TMP_IMG" ]; then - "$OUCH" decompress "$FILE_PATH" --limit "*/cover*.jpg" --dir "$TMP_DIR" >/dev/null 2>&1 + ouch decompress "$FILE_PATH" --limit "*/cover*.jpg" --dir "$TMP_DIR" >/dev/null 2>&1 mv "$TMP_DIR"/cover*.jpg "$TMP_IMG" 2>/dev/null fi [ -s "$TMP_IMG" ] && render_image "$TMP_IMG" @@ -113,7 +113,7 @@ case "$MIMETYPE" in libreoffice --headless --convert-to pdf --outdir "$TMP_DIR" "$FILE_PATH" >/dev/null 2>&1 PDF_VER="${TMP_DIR}/$(basename "${FILE_PATH%.*}").pdf" if [ -f "$PDF_VER" ]; then - "$PDFTOPPM" -f 1 -l 1 -png -singlefile "$PDF_VER" "${TMP_IMG%.png}" >/dev/null 2>&1 + pdftoppm -f 1 -l 1 -png -singlefile "$PDF_VER" "${TMP_IMG%.png}" >/dev/null 2>&1 fi fi render_image "$TMP_IMG" @@ -121,13 +121,13 @@ case "$MIMETYPE" in # --- ARCHIVES --- application/zip|application/x-7z-compressed|application/x-rar|application/x-tar|application/x-gzip) - "$OUCH" list -t "$FILE_PATH" 2>/dev/null + ouch list -t "$FILE_PATH" 2>/dev/null exit 0 ;; # --- TEXT / CODE --- text/*|application/json|application/javascript|application/xml) - "$BAT" --color=always --style=numbers --line-range :200 "$FILE_PATH" 2>/dev/null + bat --color=always --style=numbers --line-range :200 "$FILE_PATH" 2>/dev/null exit 0 ;; @@ -139,7 +139,7 @@ case "$MIMETYPE" in # --- FALLBACK --- *) - "$FILE" --dereference --brief "$FILE_PATH" + file --dereference --brief "$FILE_PATH" echo "------------------------------------------------" hexdump -C "$FILE_PATH" | head -n 100 exit 0 diff --git a/modules/scripts/fzf-launcher.sh b/modules/scripts/fzf-launcher.sh index 5654d80..a1ab292 100644 --- a/modules/scripts/fzf-launcher.sh +++ b/modules/scripts/fzf-launcher.sh @@ -48,7 +48,7 @@ done entries=$(printf '%s' "$entries" | sort -fu -t$'\t' -k1,1) # FZF selection -chosen=$(printf '%s' "$entries" | "$FZF" \ +chosen=$(printf '%s' "$entries" | fzf \ --prompt='Launch: ' \ --layout=reverse \ --info=inline \ diff --git a/modules/scripts/screen-recording.sh b/modules/scripts/screen-recording.sh index 5bd5ee9..c0e8525 100644 --- a/modules/scripts/screen-recording.sh +++ b/modules/scripts/screen-recording.sh @@ -34,10 +34,10 @@ if command -v xwininfo >/dev/null 2>&1; then fi if [ "$SELECT_MODE" = true ]; then - if command -v "$SLOP" >/dev/null 2>&1; then + if command -v slop >/dev/null 2>&1; then echo -e "${YELLOW}Select a window or draw a box...${NC}" # slop output: 123 456 10 20 - read -r W H X Y < <("$SLOP" -f "%w %h %x %y" --nokeyboard) + read -r W H X Y < <(slop -f "%w %h %x %y" --nokeyboard) if [ -n "$W" ]; then WIDTH=$W @@ -67,7 +67,7 @@ echo "File: $FILENAME" echo "------------------------------------------------" # We pass arguments explicitly here to avoid "Unrecognized option" shell errors -"$FFMPEG" -hide_banner \ +ffmpeg -hide_banner \ -f x11grab \ -video_size "${WIDTH}x${HEIGHT}" \ -framerate 30 \ diff --git a/modules/scripts/system-monitor.sh b/modules/scripts/system-monitor.sh index 4fd59ac..cadae3a 100644 --- a/modules/scripts/system-monitor.sh +++ b/modules/scripts/system-monitor.sh @@ -4,26 +4,26 @@ # - Right pane: nvtop (GPU monitor) SESSION="system-monitor" -"$KITTY" @ set-font-size -- -4 +kitty @ set-font-size -- -4 cleanup() { - "$KITTY" @ set-font-size -- +4 + kitty @ set-font-size -- +4 } trap cleanup EXIT INT TERM # Kill any existing session -"$TMUX" kill-session -t "$SESSION" 2>/dev/null +tmux kill-session -t "$SESSION" 2>/dev/null -# Start new "$TMUX" session with $BTM wrapped to kill session on exit -"$TMUX" new-session -d -s "$SESSION" -c "$HOME" "bash -c '\"$BTM\"; \"$TMUX\" kill-session -t $SESSION'" +# Start new tmux session with btm wrapped to kill session on exit +tmux new-session -d -s "$SESSION" -c "$HOME" "bash -c 'btm; tmux kill-session -t $SESSION'" -# Split horizontally: right pane runs $NVTOP wrapped similarly -"$TMUX" split-window -h -t "$SESSION:0" -c "$HOME" "bash -c '\"$NVTOP\"; \"$TMUX\" kill-session -t $SESSION'" +# Split horizontally: right pane runs nvtop wrapped similarly +tmux split-window -h -t "$SESSION:0" -c "$HOME" "bash -c 'nvtop; tmux kill-session -t $SESSION'" -"$TMUX" set -g status off -"$TMUX" set -g mouse on -"$TMUX" set -g focus-events on +tmux set -g status off +tmux set -g mouse on +tmux set -g focus-events on # Select main pane and attach -"$TMUX" select-pane -t "$SESSION:0.0" -"$TMUX" attach-session -t "$SESSION" +tmux select-pane -t "$SESSION:0.0" +tmux attach-session -t "$SESSION" diff --git a/modules/scripts/vpn-connect.sh b/modules/scripts/vpn-connect.sh index 216facc..de4655d 100644 --- a/modules/scripts/vpn-connect.sh +++ b/modules/scripts/vpn-connect.sh @@ -24,10 +24,10 @@ fi # Select if needed if [[ "$REFRESH" == true ]]; then - CRED=$(find "$CREDS_DIR" -type f | "$FZF" --prompt="Select Credentials > ") + CRED=$(find "$CREDS_DIR" -type f | fzf --prompt="Select Credentials > ") [ -z "$CRED" ] && exit 1 - SERVER=$(find "$SERVERS_DIR" -type f \( -name "*.conf" -o -name "*.ovpn" \) | "$FZF" --prompt="Select VPN Server > ") + SERVER=$(find "$SERVERS_DIR" -type f \( -name "*.conf" -o -name "*.ovpn" \) | fzf --prompt="Select VPN Server > ") [ -z "$SERVER" ] && exit 1 echo "CRED=\"$CRED\"" > "$CACHE_FILE" @@ -44,12 +44,15 @@ sed -e '/up \/etc\/openvpn\/update-resolv-conf/d' \ # Run in background sudo -v || exit 1 -nohup sudo "$OPENVPN" \ +OPENVPNBinary=$(command -v openvpn) +SYSTEMD_RESOLVED_PATH="${OPENVPNBinary%/openvpn}/libexec/update-systemd-resolved" + +nohup sudo openvpn \ --config "$TMP_CONF" \ --auth-user-pass "$CRED" \ --script-security 2 \ - --up "$SYSTEMD_RESOLVED" \ - --down "$SYSTEMD_RESOLVED" \ + --up "$SYSTEMD_RESOLVED_PATH" \ + --down "$SYSTEMD_RESOLVED_PATH" \ --down-pre \ > "$LOG_FILE" 2>&1 & |
