Skip to content

Instantly share code, notes, and snippets.

@mtngld
Created August 27, 2015 07:13
Show Gist options
  • Save mtngld/7a3d850624552dc618de to your computer and use it in GitHub Desktop.
Save mtngld/7a3d850624552dc618de to your computer and use it in GitHub Desktop.
Terminal tabs saving and restoring
#!/usr/bin/env bash
##########
# This file should be run in cron, such as:
# 0 * * * * bash ~/save_tabs.sh
##########
STATE_FILE = $HOME/saved_tabs
gnome-terminal --save-config=$STATE_FILE
LINES=($(grep -n '\[Terminal' $STATE_FILE | cut -d: -f1))
for ((i=0; i<$(grep '\[Terminal' $STATE_FILE | wc -l); i++))
do
TITLE=$(xprop -id $WINDOWID WM_NAME | sed -e 's/WM_NAME(STRING) = "//' -e 's/"$//';xdotool key ctrl+Page_Down;)
echo $TITLE
sed -ri "$((${LINES[$i]}+$i))s/.*/&\nTitle=$TITLE/" $STATE_FILE
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment