Use cached-nix-shell for scr{cap,rec} scripts

Also refactor them
This commit is contained in:
Henrik Lissner 2020-01-12 18:18:09 -05:00
parent 3f4eba408e
commit ef3b5df3cb
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395
2 changed files with 22 additions and 18 deletions

View file

@ -1,4 +1,5 @@
#!/usr/bin/env bash #!/usr/bin/env cached-nix-shell
#! nix-shell -i bash -p maim slop
# A script that takes a screenshot (prompts you for what region/window to # A script that takes a screenshot (prompts you for what region/window to
# capture) and stores it in the clipboard. # capture) and stores it in the clipboard.
@ -8,7 +9,7 @@ cleanup() { rm -f "$tmp"; }
trap cleanup EXIT trap cleanup EXIT
# Delay for long enough that we can refocus the targeted window # Delay for long enough that we can refocus the targeted window
if maim --delay=${1:-0.6} -us >"$tmp"; then if maim --delay=${2:-1} -us >"$tmp"; then
xclip -selection clipboard -t image/png "$tmp" && xclip -selection clipboard -t image/png "$tmp" &&
notify-send "Screenshot saved" notify-send "Screenshot saved"
else else

View file

@ -1,4 +1,5 @@
#!/usr/bin/env bash #!/usr/bin/env cached-nix-shell
#! nix-shell -i bash -p ffmpeg slop
# Select a region and record it. # Select a region and record it.
# #
@ -14,26 +15,25 @@ geom=
delay=1 delay=1
count=3 count=3
fps=30 fps=30
compton=1
stopfile=/tmp/_stop stopfile=/tmp/_stop
while getopts spg:d:c: opt; do while getopts c:d:f:g:ps opt; do
case $opt in case $opt in
s) is_script=1 ;;
c) count=$OPTARG ;; c) count=$OPTARG ;;
p) compton= ;; d) delay="$OPTARG" ;;
f) fps=$OPTARG ;; f) fps=$OPTARG ;;
g) geom="$OPTARG" ;; g) geom="$OPTARG" ;;
d) delay="$OPTARG" ;; p) compton= ;;
s) is_script=1 ;;
esac esac
done done
shift $((OPTIND-1)) shift $((OPTIND-1))
## ##
select_region() { select-region() {
if [[ $geom ]]; then if [[ $geom ]]; then
echo "${geom//[x+]/ }" echo "${geom//[x+]/ }"
else else
slop -n -f "%x %y %w %h" slop -nof "%w %h %x %y"
fi fi
} }
@ -55,11 +55,9 @@ countdown() {
} }
recording-start() { recording-start() {
local X Y W H local ffmpeg_opts="-y -f x11grab -show_region 1 -ss $delay -s ${4}x${5} -i :0.0+${2},${3} -framerate ${fps}"
read -r X Y W H < <(select_region)
local ffmpeg_opts="-y -f x11grab -show_region 1 -ss $delay -s ${W}x${H} -i :0.0+${X},${Y} -framerate ${fps}"
local dest=${1:-./rec.mp4} local dest=${1:-./rec.mp4}
local mp4dest local mp4dest=
[[ $dest == *.gif ]] && mp4dest="${dest%.*}.mp4" [[ $dest == *.gif ]] && mp4dest="${dest%.*}.mp4"
countdown countdown
touch $stopfile touch $stopfile
@ -80,14 +78,19 @@ if [[ $is_script && -f $stopfile ]]; then
exit 0 exit 0
fi fi
read -r W H X Y < <(select-region)
# Compton with blur and/or transparencies cause unbearable flickering in # Compton with blur and/or transparencies cause unbearable flickering in
# recordings, so temporarily disable it. # recordings, so temporarily disable it.
compton=
if systemctl is-enabled --user compton >/dev/null; then if systemctl is-enabled --user compton >/dev/null; then
systemctl --user stop compton systemctl --user stop compton
compton=1
fi fi
recording-start "$dest" cleanup() { [[ $compton ]] && systemctl --user start compton; }
if systemctl is-enabled --user compton >/dev/null; then trap cleanup EXIT
systemctl --user start compton
fi # Let 'er rip
recording-start "$dest" "$X" "$Y" "$W" "$H"
# vim:set ft=sh shiftwidth=2: # vim:set ft=sh shiftwidth=2: