From 2d3132e87004273e0a9b66deeb9d7fdda645e5c5 Mon Sep 17 00:00:00 2001 From: Keegan Date: Mon, 22 Aug 2022 17:58:41 -0400 Subject: [PATCH] finally made it so tmux auto starts and formats on a hook --- bin/startup/lay_doormat.sh | 55 ++++++++++++++++++++++++++++ bin/startup/quote.sh | 3 +- bin/startup/tmux_start.sh | 42 ++++++++++++++++++++++ bin/startup/tmux_startup.sh | 71 ------------------------------------- tmux.conf | 3 ++ zshrc | 4 +-- 6 files changed, 102 insertions(+), 76 deletions(-) create mode 100755 bin/startup/lay_doormat.sh create mode 100755 bin/startup/tmux_start.sh delete mode 100755 bin/startup/tmux_startup.sh diff --git a/bin/startup/lay_doormat.sh b/bin/startup/lay_doormat.sh new file mode 100755 index 0000000..5de6bac --- /dev/null +++ b/bin/startup/lay_doormat.sh @@ -0,0 +1,55 @@ +#!/usr/bin/env bash + +set_greeting() { + # sets the TOD variable based on time of calling + cur_time=$(date +%H) # hour + # this control flow will be scuffed because I need to deal with early AM = evening + if [[ $cur_time -lt 4 || $cur_time -gt 17 ]] ; then + # between 5:00 pm and 4:00 am + Greeting="Evening" + elif [[ $cur_time -lt 12 ]] ; then + # between 4:00 am and 12:00 pm + Greeting="Morning" + else + Greeting="Afternoon" + fi +} + +format_doormat() { + # formats doormat on entry + + set_greeting # set $Greeting based on TOD + window="Good $Greeting" + + + + tmux select-window -t "$SESSION:0" + # creating a weather view on right quater + tmux split-window -h -p 25 + # creating quote area + tmux split-window -v -p 20 + # weather + tmux select-pane -t 1 + tmux send-keys 'c && curl --silent -fL https://wttr.in?Fn' C-m + # quote + tmux select-pane -t 2 + tmux send-keys 'c && quote.sh' C-m + + # creating a central vim pane taking up half the screen and a little box on the top left + tmux select-pane -t 0 + tmux split-window -h -p 66 + # opening vim + tmux select-pane -t 1 + tmux send-keys 'c && vim' C-m + # renaming based on TOD + tmux rename-window -t "$SESSION:0" "$window" + tmux set-hook -u -t $SESSION client-attached + +} + +eval "$(tmux_start.sh -s)" + +if [[ ! -z $SESSION ]] ; then + # session is set + format_doormat +fi diff --git a/bin/startup/quote.sh b/bin/startup/quote.sh index da82d63..e98f5c6 100755 --- a/bin/startup/quote.sh +++ b/bin/startup/quote.sh @@ -24,5 +24,4 @@ else fi get_qotd # sets quote and author -printf '\n"%s"\n - %s\n' "$quote" "$author" | fold -s - +printf '"%s"\n - %s\n' "$quote" "$author" | fold -s diff --git a/bin/startup/tmux_start.sh b/bin/startup/tmux_start.sh new file mode 100755 index 0000000..bb1f47d --- /dev/null +++ b/bin/startup/tmux_start.sh @@ -0,0 +1,42 @@ +#!/usr/bin/env bash + +print_output=false + +while getopts "s" arg; do + case $arg in + s) + print_output=true + ;; + esac +done + +SESSION="doormat" # welcom session name +START_SERVER=false + +set_session() { + # sets $SESSION variable to doormat + active_sessions=$(tmux list-sessions 2>/dev/null) + if [[ ! -z "$active_sessions" ]] ; then + # active sessions + session=$(echo "$active_sessions" | grep "$SESSION" | cut -d ':' -f 1 2>/dev/null) +# tmux doormat script + if [[ "$session" != "$SESSION" ]] ; then + # door mat doesn't exist + START_SERVER=true + fi + else + START_SERVER=true + fi + + if $START_SERVER ; then + # need to start server + tmux new-session -d -s "$SESSION" + tmux set-hook -t "$SESSION" client-attached 'run-shell ~/.dotfiles/bin/startup/lay_doormat.sh' + fi +} + +set_session + +if $print_output ; then + echo "SESSION=$SESSION" +fi diff --git a/bin/startup/tmux_startup.sh b/bin/startup/tmux_startup.sh deleted file mode 100755 index 2aef79f..0000000 --- a/bin/startup/tmux_startup.sh +++ /dev/null @@ -1,71 +0,0 @@ -#!/usr/bin/env bash - -set_greeting() { - # sets the TOD variable based on time of calling - cur_time=$(date +%H) # hour - # this control flow will be scuffed because I need to deal with early AM = evening - if [[ $cur_time -lt 4 || $cur_time -gt 17 ]] ; then - # between 5:00 pm and 4:00 am - Greeting="Evening" - elif [[ $cur_time -lt 12 ]] ; then - # between 4:00 am and 12:00 pm - Greeting="Morning" - else - Greeting="Afternoon" - fi -} - -lay_doormat(){ - # formats a tmux session stored under $session - set_greeting # set $Greeting based on TOD - window="Good $Greeting" - - tmux select-window -t $session:0 - # creating a weather view on right quater - tmux split-window -h -p 25 - tmux send-keys 'cd && clear && curl --silent -fL https://wttr.in?Fn' Enter - - # creating a central vim pane taking up half the screen and a little box on the top left - tmux select-pane -t 0 - tmux split-window -h -p 66 - tmux select-pane -t 0 - tmux split-window -v -p 90 - - # clearing bottom left - tmux select-pane -t 1 - tmux send-keys 'cd && clear' C-m - # writing quote to top left - tmux select-pane -t 0 - tmux send-keys 'cd && clear && ~/.dotfiles/bin/startup/quote.sh' Enter - # opening vim - tmux select-pane -t 2 - tmux send-keys 'cd && clear && vim' C-m - # renaming based on TOD - tmux rename-window -t $session:0 "$window" -} - -session="doormat" - - -if [[ ! tmuxhas-session -t $session 2>/d ]] ; then - # no server - tmux new-session -d -t "$session" - lay_doormat -else - # existing server - cur_session=$(tmux list-sessions 2>/dev/null | awk '{print $1}' | cut -d ":" -f 1) - if [[ "$cur_session" == "$session" ]] ; then - # check to see if window is set up - cur_window=$(tmux list-windows -t "$session" 2>/dev/null | grep Good) - if [[ -z $cur_window ]] ; then - # no window active - lay_doormat - #tmux -2 attach-session -t "$session" - fi - else - # doormat exists get window - tmux new-session -d -t "$session" - lay_doormat - fi -fi - diff --git a/tmux.conf b/tmux.conf index e40749f..5ad17a6 100644 --- a/tmux.conf +++ b/tmux.conf @@ -36,6 +36,9 @@ set -g @plugin 'tmux-plugins/tmux-continuum' set -g @continuum-save-interval 10 set -g @resurrect-capture-pane-contents 'on' set -g @resurrect-strategy-vim 'session' +set -g @continuum-boot 'on' +set -g @continuum-systemd-start-cmd 'new-session -d -s doormat' + # run tpm run '~/.tmux/plugins/tpm/tpm' diff --git a/zshrc b/zshrc index 313a1c6..c540bcb 100644 --- a/zshrc +++ b/zshrc @@ -150,6 +150,4 @@ alias water="$HOME/.dotfiles/bin/water/water.sh" # setting up location variables # source "$HOME/.dotfiles/bin/weather/location.sh" -# -# tmux doormat script -# source "$HOME/.dotfiles/bin/startup/tmux_startup.sh" +source "$HOME/.dotfiles/bin/startup/tmux_start.sh"