Major rewrite: switching back to Arch from NixOS

This commit is contained in:
ItsDrike 2024-10-02 14:37:28 +02:00
parent df585b737b
commit 254181c0fc
Signed by: ItsDrike
GPG key ID: FA2745890B7048C0
121 changed files with 5433 additions and 2371 deletions

View file

@ -0,0 +1,57 @@
#!/usr/bin/env bash
# Source: https://gist.github.com/schacon/e9e743dee2e92db9a464619b99e94eff
# Colors
RED='\033[0;31m'
GREEN='\033[0;32m'
NO_COLOR='\033[0m'
BLUE='\033[0;34m'
YELLOW='\033[0;33m'
NO_COLOR='\033[0m'
width1=5
width2=6
width3=30
width4=20
width5=20
# Function to count commits
count_commits() {
local branch="$1"
local base_branch="$2"
local ahead_behind
ahead_behind=$(git rev-list --left-right --count "$base_branch"..."$branch")
echo "$ahead_behind"
}
# Main script
main_branch=$(git rev-parse HEAD)
printf "${GREEN}%-${width1}s ${RED}%-${width2}s ${BLUE}%-${width3}s ${YELLOW}%-${width4}s ${NO_COLOR}%-${width5}s\n" "Ahead" "Behind" "Branch" "Last Commit" " "
# Separator line for clarity
printf "${GREEN}%-${width1}s ${RED}%-${width2}s ${BLUE}%-${width3}s ${YELLOW}%-${width4}s ${NO_COLOR}%-${width5}s\n" "-----" "------" "------------------------------" "-------------------" " "
format_string="%(objectname:short)@%(refname:short)@%(committerdate:relative)"
IFS=$'\n'
for branchdata in $(git for-each-ref --sort=-authordate --format="$format_string" refs/heads/ --no-merged); do
sha=$(echo "$branchdata" | cut -d '@' -f1)
branch=$(echo "$branchdata" | cut -d '@' -f2)
time=$(echo "$branchdata" | cut -d '@' -f3)
if [ "$branch" != "$main_branch" ]; then
# Get branch description
description=$(git config branch."$branch".description)
# Count commits ahead and behind
ahead_behind=$(count_commits "$sha" "$main_branch")
ahead=$(echo "$ahead_behind" | cut -f2)
behind=$(echo "$ahead_behind" | cut -f1)
# Display branch info
# shellcheck disable=SC2086
printf "${GREEN}%-${width1}s ${RED}%-${width2}s ${BLUE}%-${width3}s ${YELLOW}%-${width4}s ${NO_COLOR}%-${width5}s\n" $ahead $behind $branch "$time" "$description"
fi
done

View file

@ -0,0 +1,36 @@
#!/bin/sh
RESIZE_SIZE=${1:?Missing resize size}
RESIZE_PARAMS_X=0
RESIZE_PARAMS_Y=0
DIRECTION=${2:?Missing move direction}
case $DIRECTION in
l)
RESIZE_PARAMS_X=-$RESIZE_SIZE
;;
r)
RESIZE_PARAMS_X=$RESIZE_SIZE
;;
u)
RESIZE_PARAMS_Y=-$RESIZE_SIZE
;;
d)
RESIZE_PARAMS_Y=$RESIZE_SIZE
;;
*)
echo "kbye"
return 1
;;
esac
ACTIVE_WINDOW=$(hyprctl activewindow -j)
IS_FLOATING=$(echo "$ACTIVE_WINDOW" | jq .floating)
if [ "$IS_FLOATING" = "true" ]; then
hyprctl dispatch moveactive "$RESIZE_PARAMS_X" "$RESIZE_PARAMS_Y"
else
hyprctl dispatch movewindow "$DIRECTION"
fi

View file

@ -0,0 +1,216 @@
#!/bin/sh
# Inspired by grimblast (https://github.com/hyprwm/contrib/blob/main/grimblast/grimblast)
# Helper functions
die() {
MSG="${1}"
ERR_CODE="${2:-1}"
URGENCY="${3:-critical}"
>&2 echo "$MSG"
if [ "$NOTIFY" = "yes" ]; then
notify-send -a screenshot -u "$URGENCY" "Error ($ERR_CODE)" "$MSG"
fi
exit "$ERR_CODE"
}
# Argument parsing
SAVE_METHOD=
SAVE_FILE=
TARGET=
NOTIFY=no
CURSOR=no
EDIT=no
DELAY=0
while [ "${1-}" ]; do
case "$1" in
-h | --help)
>&2 cat <<EOF
screenshot taking utility script, allowing for easy all-in-one solution for
controlling how a screenshot should be taken.
Methods (one is required):
--copy: Copy the screenshot data into the clipboard
--save [FILE]: Save the screenshot data into a file
--copysave [FILE]: Both save to clipboard and to file
General options:
--notify: Send a notification that the screenshot was saved
--cursor: Capture cursor in the screenshot
--edit: Once the screenshot is taken, edit it first with swappy
--delay [MILISECONDS]: Wait for given time until the screenshot is taken
--target [TARGET]: (REQUIRED) What should be captured
Variables:
FILE: A path to a .png image file for output, or '-' to pipe to STDOUT
MILISECONDS: Number of miliseconds; Must be a whole, non-negative number!
TARGET: Area on screen; can be one of:
- activewin: Currently active window
- window: Manually select a window
- activemon: Currently active monitor (output)
- monitor: Manually select a monitor
- all: Everything (all visible monitors/outputs)
- area: Manually select a region
EOF
exit 0
;;
--notify)
NOTIFY=yes
shift
;;
--cursor)
CURSOR=yes
shift
;;
--edit)
EDIT=yes
shift
;;
--target)
if [ -z "$TARGET" ]; then
case "$2" in
activewin | window | activemon | monitor | all | area)
TARGET="$2"
shift 2
;;
*)
die "Invalid target (see TARGET variable in --help)"
;;
esac
else
die "Only one target can be passed."
fi
;;
--delay)
case "$2" in
'' | *[!0-9]*)
die "Argument after --delay must be an amount of MILISECONDS"
;;
*)
DELAY="$2"
shift 2
;;
esac
;;
--copy)
if [ -z "$SAVE_METHOD" ]; then
SAVE_METHOD="copy"
shift
else
die "Only one method can be passed."
fi
;;
--save)
if [ -z "$SAVE_METHOD" ]; then
SAVE_METHOD="save"
SAVE_FILE="$2"
shift 2
else
die "Only one method can be passed."
fi
;;
--copysave)
if [ -z "$SAVE_METHOD" ]; then
SAVE_METHOD="copysave"
SAVE_FILE="$2"
shift 2
else
die "Only one method can be passed."
fi
;;
*)
die "Unrecognized argument: $1"
;;
esac
done
# Screenshot functions
takeScreenshot() {
FILE="$1"
GEOM="$2"
ARGS=()
[ "$CURSOR" = "yes" ] && ARGS+=("-c")
[ -n "$GEOM" ] && ARGS+=("-g" "$GEOM")
ARGS+=("$FILE")
sleep "$DELAY"e-3
grim "${ARGS[@]}" || die "Unable to invoke grim"
}
takeEditedScreenshot() {
FILE="$1"
GEOM="$2"
if [ "$EDIT" = "yes" ]; then
takeScreenshot - "$GEOM" | swappy -f - -o "$FILE" || die "Unable to invoke swappy"
else
takeScreenshot "$FILE" "$GEOM"
fi
}
# Obtain the geometry for screenshot to be taken at
if [ "$TARGET" = "area" ]; then
GEOM="$(slurp -d)"
if [ -z "$GEOM" ]; then
die "No area selected" 2 normal
fi
WHAT="Area"
elif [ "$TARGET" = "all" ]; then
GEOM=""
WHAT="Screen"
elif [ "$TARGET" = "activewin" ]; then
FOCUSED="$(hyprctl activewindow -j)"
GEOM="$(echo "$FOCUSED" | jq -r '"\(.at[0]),\(.at[1]) \(.size[0])x\(.size[1])"')"
APP_ID="$(echo "$FOCUSED" | jq -r '.class')"
WHAT="$APP_ID window"
elif [ "$TARGET" = "window" ]; then
WORKSPACES="$(hyprctl monitors -j | jq -r 'map(.activeWorkspace.id)')"
WINDOWS="$(hyprctl clients -j | jq -r --argjson workspaces "$WORKSPACES" 'map(select([.workspace.id] | inside($workspaces)))')"
GEOM=$(echo "$WINDOWS" | jq -r '.[] | "\(.at[0]),\(.at[1]) \(.size[0])x\(.size[1])"' | slurp -r)
if [ -z "$GEOM" ]; then
die "No window selected" 2 normal
fi
WHAT="Window"
elif [ "$TARGET" = "activemon" ]; then
ACTIVEMON="$(hyprctl monitors -j | jq -r '.[] | select(.focused == true)')"
GEOM="$(echo "$ACTIVEMON" | jq -r '"\(.x),\(.y) \(.width)x\(.height)"')"
WHAT="$(echo "$ACTIVEMON" | jq -r '.name')"
elif [ "$TARGET" = "monitor" ]; then
GEOM="$(slurp -o)"
if [ -z "$GEOM" ]; then
die "No monitor selected" 2 normal
fi
WHAT="Monitor"
else
if [ -z "$TARGET" ]; then
die "No target specified!"
else
die "Unknown target: $SAVE_METHOD"
fi
fi
# Invoke grim and capture the screenshot
if [ "$SAVE_METHOD" = "save" ]; then
takeEditedScreenshot "$SAVE_FILE" "$GEOM"
[ "$NOTIFY" = "yes" ] && notify-send -a screenshot "Success" "$WHAT screenshot saved" -i "$(realpath "$SAVE_FILE")"
elif [ "$SAVE_METHOD" = "copy" ]; then
TEMP_FILE="$(mktemp --suffix=.png)"
takeEditedScreenshot "-" "$GEOM" | tee "$TEMP_FILE" | wl-copy --type image/png || die "Clipboard error"
[ "$NOTIFY" = "yes" ] && notify-send -a screenshot "Success" "$WHAT screenshot copied" -i "$(realpath "$TEMP_FILE")" && rm "$TEMP_FILE"
elif [ "$SAVE_METHOD" = "copysave" ]; then
takeEditedScreenshot "-" "$GEOM" | tee "$SAVE_FILE" | wl-copy --type image/png || die "Clipboard error"
[ "$NOTIFY" = "yes" ] && notify-send -a screenshot "Success" "$WHAT screenshot copied and saved" -i "$(realpath "$SAVE_FILE")"
else
if [ -z "$SAVE_METHOD" ]; then
die "No save method specified!"
else
die "Unknown save method: $SAVE_METHOD"
fi
fi

View file

@ -1,17 +0,0 @@
#!/bin/sh
# export LIBVA_DRIVER_NAME=nvidia
# export XDG_SESSION_TYPE=wayland
# export __GLX_VENDOR_LIBRARY_NAME=nvidia
# export WLR_NO_HARDWARE_CURSORS=1
# export GBM_BACKEND=nvidia-drm # can cause issues
HYPRLAND_LOG="${XDG_CACHE_HOME:-$HOME/.cache}/hyprlog.txt"
echo "---------- NEW RUN $(date) ----------" >> "$HYPRLAND_LOG"
Hyprland 2>&1 | awk '{ print strftime("%s: "), $0, fflush(); }' | tee -a "$HYPRLAND_LOG"
echo "---------- ENDED $(date) ----------" >> "$HYPRLAND_LOG"
if systemctl --user is-active wayland-session.target &>/dev/null; then
systemctl --user stop wayland-session.target
fi

View file

@ -1,226 +0,0 @@
#!/bin/bash
# Inspired by grimblast (https://github.com/hyprwm/contrib/blob/main/grimblast/grimblast)
# Requirements:
# - `grim`: screenshot utility for wayland
# - `slurp`: to select an area
# - `hyprctl`: to read properties of current window
# - `wl-copy`: clipboard utility
# - `jq`: json utility to parse hyprctl output
# - `notify-send`: to show notifications
# - `swappy`: for editing the screenshots (only required for --edit)
# Helper functions
die() {
MSG="${1}"
ERR_CODE="${2:-1}"
URGENCY="${3:-critical}"
>&2 echo "$MSG"
if [ "$NOTIFY" = "yes" ]; then
notify-send -a screenshot -u "$URGENCY" "Error ($ERR_CODE)" "$MSG"
fi
exit "$ERR_CODE"
}
# Argument parsing
SAVE_METHOD=
SAVE_FILE=
TARGET=
NOTIFY=no
CURSOR=no
EDIT=no
DELAY=0
while [ "$1" ]; do
case "$1" in
-h | --help)
>&2 cat << EOF
screenshot taking utility script, allowing for easy all-in-one solution for
controlling how a screenshot should be taken.
Methods (one is required):
--copy: Copy the screenshot data into the clipboard
--save [FILE]: Save the screenshot data into a file
--copysave [FILE]: Both save to clipboard and to file
General options:
--notify: Send a notification that the screenshot was saved
--cursor: Capture cursor in the screenshot
--edit: Once the screenshot is taken, edit it first with swappy
--delay [MILISECONDS]: Wait for given time until the screenshot is taken
--target [TARGET]: (REQUIRED) What should be captured
Variables:
FILE: A path to a .png image file for output, or '-' to pipe to STDOUT
MILISECONDS: Number of miliseconds; Must be a whole, non-negative number!
TARGET: Area on screen; can be one of:
- activewin: Currently active window
- window: Manually select a window
- activemon: Currently active monitor (output)
- monitor: Manually select a monitor
- all: Everything (all visible monitors/outputs)
- area: Manually select a region
EOF
exit 0
;;
--notify)
NOTIFY=yes
shift
;;
--cursor)
CURSOR=yes
shift
;;
--edit)
EDIT=yes
shift
;;
--target)
if [ -z "$TARGET" ]; then
case "$2" in
activewin|window|activemon|monitor|all|area)
TARGET="$2"
shift 2
;;
*)
die "Invalid target (see TARGET variable in --help)"
;;
esac
else
die "Only one target can be passed."
fi
;;
--delay)
case "$2" in
''|*[!0-9]*)
die "Argument after --delay must be an amount of MILISECONDS"
;;
*)
DELAY="$2"
shift 2
;;
esac
;;
--copy)
if [ -z "$SAVE_METHOD" ]; then
SAVE_METHOD="copy"
shift
else
die "Only one method can be passed."
fi
;;
--save)
if [ -z "$SAVE_METHOD" ]; then
SAVE_METHOD="save"
SAVE_FILE="$2"
shift 2
else
die "Only one method can be passed."
fi
;;
--copysave)
if [ -z "$SAVE_METHOD" ]; then
SAVE_METHOD="copysave"
SAVE_FILE="$2"
shift 2
else
die "Only one method can be passed."
fi
;;
*)
die "Unrecognized argument: $1"
;;
esac
done
# Screenshot functions
takeScreenshot() {
FILE="$1"
GEOM="$2"
ARGS=()
[ "$CURSOR" = "yes" ] && ARGS+=("-c")
[ -n "$GEOM" ] && ARGS+=("-g" "$GEOM")
ARGS+=("$FILE")
sleep "$DELAY"e-3
grim "${ARGS[@]}" || die "Unable to invoke grim"
}
takeEditedScreenshot() {
FILE="$1"
GEOM="$2"
if [ "$EDIT" = "yes" ]; then
takeScreenshot - "$GEOM" | swappy -f - -o "$FILE" || die "Unable to invoke swappy"
else
takeScreenshot "$FILE" "$GEOM"
fi
}
# Obtain the geometry for screenshot to be taken at
if [ "$TARGET" = "area" ]; then
GEOM="$(slurp -d)"
if [ -z "$GEOM" ]; then
die "No area selected" 2 normal
fi
WHAT="Area"
elif [ "$TARGET" = "all" ]; then
GEOM=""
WHAT="Screen"
elif [ "$TARGET" = "activewin" ]; then
FOCUSED="$(hyprctl activewindow -j)"
GEOM="$(echo "$FOCUSED" | jq -r '"\(.at[0]),\(.at[1]) \(.size[0])x\(.size[1])"')"
APP_ID="$(echo "$FOCUSED" | jq -r '.class')"
WHAT="$APP_ID window"
elif [ "$TARGET" = "window" ]; then
WORKSPACES="$(hyprctl monitors -j | jq -r 'map(.activeWorkspace.id)')"
WINDOWS="$(hyprctl clients -j | jq -r --argjson workspaces "$WORKSPACES" 'map(select([.workspace.id] | inside($workspaces)))' )"
GEOM=$(echo "$WINDOWS" | jq -r '.[] | "\(.at[0]),\(.at[1]) \(.size[0])x\(.size[1])"' | slurp -r)
if [ -z "$GEOM" ]; then
die "No window selected" 2 normal
fi
WHAT="Window"
elif [ "$TARGET" = "activemon" ]; then
ACTIVEMON="$(hyprctl monitors -j | jq -r '.[] | select(.focused == true)')"
GEOM="$(echo "$ACTIVEMON" | jq -r '"\(.x),\(.y) \(.width)x\(.height)"')"
WHAT="$(echo "$ACTIVEMON" | jq -r '.name')"
elif [ "$TARGET" = "monitor" ]; then
GEOM="$(slurp -o)"
if [ -z "$GEOM" ]; then
die "No monitor selected" 2 normal
fi
WHAT="Monitor"
else
if [ -z "$TARGET" ]; then
die "No target specified!"
else
die "Unknown target: $SAVE_METHOD"
fi
fi
# Invoke grim and capture the screenshot
if [ "$SAVE_METHOD" = "save" ]; then
takeEditedScreenshot "$SAVE_FILE" "$GEOM"
notify-send -a screenshot "Success" "$WHAT screenshot saved" -i "$(realpath "$SAVE_FILE")"
elif [ "$SAVE_METHOD" = "copy" ]; then
TEMP_FILE="$(mktemp --suffix=.png)"
takeEditedScreenshot "-" "$GEOM" | tee "$TEMP_FILE" | wl-copy --type image/png || die "Clipboard error"
notify-send -a screenshot "Success" "$WHAT screenshot copied" -i "$(realpath "$TEMP_FILE")" && rm "$TEMP_FILE"
elif [ "$SAVE_METHOD" = "copysave" ]; then
takeEditedScreenshot "-" "$GEOM" | tee "$SAVE_FILE" | wl-copy --type image/png || die "Clipboard error"
notify-send -a screenshot "Success" "$WHAT screenshot copied and saved" -i "$(realpath "$SAVE_FILE")"
else
if [ -z "$SAVE_METHOD" ]; then
die "No save method specified!"
else
die "Unknown save method: $SAVE_METHOD"
fi
fi

View file

@ -1,22 +0,0 @@
#!/bin/bash
WORKSPACE="$1"
monitors_out="$(hyprctl monitors -j)"
focused_mon="$(echo "$monitors_out" | jq '.[] | select(.focused==true) | .id')"
focused_wks="$(echo "$monitors_out" | jq '.[].activeWorkspace.id')"
# Workspace is already focused, check on which monitor
if echo "$focused_wks" | grep "$WORKSPACE" >/dev/null; then
mon_id="$(echo "$monitors_out" | jq ".[] | select(.activeWorkspace.id==$WORKSPACE) | .id")"
# If the workspace is focused on the active monitor, don't do anything (we're here).
# Otherwise, swap the workspaces.
if [ "$mon_id" -ne "$focused_mon" ]; then
hyprctl dispatch swapactiveworkspaces "$focused_mon" "$mon_id"
fi
# Switching to an unfocused workspace, always move it to focused monitor
else
hyprctl dispatch moveworkspacetomonitor "$WORKSPACE" "$focused_mon"
hyprctl dispatch workspace "$WORKSPACE"
fi

View file

@ -0,0 +1,22 @@
#!/usr/bin/env bash
#ACTIVE_BORDER_COLOR="0xFF327BD1"
ACTIVE_BORDER_COLOR="0xFFFF6600"
DEFAULT_BORDER_COLOR="0xFFFFA500"
hyprctl dispatch fullscreenstate -1 2
fullscreen_status="$(hyprctl activewindow -j | jq '.fullscreenClient')"
if [ "$fullscreen_status" = "null" ]; then
echo "Update your hyprland, 'fakeFullscreen' window property not found."
exit 1
elif [ "$fullscreen_status" = "2" ]; then
window_address="$(hyprctl activewindow -j | jq -r '.address')"
hyprctl setprop "address:$window_address" activebordercolor "$ACTIVE_BORDER_COLOR" lock
elif [ "$fullscreen_status" = "0" ]; then
window_address="$(hyprctl activewindow -j | jq -r '.address')"
hyprctl setprop "address:$window_address" activebordercolor "$DEFAULT_BORDER_COLOR"
else
echo "Unexpected output from 'fullscreenClient' window property: $fullscreen_status"
exit 1
fi

View file

@ -1,22 +0,0 @@
#!/bin/bash
#ACTIVE_BORDER_COLOR="0xFF327BD1"
ACTIVE_BORDER_COLOR="0xFFFF6600"
DEFAULT_BORDER_COLOR="0xFFFFA500"
hyprctl dispatch fakefullscreen ""
fullscreen_status="$(hyprctl activewindow -j | jq '.fakeFullscreen')"
if [ "$fullscreen_status" = "null" ]; then
echo "Update your hyprland, 'fakeFullscreen' window property not found."
exit 1
elif [ "$fullscreen_status" = "true" ]; then
window_address="$(hyprctl activewindow -j | jq -r '.address')"
hyprctl setprop "address:$window_address" activebordercolor "$ACTIVE_BORDER_COLOR" lock
elif [ "$fullscreen_status" = "false" ]; then
window_address="$(hyprctl activewindow -j | jq -r '.address')"
hyprctl setprop "address:$window_address" activebordercolor "$DEFAULT_BORDER_COLOR"
else
echo "Unexpected output from 'fakeFullscreen' window property: $fullscreen_status"
exit 1
fi

View file

@ -1,4 +1,4 @@
#!/bin/bash
#!/usr/bin/env bash
set -euo pipefail
idleprog="hypridle" # or swayidle

