feat(work): add print scripts

This commit is contained in:
lucas barbieri 2024-11-28 11:05:26 -03:00
parent 68011d1163
commit 392d20ce0b
2 changed files with 41 additions and 10 deletions

View File

@ -0,0 +1,30 @@
#!/bin/bash
swpy_dir="${XDG_CONFIG_HOME:-$HOME/.config}/swappy"
save_dir="$HOME/pics/screenshots"
save_file="screenshot-$(date -Iseconds | cut -d '+' -f1).png"
temp_screenshot="/tmp/screenshot.png"
mkdir -p $save_dir
mkdir -p $swpy_dir
echo -e "[Default]\nsave_dir=$save_dir\nsave_filename_format=$save_file" > $swpy_dir/config
if [[ $XDG_SESSION_TYPE == "x11" ]]; then
maim -i $(xdotool getactivewindow) | xclip -sel clip -t image/png
fi
if [[ $XDG_SESSION_TYPE == "wayland" ]]; then
if [[ $XDG_CURRENT_DESKTOP == "Hyprland" ]]; then
window_info=$(hyprctl activewindow)
coordinates=$(echo "$window_info" | grep -oP 'at: \K([0-9]+,[0-9]+)')
size=$(echo "$window_info" | grep -oP 'size: \K([0-9]+,[0-9]+)')
IFS=',' read -r x y <<< "$coordinates"
IFS=',' read -r width height <<< "$size"
grim -g "${x},${y} ${width}x${height}" ~/tmp/jabuxas.png
wl-copy < ~/tmp/jabuxas.png
fi
if [[ $XDG_CURRENT_DESKTOP == "sway" ]]; then
rm $temp_screenshot
grim -g "$(swaymsg -t get_tree | jq -j '.. | select(.type?) | select(.focused).rect | "\(.x),\(.y) \(.width)x\(.height)"')" $temp_screenshot
wl-copy < ~/tmp/jabuxas.png
swappy -f $temp_screenshot
fi
fi

View File

@ -11,32 +11,33 @@ echo -e "[Default]\nsave_dir=$save_dir\nsave_filename_format=$save_file" > $swpy
upload () upload ()
{ {
curl -F'file=@'"${save_dir}/${save_file}" -Fsecret= https://paste.jabuxas.xyz | wl-copy curl -F'file=@'"${save_dir}/${save_file}" -Fsecret= -H 'X-Auth: '$(cat ~/.key) https://paste.jabuxas.xyz | wl-copy
} }
function print_error function print_error
{ {
cat << "EOF" cat << "EOF"
./screenshot.sh <action> ./way-print.sh <action>
...valid actions are... ...valid actions are...
p : print all screens p : print all screens
s : snip current screen s : snip current screen
sf : snip current screen (frozen)
m : print focused monitor m : print focused monitor
t : tmp print
cw: current window
EOF EOF
} }
case $1 in case $1 in
p) # print all outputs p) # print all outputs
~/.local/bin/grimblast copysave screen $temp_screenshot && swappy -f $temp_screenshot ;; grim $temp_screenshot && wl-copy < $temp_screenshot && swappy -f $temp_screenshot ;;
s) # drag to manually snip an area / click on a window to print it s) # drag to manually snip an area / click on a window to print it
~/.local/bin/grimblast copysave area $temp_screenshot && swappy -f $temp_screenshot ;; grim -g "$(slurp)" $temp_screenshot && wl-copy < $temp_screenshot && swappy -f $temp_screenshot ;;
sf) # frozen screen, drag to manually snip an area / click on a window to print it
~/.local/bin/grimblast --freeze copysave area $temp_screenshot && swappy -f $temp_screenshot ;;
m) # print focused monitor m) # print focused monitor
~/.local/bin/grimblast copysave output $temp_screenshot && swappy -f $temp_screenshot ;; grim -o $(swaymsg -t get_workspaces | jq -r '.[] | select(.focused==true).output') $temp_screenshot && wl-copy < $temp_screenshot && swappy -f $temp_screenshot ;;
t) #upload to 0x0.st temporarily t) #upload to paste
~/.local/bin/grimblast copysave area $temp_screenshot && swappy -f $temp_screenshot && upload ;; grim -g "$(slurp)" $temp_screenshot && wl-copy < $temp_screenshot && swappy -f $temp_screenshot && upload ;;
cw) #current window
~/scripts/print-window.sh ;;
*) # invalid option *) # invalid option
print_error ;; print_error ;;
esac esac