Small refactor for screenshot

This commit is contained in:
Lucas 2019-12-08 18:20:59 +00:00
parent c84c0e3a99
commit 9b49b33642

View File

@ -28,21 +28,17 @@ err()
exit 1 exit 1
} }
save_screenshot()
{
xwdtopnm | pnmtopng >~/media/ss/"$(date +%Y%m%d-%H%M%S)".png
}
case $# in case $# in
0) xwd -silent -root | save_screenshot 0) set -- -root
;; ;;
1) [ "$1" = "-window" ] || err "Unknown option \"$1\"." 1) [ "$1" = "-window" ] || err "Unknown option \"$1\"."
xwd -silent | save_screenshot set --
;; ;;
2) [ "$1" = "-id" ] || [ "$1" = "-name" ] || err "Unknown option \"$1\"." 2) [ "$1" = "-id" ] || [ "$1" = "-name" ] || err "Unknown option \"$1\"."
[ -n "$2" ] || err "$1 expects a non-empty parameter." [ -n "$2" ] || err "$1 expects a non-empty parameter."
xwd -silent "$1" "$2" | save_screenshot
;; ;;
*) usage *) usage
;; ;;
esac esac
xwd -silent "$@" | xwdtopnm | pnmtopng >~/media/ss/"$(date +%Y%m%d-%H%M%S)".png