mirror of
https://github.com/ItsDrike/dotfiles.git
synced 2025-01-23 07:34:34 +00:00
Compare commits
3 commits
9e946c7611
...
6c5c3fb36c
Author | SHA1 | Date | |
---|---|---|---|
ItsDrike | 6c5c3fb36c | ||
ItsDrike | db58721f45 | ||
ItsDrike | f871b7b427 |
|
@ -102,3 +102,4 @@
|
|||
gpgsign = true
|
||||
[init]
|
||||
defaultBranch = main
|
||||
templatedir = ~/.config/git/templates
|
||||
|
|
156
home/.config/git/templates/hooks/commit-msg
Executable file
156
home/.config/git/templates/hooks/commit-msg
Executable file
|
@ -0,0 +1,156 @@
|
|||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
# A hook script to check the commit log message.
|
||||
# Called by "git commit" with one argument, the name of the file
|
||||
# that has the commit message. The hook should exit with non-zero
|
||||
# status after issuing an appropriate message if it wants to stop the
|
||||
# commit. The hook is allowed to edit the commit message file.
|
||||
|
||||
# This script focuses on enforcing semantic commit message specification.
|
||||
#
|
||||
# It primarily focuses on the commit title, however, it also enforces some
|
||||
# the mandatory newline between the title and the body.
|
||||
|
||||
LIGHT_GRAY="\033[0;37m"
|
||||
YELLOW="\033[33m"
|
||||
CYAN="\033[36m"
|
||||
RED="\033[31m"
|
||||
UNDO_COLOR="\033[0m"
|
||||
|
||||
check_dependencies() {
|
||||
if ! [ -x "$(command -v jq)" ]; then
|
||||
echo "\`commit-msg\` hook failed. Please install jq."
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
load_config() {
|
||||
config_file="$PWD/.commit-msg-config.json"
|
||||
|
||||
if [ ! -f "$config_file" ]; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
enabled=$(jq -r .enabled "$config_file")
|
||||
|
||||
if [ "$enabled" != "true" ]; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
title_semver_enabled=$(jq -r .semver_structure "$config_file")
|
||||
mapfile -t special_types < <(jq -r '.special_types[]' "$config_file")
|
||||
mapfile -t types < <(jq -r '.types[]' "$config_file")
|
||||
mapfile -t scopes < <(jq -r '.scopes[]' "$config_file")
|
||||
title_min_length=$(jq -r '.length.min' "$config_file")
|
||||
title_max_length=$(jq -r '.length.max' "$config_file")
|
||||
}
|
||||
|
||||
# Build a dynamic regex for the commit message
|
||||
build_title_regex() {
|
||||
regexp="^("
|
||||
|
||||
# Special types
|
||||
if [ ${#special_types[@]} -eq 0 ]; then
|
||||
for s_type in "${special_types[@]}"; do
|
||||
regexp="${regexp}$s_type|"
|
||||
done
|
||||
regexp="${regexp%|})"
|
||||
|
||||
regexp="${regexp}(: .+)?"
|
||||
|
||||
regexp="${regexp}$|^("
|
||||
fi
|
||||
|
||||
# Types
|
||||
if [ ${#types[@]} -eq 0 ]; then
|
||||
regexp="${regexp}.+"
|
||||
else
|
||||
for type in "${types[@]}"; do
|
||||
regexp="${regexp}$type|"
|
||||
done
|
||||
regexp="${regexp%|})"
|
||||
fi
|
||||
|
||||
# Scope
|
||||
regexp="${regexp}(\("
|
||||
if [ ${#scopes[@]} -eq 0 ]; then
|
||||
regexp="${regexp}.+"
|
||||
else
|
||||
for scope in "${scopes[@]}"; do
|
||||
regexp="${regexp}$scope|"
|
||||
done
|
||||
regexp="${regexp%|}"
|
||||
fi
|
||||
regexp="${regexp}\))?"
|
||||
|
||||
# Breaking change indicator
|
||||
regexp="${regexp}(!)?"
|
||||
|
||||
regexp="${regexp}: (.+)$"
|
||||
}
|
||||
|
||||
error_header() {
|
||||
echo -e "${RED}[Invalid Commit Message]${UNDO_COLOR}"
|
||||
echo -e "------------------------"
|
||||
}
|
||||
|
||||
# ---------------------------------------------
|
||||
|
||||
INPUT_FILE="$1"
|
||||
|
||||
check_dependencies
|
||||
load_config
|
||||
|
||||
# Get the actual commit message, excluding comments
|
||||
commit_message=$(sed '/^#/d' <"$INPUT_FILE")
|
||||
|
||||
# Don't do any checking on empty commit messages.
|
||||
# Git will abort empty commits by default anyways.
|
||||
if [ -z "$commit_message" ]; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
commit_title=$(echo "$commit_message" | head -n1 "$INPUT_FILE")
|
||||
|
||||
# Check the semver commit title structure first
|
||||
if [ "$title_semver_enabled" == "true" ]; then
|
||||
build_title_regex
|
||||
|
||||
if [[ ! $commit_title =~ $regexp ]]; then
|
||||
error_header
|
||||
echo -e "${LIGHT_GRAY}Valid types: ${UNDO_COLOR}${CYAN}${types[*]}${UNDO_COLOR}"
|
||||
echo -e "${LIGHT_GRAY}Valid special types: ${UNDO_COLOR}${CYAN}${special_types[*]}${UNDO_COLOR}"
|
||||
if [ ${#scopes[@]} -eq 0 ]; then
|
||||
echo -e "${LIGHT_GRAY}Valid scopes: any${UNDO_COLOR}"
|
||||
else
|
||||
echo -e "${LIGHT_GRAY}Valid scopes: ${UNDO_COLOR}${CYAN}${scopes[*]}${UNDO_COLOR}"
|
||||
fi
|
||||
|
||||
#echo -e "${LIGHT_GRAY}Expected regex: ${UNDO_COLOR}${CYAN}${regexp}${UNDO_COLOR}"
|
||||
|
||||
echo -e "Actual commit title: ${YELLOW}${commit_title}${UNDO_COLOR}"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
# Then check the length of the commit title
|
||||
commit_title_len=${#commit_title}
|
||||
if { [ "$title_min_length" != "null" ] && [ "$commit_title_len" -lt "$title_min_length" ]; } ||
|
||||
{ [ "$title_max_length" != "null" ] && [ "$commit_title_len" -gt "$title_max_length" ]; }; then
|
||||
error_header
|
||||
echo -e "${LIGHT_GRAY}Expected title (first line) length: Min=${CYAN}$title_min_length${UNDO_COLOR} Max=${CYAN}$title_max_length${UNDO_COLOR}"
|
||||
echo -e "Actual length: ${YELLOW}${commit_title_len}${UNDO_COLOR}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Check for a newline between the title and the body
|
||||
if [ "$(echo "$commit_message" | wc -l)" -gt 1 ]; then
|
||||
second_line=$(echo "$commit_message" | sed -n '2p')
|
||||
third_line=$(echo "$commit_message" | sed -n '3p')
|
||||
if [ "$second_line" != "" ] || [ "$third_line" == "" ]; then
|
||||
error_header
|
||||
echo -e "There must be exactly one blank line between the commit title and the body."
|
||||
exit 1
|
||||
fi
|
||||
fi
|
|
@ -1,19 +1,18 @@
|
|||
#!/bin/sh
|
||||
#!/bin/bash
|
||||
|
||||
# Inspired by grimblast (https://github.com/hyprwm/contrib/blob/main/grimblast/grimblast)
|
||||
|
||||
# Helper functions
|
||||
|
||||
die() {
|
||||
MSG="${1}"
|
||||
ERR_CODE="${2:-1}"
|
||||
URGENCY="${3:-critical}"
|
||||
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"
|
||||
if [ "$NOTIFY" = "yes" ]; then
|
||||
notify-send -a screenshot -u "$URGENCY" "Error ($ERR_CODE)" "$MSG"
|
||||
fi
|
||||
exit "$ERR_CODE"
|
||||
}
|
||||
|
||||
# Argument parsing
|
||||
|
@ -27,9 +26,9 @@ EDIT=no
|
|||
DELAY=0
|
||||
|
||||
while [ "${1-}" ]; do
|
||||
case "$1" in
|
||||
-h | --help)
|
||||
>&2 cat <<EOF
|
||||
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.
|
||||
|
||||
|
@ -54,163 +53,163 @@ Variables:
|
|||
- 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
|
||||
;;
|
||||
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
|
||||
--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"
|
||||
FILE="$1"
|
||||
GEOM="$2"
|
||||
|
||||
ARGS=()
|
||||
[ "$CURSOR" = "yes" ] && ARGS+=("-c")
|
||||
[ -n "$GEOM" ] && ARGS+=("-g" "$GEOM")
|
||||
ARGS+=("$FILE")
|
||||
ARGS=()
|
||||
[ "$CURSOR" = "yes" ] && ARGS+=("-c")
|
||||
[ -n "$GEOM" ] && ARGS+=("-g" "$GEOM")
|
||||
ARGS+=("$FILE")
|
||||
|
||||
sleep "$DELAY"e-3
|
||||
grim "${ARGS[@]}" || die "Unable to invoke grim"
|
||||
sleep "$DELAY"e-3
|
||||
grim "${ARGS[@]}" || die "Unable to invoke grim"
|
||||
}
|
||||
|
||||
takeEditedScreenshot() {
|
||||
FILE="$1"
|
||||
GEOM="$2"
|
||||
FILE="$1"
|
||||
GEOM="$2"
|
||||
|
||||
if [ "$EDIT" = "yes" ]; then
|
||||
takeScreenshot - "$GEOM" | swappy -f - -o "$FILE" || die "Unable to invoke swappy"
|
||||
else
|
||||
takeScreenshot "$FILE" "$GEOM"
|
||||
fi
|
||||
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"
|
||||
GEOM="$(slurp -d)"
|
||||
if [ -z "$GEOM" ]; then
|
||||
die "No area selected" 2 normal
|
||||
fi
|
||||
WHAT="Area"
|
||||
elif [ "$TARGET" = "all" ]; then
|
||||
GEOM=""
|
||||
WHAT="Screen"
|
||||
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"
|
||||
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"
|
||||
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')"
|
||||
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"
|
||||
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
|
||||
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")"
|
||||
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"
|
||||
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")"
|
||||
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
|
||||
if [ -z "$SAVE_METHOD" ]; then
|
||||
die "No save method specified!"
|
||||
else
|
||||
die "Unknown save method: $SAVE_METHOD"
|
||||
fi
|
||||
fi
|
||||
|
|
|
@ -107,7 +107,7 @@ paru -S --noconfirm --needed \
|
|||
|
||||
# Wayland Utilities
|
||||
paru -S --noconfirm --needed \
|
||||
grim slurp wofi swappy-git wf-recorder wlogout clipman hyprpicker hyprpaper
|
||||
grim slurp wofi swappy wf-recorder wlogout clipman hyprpicker hyprpaper
|
||||
|
||||
# Applications
|
||||
paru -S --noconfirm --needed \
|
||||
|
|
Loading…
Reference in a new issue