Skip to content

Commit

Permalink
Merge pull request #5 from m4rch3n1ng/raw
Browse files Browse the repository at this point in the history
add `--raw` command line option
  • Loading branch information
Gustash authored Jun 15, 2023
2 parents 31360af + 0ad6518 commit 9d9df54
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions hyprshot
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Options:
-f, --filename the file name of the resulting screenshot
-d, --debug print debug information
-s, --silent don't send notification when screenshot is saved
-r, --raw output raw image data to stdout
--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
Expand Down Expand Up @@ -50,23 +51,32 @@ function send_notification() {
-i "${1}" -a Hyprshot
}

function trim() {
convert "${1}" -trim +repage "${1}"
}

function save_geometry() {
Print "Geometry: %s\n" "${1}"
local output=""

if [ $RAW -eq 1 ]; then
grim -g "${1}" - | trim -
return 0
fi

if [ $CLIPBOARD -eq 0 ]; then
mkdir -p "$SAVEDIR"
grim -g "${1}" "$SAVE_FULLPATH"
output="$SAVE_FULLPATH"
# Trim transparent pixels, in case the window was floating and partially
# outside the monitor
convert $output -trim +repage $output
trim "${output}"
wl-copy < "$output"
[ -z "$COMMAND" ] || {
"$COMMAND" "$output"
}
else
wl-copy < <(grim -g "${1}" - | convert - -trim +repage -)
wl-copy < <(grim -g "${1}" - | trim -)
fi

send_notification $output
Expand Down Expand Up @@ -109,7 +119,7 @@ function grab_window() {
}

function args() {
local options=$(getopt -o hf:o:m:ds --long help,filename:,output-folder:,mode:,clipboard-only,debug,silent -- "$@")
local options=$(getopt -o hf:o:m:dsr --long help,filename:,output-folder:,mode:,clipboard-only,debug,silent,raw -- "$@")
eval set -- "$options"

while true; do
Expand Down Expand Up @@ -139,6 +149,9 @@ function args() {
-s | --silent)
SILENT=1
;;
-r | --raw)
RAW=1
;;
--)
shift # Skip -- argument
COMMAND=${@:2}
Expand All @@ -161,6 +174,7 @@ fi
CLIPBOARD=0
DEBUG=0
SILENT=0
RAW=0
FILENAME="$(date +'%Y-%m-%d-%H%M%S_hyprshot.png')"
[ -z "$HYPRSHOT_DIR" ] && SAVEDIR=${XDG_PICTURES_DIR:=~} || SAVEDIR=${HYPRSHOT_DIR}

Expand Down

0 comments on commit 9d9df54

Please sign in to comment.