Last active
May 27, 2025 16:13
-
-
Save tunalad/8e72d5e29f205f6c5fe0ebdbbf4381c3 to your computer and use it in GitHub Desktop.
Screenshot script for taking EPIC screenshots, works for both wayland and x11
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# packages needed: | |
# for wayland: | |
# grim - screenshot tool for wayland | |
# slurp - selection tool for wayland | |
# wl-clipboard - clipboard for wayland | |
# for x11: | |
# maim - screenshot tool for x11 | |
# xclip - clipboard for x11 | |
# libnotify - sends notifications | |
SS_DIR="$HOME/Pictures/screenshots" | |
SS_PATH="$SS_DIR/Screenshots_$(date +%Y-%m-%d_%H:%M:%S).png" | |
GRIM_OPTIONS="-c" | |
MAIM_OPTIONS="" | |
SLURP=0 | |
# store the options in an array | |
OPTIONS=("$@") | |
# sort the options | |
IFS=$'\n' sorted_options=($(sort <<<"${OPTIONS[*]}")) | |
unset IFS | |
# process the sorted options | |
for option in "${sorted_options[@]}"; do | |
case "$option" in | |
"--help" | "-h") | |
printf "Usage: screenshot.sh [OPTIONS]\n\n" | |
printf "OPTIONS\n" | |
printf "\t-h, --help\n\t\tPrints this help message and exits.\n" | |
printf "\t-nc, --nocursor\n\t\tScreenshots don't capture the cursor.\n" | |
printf "\t-r, --region\n\t\tLets you select a region to screenshot.\n" | |
exit | |
;; | |
"--nocursor" | "-nc") | |
GRIM_OPTIONS="" | |
MAIM_OPTIONS="--hidecursor $MAIM_OPTIONS" | |
;; | |
"--region" | "-r") | |
GRIM_OPTIONS="-g - " | |
MAIM_OPTIONS="-s " | |
SLURP=1 | |
;; | |
*) | |
;; | |
esac | |
done | |
# make screenshots dir if it doesn't exits | |
mkdir -p "$SS_DIR" | |
# for wayland | |
if [ "$XDG_SESSION_TYPE" == "wayland" ]; then | |
if [ $SLURP -eq 0 ]; then | |
grim $GRIM_OPTIONS "$SS_PATH" || exit | |
elif [ $SLURP -gt 0 ]; then | |
slurp | grim $GRIM_OPTIONS "$SS_PATH" || exit | |
# but if we only click and not drag, ss the whole window | |
fi | |
wl-copy < "$SS_PATH" | |
else | |
# for x11 | |
maim $MAIM_OPTIONS "$SS_PATH" || exit | |
xclip -selection clipboard -t image/png < "$SS_PATH" | |
fi | |
notify-send --icon "$SS_PATH" "Screenshot captured..." "$SS_PATH" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment