53 lines
1.2 KiB
Bash
Executable File
53 lines
1.2 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
|
|
unset use_clipboard
|
|
if [[ "$1" == "--clipboard" ]]; then
|
|
use_clipboard="true"
|
|
elif [[ "$1" == "--colour" ]]; then
|
|
pick_colour="true"
|
|
fi
|
|
|
|
if ! $(which slop &>/dev/null); then
|
|
notify-send "[screenshot]" "missing \`slop\`"
|
|
exit 1
|
|
fi
|
|
if [[ -n "${use_clipboard}" ]] && ! $(which xclip &>/dev/null); then
|
|
notify-send "[screenshot]" "missing \`xclip\`"
|
|
exit 1
|
|
fi
|
|
|
|
screenshots_path="${HOME}/screenshots"
|
|
if [[ ! -d "${screenshots_path}" ]]; then
|
|
mkdir "${screenshots_path}"
|
|
fi
|
|
temp_file="${screenshots_path}/temporary.png"
|
|
|
|
maim -suo -f png -t 0 "${temp_file}"
|
|
|
|
# meh!
|
|
function colour_picker {
|
|
colour_value="$(magick "${temp_file}" -scale 1x1\! -format "#%[hex:p{0,0}]" info:)"
|
|
notify-send "[colour picker]" "${colour_value}"
|
|
echo "${colour_value}" | xclip -selection clipboard
|
|
remove_temporary_file
|
|
}
|
|
|
|
function clipboard {
|
|
xclip -selection clipboard -t image/png <"${temp_file}"
|
|
remove_temporary_file
|
|
}
|
|
|
|
function save_screenshot {
|
|
mv "${temp_file}" "${screenshots_path}/$(date '+%Y%m%d_%H%M%S').png"
|
|
}
|
|
|
|
function remove_temporary_file {
|
|
rm "${temp_file}"
|
|
}
|
|
|
|
case "$1" in
|
|
"clipboard") clipboard ;;
|
|
"colour") colour_picker ;;
|
|
*) save_screenshot ;;
|
|
esac
|