Skip to content

Instantly share code, notes, and snippets.

@sochotnicky
Created March 10, 2021 11:58
Show Gist options
  • Select an option

  • Save sochotnicky/b28ed56a176a347026d2f5f430032180 to your computer and use it in GitHub Desktop.

Select an option

Save sochotnicky/b28ed56a176a347026d2f5f430032180 to your computer and use it in GitHub Desktop.
/home/w0rm/bin/screenshot
#!/bin/bash
if [ -z "$1" ]; then
echo "Need screenshot type (screen, window, selection) as argument"
exit 1
fi
case "$1" in
whole)
export IMG=~/Pictures/Screenshots/whole-$(date | sed 's/ /_/g;s/:/./g').png
grim $IMG
;;
window)
export IMG=~/Pictures/Screenshots/window-$(date | sed 's/ /_/g;s/:/./g').png
grim -g "$(swaymsg -t get_tree | \
jq -r '.. | select(.pid? and .visible?) | .rect | "\(.x),\(.y) \(.width)x\(.height)"' | \
slurp)" $IMG
;;
screen)
out=$(swaymsg -t get_outputs | jq -r '.[] | select(.focused).name')
export IMG=~/Pictures/Screenshots/$out-$(date | sed 's/ /_/g;s/:/./g').png
grim -o $out $IMG
;;
selection)
export IMG=~/Pictures/Screenshots/selection-$(date | sed 's/ /_/g;s/:/./g').png
grim -g "$(slurp)" $IMG
esac
wl-copy < $IMG
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment