59 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			Bash
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			59 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			Bash
		
	
	
		
			Executable File
		
	
	
	
	
#!/bin/sh
 | 
						|
 | 
						|
name=`basename "$0"`
 | 
						|
 | 
						|
isInstalled() {
 | 
						|
	type "$1" > /dev/null
 | 
						|
}
 | 
						|
 | 
						|
mustHaveInstalled() {
 | 
						|
	if ! isInstalled "$1"; then
 | 
						|
		echo "$name: $1 is not installed" >&2
 | 
						|
		exit 1
 | 
						|
	fi
 | 
						|
}
 | 
						|
 | 
						|
usage() {
 | 
						|
	echo "Usage: $name [selection | window | screen] [clipboard]" >&2
 | 
						|
	exit 2
 | 
						|
}
 | 
						|
 | 
						|
picturesDir=`xdg-user-dir PICTURES`
 | 
						|
test -z "$picturesDir" && picturesDir="$HOME/Pictures"
 | 
						|
picturesDir="$picturesDir/Screen Shots"
 | 
						|
 | 
						|
if ! mkdir -p "$picturesDir"; then
 | 
						|
	echo "$name: can't create $picturesDir" >&2
 | 
						|
	exit 1
 | 
						|
fi
 | 
						|
outputFilePath="$picturesDir/`date -Iseconds`.png"
 | 
						|
 | 
						|
mustHaveInstalled scrot
 | 
						|
case "$1" in
 | 
						|
"selection" | "window" | "screen")
 | 
						|
	mode="$1"
 | 
						|
	shift 1
 | 
						|
	;;
 | 
						|
*)
 | 
						|
	mode="screen"
 | 
						|
	;;
 | 
						|
esac
 | 
						|
 | 
						|
if [ "$1" = "clipboard" ]; then
 | 
						|
	clipboard=true
 | 
						|
	shift 1
 | 
						|
fi
 | 
						|
 | 
						|
[ "$#" -gt 0 ] && usage
 | 
						|
 | 
						|
case "$mode" in
 | 
						|
"selection") scrot --select --line style=dash --freeze --file "$outputFilePath";;
 | 
						|
"window"   ) scrot --focused --border --file "$outputFilePath";;
 | 
						|
"screen"   ) scrot --file "$outputFilePath";;
 | 
						|
esac
 | 
						|
 | 
						|
if [ -n "$copyToClipboard" ]; then
 | 
						|
	mustHaveInstalled xclip
 | 
						|
	xclip -selection clipboard -target image/png -i "$outputFilePath"
 | 
						|
fi
 |