mabox-tools/bin/mb-tint2-session

82 lines
2.2 KiB
Plaintext
Raw Permalink Normal View History

2020-02-18 17:24:18 +01:00
#!/bin/bash
##
# Read a saved BunsenLabs Tint2 session file and start the tint2s
#
# Written by damo <damo@bunsenlabs.org> for BunsenLabs Linux, April 2015
#
# To start the chosen Tint2 session at login, add the following line
# to config/openbox/autostart:
#
# (sleep 2s && mb-tint2-session) &
#
########################################################################
TINT2PATH="$HOME/.config/tint2"
SESSIONFILE="$TINT2PATH/tint2-sessionfile"
USAGE=$(
echo -e "\vUSAGE: with no command argument, the script uses the chosen"
echo -e "\tTint2 session file \"$TINT2PATH/tint2-sessionfile\","
echo -e "\tif it exists, otherwise the default tint2rc is used"
echo -e "\v\tTo start them at login, add the following line to autostart:"
echo -e "\v\t\t(sleep 2s && mb-tint2-session) &"
)
findArgs(){ # get command args
for arg in "$@";do
if [[ $1 = "-h" ]] || [[ $1 = "--help" ]];then
echo "$USAGE"
exit 0
else
echo -e "\tERROR: sorry I don't understand the input"
echo "$USAGE"
exit 0
fi
done
}
testSessionfile(){
if test -f "$1" &>/dev/null;then # sessionfile found
killTints
while read line;do
if test -z $line &>/dev/null;then
continue
else
2020-09-08 10:47:45 +02:00
if test -e "$HOME$line";then
tint2 -c "$HOME$line" &
2020-02-18 17:24:18 +01:00
sleep 1s
2021-11-10 14:46:25 +01:00
echo "$HOME$line" >> "$SESSIONFILE".tmp
2020-09-08 09:33:10 +02:00
else
tint2 -c "$line" &
fi
2020-02-18 17:24:18 +01:00
fi
done < "$1"
2021-11-10 14:46:25 +01:00
if test -f "$SESSIONFILE".tmp &>/dev/null;then
cat "$SESSIONFILE".tmp > "$SESSIONFILE"
rm "$SESSIONFILE".tmp
fi
2020-02-18 17:24:18 +01:00
else
echo -e "Created sessionfile \"$1\"\nRunning default tint2rc" 2>&1
2020-09-08 09:33:10 +02:00
echo "$HOME/.config/tint2/tint2rc" > "$SESSIONFILE"
2020-02-18 17:24:18 +01:00
killTints
tint2 -c "$TINT2PATH/tint2rc" &>/dev/null
fi
}
killTints(){
pgrep -a tint2 | while read pid cmd; do
if [[ ${cmd%% *} = tint2 ]]; then
kill "$pid"
fi
done
}
if [ $# -eq 0 ];then # if no args, then run default sessionfile
testSessionfile "$SESSIONFILE"
else
findArgs "$@"
fi
# restart compositor in case of rendering problems
mabox-compositor --restart
exit 0