From 75400b59d7691574cd5733c90d1f487a37b30d84 Mon Sep 17 00:00:00 2001 From: scbj Date: Thu, 20 Nov 2025 08:58:31 +0100 Subject: [PATCH] (scripts) fixed minor annoynances --- scripts/default-tmux-session.sh | 32 +++++++++++++++++++++----------- scripts/fzf-bash-history.sh | 2 ++ 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/scripts/default-tmux-session.sh b/scripts/default-tmux-session.sh index aa2550a..294c3a4 100755 --- a/scripts/default-tmux-session.sh +++ b/scripts/default-tmux-session.sh @@ -3,16 +3,24 @@ DEFAULT_SESSION='quak' DUMMY_SESSION='dummy' -# start dummy session to avoid error messages on `has-session` -tmux new-session -d -s "$DUMMY_SESSION" +function create_default_session { + if [[ -n "$TMUX" ]]; then + echo "already attached to a session. don't nest tmux sessions" + # return failure so the external attach command is not run + return 1 + fi + + # check if the default session exists + # redirect stderr to /dev/null because `session not found` is + # not a relevant error in this case + if $(tmux has-session -t ${DEFAULT_SESSION} 2>/dev/null); then + # return success so the external attach command is run + return 0 + fi + + # start dummy session to avoid error messages on `has-session` + tmux new-session -d -s "$DUMMY_SESSION" -# check if the default session exists -# redirect stderr to /dev/null because `session not found` is -# not a relevant error in this case -if $(tmux has-session -t ${DEFAULT_SESSION} 2>/dev/null); then - echo "default session <${DEFAULT_SESSION}> already exists" - # no action needed if the session exists, the attach command is run externally -else # dont forget the '-d' option, otherwise the session is closed # 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 @@ -28,6 +36,8 @@ else # `tmux attach` on successful execution #tmux attach -t "$DEFAULT_SESSION" -fi -tmux kill-session -t "$DUMMY_SESSION" + tmux kill-session -t "$DUMMY_SESSION" +} + +create_default_session diff --git a/scripts/fzf-bash-history.sh b/scripts/fzf-bash-history.sh index e795e16..d9aab56 100644 --- a/scripts/fzf-bash-history.sh +++ b/scripts/fzf-bash-history.sh @@ -1,5 +1,7 @@ #!/usr/bin/env bash +[[ "$-" != "*i*" ]] || return + function __search-history { current_line="${READLINE_LINE}" command=($(fc -lnr 1 | fzf --scheme=history --tmux --expect=tab,right -q "${current_line}"))