Skip to content

Instantly share code, notes, and snippets.

@ryot4
Created July 18, 2016 06:38
Show Gist options
  • Save ryot4/b939fe4931caa40a12fda1ca24b6b636 to your computer and use it in GitHub Desktop.
Save ryot4/b939fe4931caa40a12fda1ca24b6b636 to your computer and use it in GitHub Desktop.
#!/bin/sh
screenshot_root=~/Pictures/screenshot
viewer='xdg-open'
while getopts 'd:n:v' opt; do
case "$opt" in
d) dir="$OPTARG" ;;
n) name="$OPTARG" ;;
v) scrot_execute="$viewer \$f"
esac
done
shift $((OPTIND - 1))
scrot_options='-z'
case "$1" in
active) scrot_options="$scrot_options -u" ;;
select) scrot_options="$scrot_options -s" ;;
root|*) ;;
esac
if [ -n "$dir" ]; then
screenshot_root="$dir"
dir=''
else
dir=$(date +'%Y/%m/%d')
fi
: ${name:=$(date +'%H%M%S.png')}
mkdir -p "$screenshot_root/$dir"
scrot $scrot_options "$screenshot_root/$dir/$name" -e "${scrot_execute:-:}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment