From ce18a33847d49a867c7f63d364f252aecb8831aa Mon Sep 17 00:00:00 2001 From: Shulhan Date: Sat, 5 Apr 2025 16:46:48 +0700 Subject: bin/tmux-session.sh: check for comment and empty line If the line in .tmux.session file is empty or start with "#", skip it. Also, split the line into array and read only the first column for name and second column for directory, which allow the rest of line as comment. --- bin/tmux-session.sh | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/bin/tmux-session.sh b/bin/tmux-session.sh index 774e64b..d12aafa 100755 --- a/bin/tmux-session.sh +++ b/bin/tmux-session.sh @@ -11,8 +11,8 @@ ## ## name-1 directory ## name-2 directory -## ... -## name-n directory +## # comment +## name-n directory # inline comment ## ## Where name is unique string between each line, and directory is a path to ## directory where session will started. @@ -33,9 +33,16 @@ fi echo "searching for $SESS_NAME ..." { - while read name dir; do - if [[ "$SESS_NAME" == "$name" ]]; then - SESS_DIR=$dir + while read line; do + if [[ -z "$line" ]]; then + continue + fi + if [[ "$line" =~ ^#.* ]]; then + continue + fi + session=($line) + if [[ "$SESS_NAME" == "${session[0]}" ]]; then + SESS_DIR="${session[1]}" break fi done -- cgit v1.3