#!/usr/bin/env sh # Dependences: # xclip # imagemagick # dmenu # scrot # # TODO: # - integrate https://img.vim-cn.com/, an image pastebin NC='\033[0m' RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[0;33m' msg_info() { echo -e "${GREEN}$1${NC}" } msg_warn() { echo -e "${YELLOW}$1${NC}" } msg_error() { echo -e "${RED}$1${NC}" } print_help() { echo echo "screenshot - a wrapper for scrot (screenshot utility)" echo echo "USAGE:" echo " screenshot [OPTION ...]" echo echo "OPTIONs are:" echo " -s | --selection:" echo " takes a screenshot of the selected area or window (equivalent" echo " to scrot selection feature)." echo " -c | --clipboard:" echo " copy the screenshot to the system clipboard." echo " -d | --dmenu:" echo " Use dmenu to interactively choose whether to use the selection" echo " and copy-to-clipboard features." echo " -z | --silent:" echo " Turn off notifications (scrot sound notification is always off)." echo " -h | -? | --help:" echo " print this help." echo } notify() { convert "$1" -resize 200x200 "$2" notify-send --expire-time=5000 --icon="$2" "Screenshot taken." "$1" } copy_to_clipboard() { cat "$1" | xclip -selection clipboard -t image/png } command=${1:-simple} shift case $command in simple) # Just take a screenshot ;; ls|list) ;; start) ;; stop) ;; add) ;; rm|remove) ;; del|delete) ;; pause) ;; unpause) ;; info) ;; help) print_help ;; *) msg_error "$COMMAND: invalid command" print_help exit 1 ;; esac name="screenshot-$(date '+%Y%m%d-%H%M%S').png" scrot_path="$IMGS/screenshots/" thumb_path="$TMPDIR/screenshots/" choice=$(echo -e "select\nselect and copy\nfullscreen\nfullscreen and copy" | dmenu -l 10 -i -p "Screenshot:") mkdir -p "$scrot_path" mkdir -p "$thumb_path" case "$choice" in "select") scrot -s "$scrot_path$name" notify "$scrot_path$name" "$thumb_path$name" ;; "select and copy") scrot -s "$scrot_path$name" notify "$scrot_path$name" "$thumb_path$name" copy_to_clipboard "$scrot_path$name" ;; "fullscreen") scrot "$scrot_path$name" notify "$scrot_path$name" "$thumb_path$name" ;; "fullscreen and copy") scrot "$scrot_path$name" notify "$scrot_path$name" "$thumb_path$name" copy_to_clipboard "$scrot_path$name" ;; *) exit 1 ;; esac # # #exit 0