View file

@ -1,10 +1,10 @@
#!/bin/sh
if [ "$(dunstctl is-paused)" = "false" ]; then
notify-send "Notifications" "Pausing notifications..." -h string:x-canonical-private-synchronous:notif-pause
sleep 2
dunstctl set-paused true
notify-send "Notifications" "Pausing notifications..." -h string:x-canonical-private-synchronous:notif-pause
sleep 2
dunstctl set-paused true
else
dunstctl set-paused false
notify-send "Notifications" "Notifications enabled" -h string:x-canonical-private-synchronous:notif-pause
dunstctl set-paused false
notify-send "Notifications" "Notifications enabled" -h string:x-canonical-private-synchronous:notif-pause
fi

View file

@ -0,0 +1,19 @@
#!/bin/bash
set -euo pipefail
id=$(tr -dc 'a-zA-Z0-9' </dev/urandom | fold -w 6 | head -n 1 || true)
echo "Image ID: $id"
echo "Taking screenshot..."
grim -g "$(slurp -w 0)" /tmp/ocr-"$id".png
echo "Running OCR..."
tesseract /tmp/ocr-"$id".png - | wl-copy
echo -en "File saved to /tmp/ocr-'$id'.png\n"
echo "Sending notification..."
notify-send "OCR " "Text copied!"
echo "Cleaning up..."
rm /tmp/ocr-"$id".png -vf

View file

