-
Notifications
You must be signed in to change notification settings - Fork 0
/
screen_save
executable file
·67 lines (59 loc) · 1.62 KB
/
screen_save
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/bin/bash
screensave="${HOME}/.screen_saves"
function save() {
# only save if there are running screens!
#ps xua | grep screen
pgrep -U "$UID" "screen" > /dev/null || exit
echo -n "# " > "$screensave"
date >> "$screensave"
for s in $(screen -list | grep "tached" | awk '{print $1}'); do
#echo "Getting info for $s"
name="${s#*.}"
pid="${s%%.*}"
childpids=$(ps --ppid $pid -o pid --no-headers)
echo "$name" >> "$screensave"
for c in $childpids; do
cwd=$(readlink /proc/$c/cwd)
echo "$cwd" >> "$screensave"
done
echo "---" >> "$screensave"
done
}
function restore() {
while read line; do
[[ "$line" =~ ^[[:space:]]*# ]] && { echo "$line" ; continue; }
name="$line"
newtempfile=$(mktemp ~/.byobu/windows.XXXXX)
i=0
while read line; do
[[ "$line" == "---" ]] && break
echo "chdir $line" >> "$newtempfile"
echo "screen $i bash" >> "$newtempfile"
i=$(( ++i ))
done
echo -e "\nselect 0\n" >> "$newtempfile"
#echo -e "\nsleep 2\ndetach\n" >> "$newtempfile"
tempid="${newtempfile##*windows.}"
# Actually start the new screen session
export BYOBU_WINDOWS="$newtempfile"
#export BYOBU_PREFIX="/usr/"
#screen -c /usr/share/byobu/profiles/screenrc -d -m -S "${name}"&
byobu --version 2>/dev/null | grep -q '3\.33' \
&& echo "This byobu version will probably fail!"
byobu -d -m -S ${name}
# cat "$newtempfile"
sleep 5
rm "$newtempfile"
done < "$screensave"
echo "Done."
}
if [[ $1 == "save" ]]; then
save
elif [[ $1 == "restore" ]]; then
restore
else
cat << EOF
Usage:
$0 (save|restore)
EOF
fi