aboutsummaryrefslogtreecommitdiff
path: root/session
diff options
context:
space:
mode:
authorSilvio Rhatto <rhatto@riseup.net>2018-03-08 10:57:39 -0300
committerSilvio Rhatto <rhatto@riseup.net>2018-03-08 10:57:39 -0300
commit268438b049218a5421d8ddaa2b1bc56cddb78dcd (patch)
treebee56c6c763ba4ebf4591b35bee73758725d278e /session
parentb3f4a69af036ae36b0e846083bca95394bde33e4 (diff)
downloadutils-x11-268438b049218a5421d8ddaa2b1bc56cddb78dcd.tar.gz
utils-x11-268438b049218a5421d8ddaa2b1bc56cddb78dcd.tar.bz2
Session: ensure the programs wont be killed
Diffstat (limited to 'session')
-rwxr-xr-xsession44
1 files changed, 34 insertions, 10 deletions
diff --git a/session b/session
index aba9bc7..93db6c5 100755
--- a/session
+++ b/session
@@ -9,6 +9,7 @@ NAME="$0"
BASENAME="`basename $0`"
IGNORE="$HOME/.config/session-ignore"
+# Check if a given program is not being ignored by configuration
function __session_not_ignored {
if [ -z "$1" ]; then
return 1
@@ -25,6 +26,7 @@ function __session_not_ignored {
return 0
}
+# Query for program sessions
function __session_query {
# VIM
if __session_not_ignored vim && [ -e "$HOME/.local/share/vim/sessions" ]; then
@@ -62,6 +64,7 @@ function __session_query {
fi
}
+# List available sessions
function __session_list {
n="0"
__session_query | sort | uniq | while read session; do
@@ -121,6 +124,7 @@ function __session_list {
done | column -t -c 6 #| sed -e 's/^/\t/'
}
+# Session chooser mennu
function __session_chooser {
__session_list
read -rep "Choose session: " n
@@ -134,29 +138,44 @@ function __session_chooser {
fi
}
+# Run a program
+function __session_exec {
+ if [ -z "$1" ]; then
+ return
+ fi
+
+ # Ensure it won't be killed if parent exit
+ nohup setsid $* >> $HOME/.xsession-errors 2>&1 &
+
+ # Indicate that we should wait for the main script to wait
+ # while the program starts
+ SHOULD_SLEEP="5"
+}
+
+# Open a session
function __session_open {
SESSION="$1"
# Check VIM session
if __session_not_ignored vim && [ -e "$HOME/.local/share/vim/sessions/$SESSION.vim" ]; then
if which vim &> /dev/null; then
- terminal vim -S $HOME/.local/share/vim/sessions/$SESSION.vim &
+ __session_exec terminal vim -S $HOME/.local/share/vim/sessions/$SESSION.vim
fi
fi
# Check tmux session
if __session_not_ignored tmux && [ -e "$HOME/.tmux/$SESSION" ]; then
if which tmux &> /dev/null; then
- terminal shell $SESSION &
+ __session_exec terminal shell $SESSION
fi
fi
# Screen
- #if __session_not_ignored screen && [ -e "$HOME/.screen/$SESSION" ]; then
- # if which screen &> /dev/null; then
- # terminal shell $SESSION &
- # fi
- #fi
+ if __session_not_ignored screen && [ -e "$HOME/.screen/$SESSION" ]; then
+ if which screen &> /dev/null; then
+ __session_exec terminal wscreen $SESSION
+ fi
+ fi
# Luakit
# TODO: how to open luakit in a given session from the command line?
@@ -168,20 +187,20 @@ function __session_open {
# Qutebrowser
if __session_not_ignored qutebrowser && [ -d "$HOME/.local/share/qutebrowser/$SESSION" ]; then
if which qutebrowser &> /dev/null; then
- qutebrowser -r $SESSION
+ __session_exec qutebrowser -r $SESSION
fi
fi
# Chromium
if __session_not_ignored chromium && [ -d "$HOME/.config/chromium-profiles/$SESSION" ]; then
if which chromium-profile &> /dev/null; then
- chromium-profile $SESSION
+ __session_exec chromium-profile $SESSION
fi
fi
# Firefox
if __session_not_ignored firefox && [ -d "$HOME/.mozilla/firefox/profiles" ]; then
- firefox-profile $SESSION
+ __session_exec firefox-profile $SESSION
fi
}
@@ -205,3 +224,8 @@ elif [ -z "$1" ]; then
else
__session_open $*
fi
+
+# Check if we should wait programs to exec
+if [ ! -z "$SHOULD_SLEEP" ]; then
+ sleep $SHOULD_SLEEP
+fi