#!/bin/sh # # Script to take screenshots or gifs # menucmd=$HOME/.config/wm_scripts/menucmd grimshot=/usr/share/sway/scripts/grimshot date_format='%Y-%m-%d_%H-%M-%S' scrot_dir=$HOME/screenshots gif_dir=$scrot_dir/gifs [ -d $scrot_dir ] || mkdir $scrot_dir [ -d $gif_dir ] || mkdir $gif_dir # prompt options in Xorg prompt_xorg() { options=" 1) Fullscreen\n\ 2) Selection\n\ 3) Record screen " option=$(echo -e $options | $menucmd) case $option in 1*) sleep 0.5 f_scrot ;; 2*) s_scrot ;; 3*) prompt_gif ;; esac } # prompt options in Wayland prompt_wayland(){ options=" 1) Fullscreen\n\ 2) Selection\n\ 3) Window\n\ " option=$(echo -e $options | $menucmd) # use grimshot here case $option in 1*) sleep 0.5 f_grimshot ;; 2*) s_grimshot ;; 3*) w_grimshot ;; esac } prompt_gif() { options=" 10s\n\ 30s\n\ 60s " option=$(echo -e $options | menucmd) case $option in 10s) byzanz_gif 10 ;; 30s) byzanz_gif 30 ;; 60s) byzanz_gif 60 ;; esac } # screenshots using scrot s_scrot() { name=$(date +${date_format}_sel.png) path="${scrot_dir}/${name}" scrot -a $(slop -f "%x,%y,%w,%h") $path && xclip -sel clip $path -t image/png } f_scrot() { name=$(date +${date_format}_full.png) path="${scrot_dir}/${name}" scrot $path && xclip -sel clip $path -t image/png } # screenshots using grimshot f_grimshot() { name=$(date +${date_format}_full.png) path="${scrot_dir}/${name}" $grimshot save output $path && wl-copy --type image/png < $path } s_grimshot() { name=$(date +${date_format}_full.png) path="${scrot_dir}/${name}" $grimshot save area $path && wl-copy --type image/png < $path } w_grimshot() { name=$(date +${date_format}_full.png) path="${scrot_dir}/${name}" $grimshot save window $path && wl-copy --type image/png < $path } # screen recorder byzanz_gif() { name=$(date +${date_format}.gif) path="${gif_dir}/${name}" byzanz-record -c -d $1 --delay=0 $path } if [[ -n $WAYLAND_DISPLAY ]]; then prompt_wayland elif [[ -n $DISPLAY ]]; then prompt_xorg else echo "Error: No Wayland or X11 display detected" >&2 exit 1 fi