maim-utils/maim-utils

62 lines
2.1 KiB
Bash
Executable file

#!/bin/sh
savedir="${SCROTDIR:-$HOME/Pictures/Screenshots}"
filename="$savedir/$(date -Iseconds)_maim.png"
# test whether the screenshot directory exists, if not, create it.
[ -d $savedir ] || mkdir -p $savedir
fullscreen(){
maim -ui root "$filename"
notify-send 'Maim utils' "Shot entire screen and saved output to:\n\n$filename"
}
selection(){
maim -su "$filename"
notify-send 'Maim utils' "Shot selection and saved output to:\n\n$filename\n\nBe aware that the selection process can be cancelled using any keypress and that this won't show up due to xclip eating the exit status."
}
focus(){
maim -ui "$(xdotool getactivewindow)" "$filename"
notify-send 'Maim utils' "Shot focussed window and saved output to:\n\n$filename"
}
clip_fullscreen(){
maim -ui root | xclip -sel clip -t image/png
notify-send 'Maim utils' "Shot entire screen and sent it to the clipboard."
}
clip_selection(){
maim -su | xclip -sel clip -t image/png
notify-send 'Maim utils' "Shot selection and sent it to the clipboard.\nBe aware that the selection process can be cancelled using any keypress and that this won't show up due to xclip eating the exit status."
}
clip_focus(){
maim -ui "$(xdotool getactivewindow)" | xclip -sel clip -t image/png
notify-send 'Maim utils' "Shot focussed window and sent it to the clipboard."
}
usage(){
cat >&2 <<EOF
Usage: maim-utils <screenshot-type>
fullscreen|full: take screenshot of entire screen
selection|sel: take screenshot of rectangular selection
focus: take screenshot of focussed window
clip-fullscreen|clip-full|full-clip: take screenshot of entire screen and output to clipboard
clip-selection|clip-sel|sel-clip: take screenshot of rectangular selection and output to clipboard
clip-focus|focus-clip: take screenshot of focussed window and output to clipboard
open|show|screenshots: open screenshot directory
EOF
}
case $1 in
sel|selection) selection;;
sel-clip|clip-sel|clip-selection) clip_selection;;
full|fullscreen) fullscreen;;
full-clip|clip-full|clip-fullscreen) clip_fullscreen;;
focus) foucs;;
clip-focus|focus-clip) clip_focus;;
open|show|screenshots) xdg-open $savedir;;
*) usage;;
esac