(scripts) improved stability of tmux script
This commit is contained in:
@@ -1,7 +1,8 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
DEFAULT_SESSION='quak'
|
default_session='quak'
|
||||||
DUMMY_SESSION='dummy'
|
dummy_session='dummy'
|
||||||
|
temp_window='temp'
|
||||||
|
|
||||||
function create_default_session {
|
function create_default_session {
|
||||||
if [[ -n "$TMUX" ]]; then
|
if [[ -n "$TMUX" ]]; then
|
||||||
@@ -13,31 +14,45 @@ function create_default_session {
|
|||||||
# check if the default session exists
|
# check if the default session exists
|
||||||
# redirect stderr to /dev/null because `session not found` is
|
# redirect stderr to /dev/null because `session not found` is
|
||||||
# not a relevant error in this case
|
# not a relevant error in this case
|
||||||
if $(tmux has-session -t ${DEFAULT_SESSION} 2>/dev/null); then
|
if $(tmux has-session -t ${default_session} 2>/dev/null); then
|
||||||
# return success so the external attach command is run
|
# return success so the external attach command is run
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# check repository paths
|
||||||
|
if [[ -d "${HOME}/repositories" ]]; then
|
||||||
|
path_repositories="${HOME}/repositories"
|
||||||
|
fi
|
||||||
|
if [[ -d "${HOME}/dotfiles" ]]; then
|
||||||
|
path_dotfiles="${HOME}/dotfiles"
|
||||||
|
elif [[ -n "${path_repositories}" ]] && [[ -d "${path_repositories}/dotfiles" ]]; then
|
||||||
|
path_dotfiles="${path_repositories}/dotfiles"
|
||||||
|
fi
|
||||||
|
if [[ -d "${HOME}/collection" ]]; then
|
||||||
|
path_documentation="${HOME}/collection"
|
||||||
|
elif [[ -n "${path_repositories}" ]] && [[ -d "${path_repositories}/collection" ]]; then
|
||||||
|
path_documentation="${path_repositories}/collection"
|
||||||
|
fi
|
||||||
|
|
||||||
# start dummy session to avoid error messages on `has-session`
|
# start dummy session to avoid error messages on `has-session`
|
||||||
tmux new-session -d -s "$DUMMY_SESSION"
|
tmux new-session -d -s "${dummy_session}"
|
||||||
|
|
||||||
# dont forget the '-d' option, otherwise the session is closed
|
# dont forget the '-d' option, otherwise the session is closed
|
||||||
# before the rest of the commands are executed
|
# before the rest of the commands are executed
|
||||||
tmux new-session -d -s "$DEFAULT_SESSION" -n "temp" -c "$HOME" # create dummy window to set default path for new windows
|
tmux new-session -d -s "${default_session}" -n "${temp_window}" -c "${HOME}" # create dummy window to set default path for new windows
|
||||||
tmux new-window -t "$DEFAULT_SESSION" -n "dotfiles" -c "$HOME/dotfiles"
|
tmux new-window -t "${default_session}" -n "dotfiles" -c "${path_dotfiles}"
|
||||||
tmux new-window -t "$DEFAULT_SESSION" -n "docs" -c "$HOME/collection"
|
tmux new-window -t "${default_session}" -n "docs" -c "${path_documentation}"
|
||||||
tmux new-window -t "$DEFAULT_SESSION" -n "stuff" -c "$HOME"
|
tmux new-window -t "${default_session}" -n "stuff" -c "${HOME}"
|
||||||
tmux kill-window -t "temp"
|
tmux kill-window -t "${temp_window}"
|
||||||
|
|
||||||
# this causes the script to exit only, when the session is ended or detached
|
## NOTE: this causes the script to exit only, when the session is ended
|
||||||
# it also causes tmux's detach command with hang up signal to fail
|
## or detached.
|
||||||
# therefore the following line is commented out
|
## it also causes tmux's detach command with hang up signal to fail,
|
||||||
# an `alias` is created in `.bashrc` which calls this script and runs
|
## therefore the following line is commented out and an `alias` is
|
||||||
# `tmux attach` on successful execution
|
## created in `.bashrc`, which runs this script and `tmux attach`
|
||||||
|
#tmux attach -t "${DEFAULT_SESSION}"
|
||||||
|
|
||||||
#tmux attach -t "$DEFAULT_SESSION"
|
tmux kill-session -t "${dummy_session}"
|
||||||
|
|
||||||
tmux kill-session -t "$DUMMY_SESSION"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
create_default_session
|
create_default_session
|
||||||
|
|||||||
Reference in New Issue
Block a user