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