💄 style(hypr): hyprlock script indentation corrected to 2 spaces

This commit is contained in:
Sergio Laín 2024-07-25 18:56:17 +02:00
parent 019ccf9272
commit 341c78ff12
No known key found for this signature in database
GPG key ID: 8429B2EE312F8150

View file

@ -20,11 +20,12 @@ Options:
-m, --mode one of: output, window, region, active, OUTPUT_NAME
-o, --output-folder directory in which to save screenshot
-f, --filename the file name of the resulting screenshot
-D, --delay how long to delay taking the screenshot after selection (seconds)
-z, --freeze freeze the screen on initialization
-d, --debug print debug information
-s, --silent don't send notification when screenshot is saved
-r, --raw output raw image data to stdout
-t, --notif-timeout notification timeout in milliseconds (default 5000)
-z, --freeze freeze current output to take screenshot
--clipboard-only copy screenshot to clipboard and don't save image in disk
-- [command] open screenshot with a command of your choosing. e.g. hyprshot -m window -- mirage
@ -59,6 +60,7 @@ function send_notification() {
action=$(notify-send -i "$1" --action "View Image" "Screenshot saved" \
"${message}" \
-t "$NOTIF_TIMEOUT" -i "${1}" -a Hyprshot)
if [ -n "$action" ]; then
if command -v satty &>/dev/null; then
satty -f "$1"
@ -69,6 +71,7 @@ function send_notification() {
}
function trim() {
Print "Geometry: %s\n" "${1}"
local geometry="${1}"
local xy_str=$(echo "${geometry}" | cut -d' ' -f1)
local wh_str=$(echo "${geometry}" | cut -d' ' -f2)
@ -104,47 +107,54 @@ function trim() {
cropped_height=$((cropped_height + y - min_y))
fi
printf "%s,%s %sx%s\n" \
local cropped=$(printf "%s,%s %sx%s\n" \
"${cropped_x}" "${cropped_y}" \
"${cropped_width}" "${cropped_height}"
"${cropped_width}" "${cropped_height}")
Print "Crop: %s\n" "${cropped}"
echo ${cropped}
}
function save_geometry() {
Print "Geometry: %s\n" "${1}"
local cropped_geometry=$(trim "${1}")
Print "Crop: %s\n" "${cropped_geometry}"
local geometry="${1}"
local output=""
if [ $RAW -eq 1 ]; then
grim -g "${cropped_geometry}" -
grim -g "${geometry}" -
return 0
fi
if [ $CLIPBOARD -eq 0 ]; then
mkdir -p "$SAVEDIR"
grim -g "${cropped_geometry}" "$SAVE_FULLPATH"
grim -g "${geometry}" "$SAVE_FULLPATH"
output="$SAVE_FULLPATH"
wl-copy <"$output"
wl-copy --type image/png <"$output"
[ -z "$COMMAND" ] || {
"$COMMAND" "$output"
}
else
wl-copy < <(grim -g "${cropped_geometry}" -)
wl-copy --type image/png < <(grim -g "${geometry}" -)
fi
send_notification $output
}
function begin_grab() {
local option=$1
function checkRunning() {
sleep 1
while [[ 1 == 1 ]]; do
if [[ $(pgrep slurp | wc -m) == 0 ]]; then
pkill hyprpicker
exit
fi
done
}
if [ $FREEZE -eq 1 ]; then
sleep 0.5
function begin_grab() {
if [ $FREEZE -eq 1 ] && [ "$(command -v "hyprpicker")" ] >/dev/null 2>&1; then
hyprpicker -r -z &
sleep 0.2
local picker_pid=$!
HYPRPICKER_PID=$!
fi
local option=$1
case $option in
output)
if [ $CURRENT -eq 1 ]; then
@ -164,14 +174,13 @@ function begin_grab() {
else
local geometry=$(grab_window)
fi
geometry=$(trim "${geometry}")
;;
esac
save_geometry "${geometry}"
if [ $FREEZE -eq 1 ]; then
kill $picker_pid
if [ ${DELAY} -gt 0 ] 2>/dev/null; then
sleep ${DELAY}
fi
save_geometry "${geometry}"
}
function grab_output() {
@ -205,14 +214,14 @@ function grab_window() {
Print "Clients: %s\n" "$clients"
# Generate boxes for each visible window and send that to slurp
# through stdin
local boxes="$(echo $clients | jq -r '.[] | "\(.at[0]),\(.at[1]) \(.size[0])x\(.size[1]) \(.title)"')"
local boxes="$(echo $clients | jq -r '.[] | "\(.at[0]),\(.at[1]) \(.size[0])x\(.size[1]) \(.title)"' | cut -f1,2 -d' ')"
Print "Boxes:\n%s\n" "$boxes"
slurp -r <<<"$boxes"
}
function grab_active_window() {
local active_window=$(hyprctl -j activewindow)
local box=$(echo $active_window | jq -r '"\(.at[0]),\(.at[1]) \(.size[0])x\(.size[1])"')
local box=$(echo $active_window | jq -r '"\(.at[0]),\(.at[1]) \(.size[0])x\(.size[1])"' | cut -f1,2 -d' ')
Print "Box:\n%s\n" "$box"
echo "$box"
}
@ -235,7 +244,7 @@ function parse_mode() {
}
function args() {
local options=$(getopt -o hf:o:m:dsrt:z --long help,filename:,output-folder:,mode:,clipboard-only,debug,silent,raw,notif-timeout:,freeze -- "$@")
local options=$(getopt -o hf:o:m:D:dszr:t: --long help,filename:,output-folder:,mode:,delay:,clipboard-only,debug,silent,freeze,raw,notif-timeout: -- "$@")
eval set -- "$options"
while true; do
@ -252,6 +261,10 @@ function args() {
shift
FILENAME=$1
;;
-D | --delay)
shift
DELAY=$1
;;
-m | --mode)
shift
parse_mode $1
@ -262,6 +275,9 @@ function args() {
-d | --debug)
DEBUG=1
;;
-z | --freeze)
FREEZE=1
;;
-s | --silent)
SILENT=1
;;
@ -272,9 +288,6 @@ function args() {
shift
NOTIF_TIMEOUT=$1
;;
-z | --freeze)
FREEZE=1
;;
--)
shift # Skip -- argument
COMMAND=${@:2}
@ -299,9 +312,9 @@ CLIPBOARD=0
DEBUG=0
SILENT=0
RAW=0
FREEZE=0
NOTIF_TIMEOUT=5000
CURRENT=0
FREEZE=0
[ -z "$XDG_PICTURES_DIR" ] && type xdg-user-dir &>/dev/null && XDG_PICTURES_DIR=$(xdg-user-dir PICTURES)
FILENAME="$(date +'%Y-%m-%d-%H%M%S_hyprshot.png')"
[ -z "$HYPRSHOT_DIR" ] && SAVEDIR=${XDG_PICTURES_DIR:=~} || SAVEDIR=${HYPRSHOT_DIR}
@ -310,4 +323,5 @@ args $0 "$@"
SAVE_FULLPATH="$SAVEDIR/$FILENAME"
[ $CLIPBOARD -eq 0 ] && Print "Saving in: %s\n" "$SAVE_FULLPATH"
begin_grab $OPTION
begin_grab $OPTION &
checkRunning