-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathtermshot
More file actions
executable file
·40 lines (33 loc) · 1.03 KB
/
termshot
File metadata and controls
executable file
·40 lines (33 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/bin/bash
set -e
CROP=+14+0 #this removes the scrollbar, adjust as needed depending on your terminal emulator
PIDFILE=/tmp/termshot.$$
[ -z "$WINDOWID" ] && WINDOWID="$(xdotool getactivewindow)"
[ -z "$WINDOWID" ] && echo \$WINDOWID is not set and xdotool does not work. Check you terminal emulator or install xdotool. && exit 2
sc=0
while [ "${1:0:1}" == "-" ]; do
case ${1:1} in
c) sc=1 ;;
*) echo "Unknown switch; see usage"; exit 1 ;;
esac
shift
done
[ -z $2 ] && echo "Usage: $0 [-c] /path/to/destination_image.png command [arguments]" && exit 1
clear
sleep 0.2
file=$1
shift
if [ $sc -gt 0 ]; then
[ "$EUID" == "0" ] && q="\#" || q="\$"
echo "clear; echo $q \"${@@Q}\"; "${@@Q}"; touch $PIDFILE; sleep 1; exit" | script -q /dev/null & #preserve colors
else
echo "clear; "${@@Q}"; touch $PIDFILE; sleep 1; exit" | script -q /dev/null & #preserve colors
fi
while [ ! -f $PIDFILE ]; do
sleep 0.1
done
rm $PIDFILE
sleep 0.5
import -silent -window "$WINDOWID" -gravity East -crop "$CROP" "$file"
sleep 1
echo Saved screenshot in $file