From 268438b049218a5421d8ddaa2b1bc56cddb78dcd Mon Sep 17 00:00:00 2001 From: Silvio Rhatto Date: Thu, 8 Mar 2018 10:57:39 -0300 Subject: Session: ensure the programs wont be killed --- session | 44 ++++++++++++++++++++++++++++++++++---------- 1 file 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 -- cgit v1.2.3