From c7e33b61628141fd40700531e1393c8e4731f5fd Mon Sep 17 00:00:00 2001 From: tiyn Date: Mon, 17 Feb 2025 04:19:49 +0100 Subject: [PATCH] scripts: updated to cleaner logic for global variables --- .local/bin/etc/screen_capture/record_replay_start | 6 +++--- .local/bin/etc/screen_capture/record_start | 12 ++++++------ .local/bin/etc/statusbar/disk | 2 +- .local/bin/etc/sxhkd/audio/lmc | 2 +- .local/bin/etc/sxhkd/monitor | 4 ++-- .local/bin/etc/sxhkd/screenshot | 4 ++-- .local/bin/tools/wallpaper | 7 ++----- 7 files changed, 17 insertions(+), 20 deletions(-) diff --git a/.local/bin/etc/screen_capture/record_replay_start b/.local/bin/etc/screen_capture/record_replay_start index 1d45701..c24a1f4 100755 --- a/.local/bin/etc/screen_capture/record_replay_start +++ b/.local/bin/etc/screen_capture/record_replay_start @@ -1,8 +1,8 @@ #!/bin/sh -[ -z "$CAPTURE_INPUT_AUDIO" ] && audio_1="easyeffects_sink.monitor" || audio_1="$CAPTURE_INPUT_AUDIO" -[ -z "$CAPTURE_OUTPUT_AUDIO" ] && audio_2="easyeffects_source" || audio_2="$CAPTURE_OUTPUT_AUDIO" -[ -z "$CAPTURE_DIR" ] && output="$HOME/downloads" || output="$CAPTURE_DIR" +audio_1=${CAPTURE_INPUT_AUDIO:-easyeffects_sink.monitor} +audio_2=${CAPTURE_OUTPUT_AUDIO:-easyeffects_source} +output=${CAPTURE_DIR:-$HOME/downloads} window=$(xdotool getwindowfocus) fps=60 diff --git a/.local/bin/etc/screen_capture/record_start b/.local/bin/etc/screen_capture/record_start index 5dd1190..8bc8e5e 100755 --- a/.local/bin/etc/screen_capture/record_start +++ b/.local/bin/etc/screen_capture/record_start @@ -1,15 +1,15 @@ #!/bin/sh -[ -z "$CAPTURE_INPUT_AUDIO" ] && audio_1="easyeffects_sink.monitor" || audio_1="$CAPTURE_INPUT_AUDIO" -[ -z "$CAPTURE_OUTPUT_AUDIO" ] && audio_2="easyeffects_source" || audio_2="$CAPTURE_OUTPUT_AUDIO" -[ -z "$CAPTURE_DIR" ] && output_dir="$HOME/downloads" || output_dir="$CAPTURE_DIR" +audio_1=${CAPTURE_INPUT_AUDIO:-easyeffects_sink.monitor} +audio_2=${CAPTURE_OUTPUT_AUDIO:-easyeffects_source} +output=${CAPTURE_DIR:-$HOME/downloads} window=$(xdotool getwindowfocus) fps=30 format="mp4" v_codec="h264" -a_codec="opus" -output="$output_dir/recording-$(date '+%Y-%m-%d_%H-%M-%S').$format" +a_codec="aac" +output="$output/recording-$(date '+%Y-%m-%d_%H-%M-%S').$format" -gpu-screen-recorder -w $window -c $format -k $v_codec -ac $a_codec -f $fps -a $audio_1 -a $audio_2 -o $output & +gpu-screen-recorder -w $window -c $format -k $v_codec -ac $a_codec -f $fps -o $output & notify-send -u low 'Screen record' 'Recording started' diff --git a/.local/bin/etc/statusbar/disk b/.local/bin/etc/statusbar/disk index 5352897..56994f7 100755 --- a/.local/bin/etc/statusbar/disk +++ b/.local/bin/etc/statusbar/disk @@ -3,7 +3,7 @@ # Status bar module for disk space # $1 should be drive mountpoint -[ -z "$STATUSBAR_DISK" ] && disk="/home" || disk="$STATUSBAR_DISK" +disk=${STATUSBAR_DISK:-/home} [ ! -z "$1" ] && disk="$1" diff --git a/.local/bin/etc/sxhkd/audio/lmc b/.local/bin/etc/sxhkd/audio/lmc index ca458c8..ba991a2 100755 --- a/.local/bin/etc/sxhkd/audio/lmc +++ b/.local/bin/etc/sxhkd/audio/lmc @@ -4,7 +4,7 @@ # Based on a script by lukesmithxyz, checkout github.com/lukesmithxyz/voidrice # Heavily extended and updated to a pipewire system -[ -z "$LOOPBACK_DEVICE" ] && device="Easy Effects Source" || device="$LOOPBACK_DEVICE" +device=${LOOPBACK_DEVICE:-Easy Effects Source} name=$(wpctl status | sed -n '/Sources/,$p' | sed -n '/Filter/q;p' | grep "$device" | sed -e "s/*/\ /g") id=$( echo $name | cut -d '.' -f 1 | cut -c 5-) diff --git a/.local/bin/etc/sxhkd/monitor b/.local/bin/etc/sxhkd/monitor index 5d036fe..3b09578 100755 --- a/.local/bin/etc/sxhkd/monitor +++ b/.local/bin/etc/sxhkd/monitor @@ -3,8 +3,8 @@ # toggle external monitor # by lukesmithxyz, checkout github.com/lukesmithxyz/voidrice -[ -z "$INTERNAL_MONITOR" ] && intern="LVDS1" || intern="$INTERNAL_MONITOR" -[ -z "$EXTERNAL_MONITOR" ] && extern="HDMI2" || extern="$EXTERNAL_MONITOR" +intern=${INTERNAL_MONITOR:-LVDS1} +extern=${EXTERNAL_MONITOR:-HDMI2} case "$1" in toggle) (xrandr | grep "$extern disconnected") diff --git a/.local/bin/etc/sxhkd/screenshot b/.local/bin/etc/sxhkd/screenshot index 1500adb..fa1930d 100755 --- a/.local/bin/etc/sxhkd/screenshot +++ b/.local/bin/etc/sxhkd/screenshot @@ -3,9 +3,9 @@ # Requires maim. It lets you choose the kind of screenshot to take, # including copying the image or even highlighting an area to copy. -[ -z "$SCREENSHOT_DIR" ] && output_dir="$HOME/downloads" || output_dir="$SCREENSHOT_DIR" +output=${SCREENSHOT_DIR:-$HOME/downloads} -output="$output_dir/screenshot-$(date '+%Y-%m-%d_%H-%M-%S').png" +output="$output/screenshot-$(date '+%Y-%m-%d_%H-%M-%S').png" xclip_img="xclip -sel clip -t image/png" xclip_txt="xclip -sel clip -t text/plain" diff --git a/.local/bin/tools/wallpaper b/.local/bin/tools/wallpaper index 1347de7..0c9357b 100755 --- a/.local/bin/tools/wallpaper +++ b/.local/bin/tools/wallpaper @@ -2,11 +2,8 @@ # Adapted from a script by lukesmithxyz, checkout github.com/lukesmithxyz/voidrice -[ -z "$WALLPAPER_DESKTOP" ] && wall_desk="$XDG_DATA_HOME/bg" || wall_desk="$WALLPAPER_DESKTOP" -[ -z "$WALLPAPER_LOCK" ] && wall_lock="$XDG_DATA_HOME/lock" || wall_lock="$WALLPAPER_LOCK" - -echo $wall_desk -echo $wall_lock +wall_desk=${WALLPAPER_DESKTOP:-$XDG_DATA_HOME/bg} +wall_lock=${WALLPAPER_LOCK:-$XDG_DATA_HOME/lock} case "$1" in desktop) trueloc="$(readlink -f "$2")" &&