@ -4,54 +4,56 @@ EXTENSION="mp4"
NOTIFY=0
save_file() {
wl-copy -t text/uri-list "file://${file}"
[ "$NOTIFY" -eq 1 ] && notify-send -a "quick-record" "Recording saved" "$file <file://${file}>"
echo "Recording saved: $file"
wl-copy -t text/uri-list "file://${file}"
[ "$NOTIFY" -eq 1 ] && notify-send -a "quick-record" "Recording saved" "$file <file://${file}>"
echo "Recording saved: $file"
}
stop_recording() {
if pidof -s wf-recorder >/dev/null 2>&1; then
[ "$NOTIFY" -eq 1 ] && notify-send -a "quick-record" "Recording stopped"
killall -s SIGINT wf-recorder
else
>&2 echo "No active recording to stop"
return 1
fi
if pidof -s wf-recorder >/dev/null 2>&1; then
[ "$NOTIFY" -eq 1 ] && notify-send -a "quick-record" "Recording stopped"
killall -s SIGINT wf-recorder
else
>&2 echo "No active recording to stop"
return 1
fi
}
start_recording() {
# Remove all previous recordings
# No need to clutter /tmp, since this is used for copying the recording
# as a file, it's unlikely that we'll need any of the old recordings
# when a new one is requested
rm ${TMPDIR:-/tmp}/wf-recorder-video-*.$EXTENSION
# Remove all previous recordings
# No need to clutter /tmp, since this is used for copying the recording
# as a file, it's unlikely that we'll need any of the old recordings
# when a new one is requested
rm "${TMPDIR:-/tmp}"/wf-recorder-video-*."$EXTENSION" 2>/dev/null || true
file="$(mktemp -t wf-recorder-video-XXXXX.$EXTENSION)"
geom="$(slurp)"
file="$(mktemp -t "wf-recorder-video-XXXXX.$EXTENSION")"
geom="$(slurp)"
[ "$NOTIFY" -eq 1 ] && notify-send "quick-record" "Recording starting"
[ "$NOTIFY" -eq 1 ] && notify-send "quick-record" "Recording starting"
trap save_file SIGINT
trap save_file SIGTERM
trap save_file SIGHUP
trap save_file SIGINT
trap save_file SIGTERM
trap save_file SIGHUP
# Wee need 'y' stdin to confirm that we want to override the file
# since mktemp creates a blank file there already
echo "y" | wf-recorder -g "$geom" -f "$file"
# Wee need 'y' stdin to confirm that we want to override the file
# since mktemp creates a blank file there already
# TODO: The -x 420p is a temporary fix to address the recordings appearing
# corrupted in firefox/discord/... See: <https://github.com/ammen99/wf-recorder/issues/218>
echo "y" | wf-recorder -g "$geom" -f "$file" -x yuv420p
# If wf-recorder process ends directly, rather than a trap being hit
# we also want to run the save_file func
save_file
# If wf-recorder process ends directly, rather than a trap being hit
# we also want to run the save_file func
save_file
}
# Parse any CLI flags first, before getting to positional args
# (As long as we have $2, meaning there's at least 2 args, treat
# $1 arg as CLI flag``)
while [ "$2" ]; do
case "$1" in
-h | --help)
cat << EOF
while [ "${2-}" ]; do
case "$1" in
-h | --help)
cat <<EOF
quick-record is a simple tool for performing quick screen capture recordings
on wayland WMs easily, using wf-recorder.
@ -65,26 +67,32 @@ Required positional arguments:
- stop: Stop any already running recording(s)
- toggle: If there is a running recording, stop it, otherwise start a new one
EOF
exit 0
;;
-n | --notify) NOTIFY=1; shift ;;
-e | --extension) EXTENSION="$2"; shift; shift ;;
esac
exit 0
;;
-n | --notify)
NOTIFY=1
shift
;;
-e | --extension)
EXTENSION="$2"
shift
shift
;;
esac
done
if [ "$1" = "start" ]; then
if [ "${1-}" = "start" ]; then
start_recording
elif [ "${1-}" = "stop" ]; then
stop_recording
elif [ "${1-}" = "toggle" ]; then
if stop_recording 2>/dev/null; then
exit 0
else
start_recording
elif [ "$1" = "stop" ]; then
stop_recording
elif [ "$1" = "toggle" ]; then
if stop_recording 2>/dev/null; then
exit 0
else
start_recording
fi
fi
else
>&2 echo "Error: No argument provided!"
>&2 echo "Expected one of: start, stop, toggle"
exit 1
>&2 echo "Error: No argument provided!"
>&2 echo "Expected one of: start, stop, toggle"
exit 1
fi