From 6fe855290f2d92ed91c165d2e6f925c12d21f901 Mon Sep 17 00:00:00 2001 From: jonathanforhan Date: Fri, 12 May 2023 13:35:49 -0400 Subject: [PATCH] fix bug with multi-word cwd --- scripts/cwd.sh | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/scripts/cwd.sh b/scripts/cwd.sh index cfae694..5da448c 100755 --- a/scripts/cwd.sh +++ b/scripts/cwd.sh @@ -1,29 +1,24 @@ #!/usr/bin/env bash # return current working directory of tmux pane -getPaneDir() -{ +getPaneDir() { nextone="false" - for i in $(tmux list-panes -F "#{pane_active} #{pane_current_path}"); - do - if [ "$nextone" == "true" ]; then - echo $i - return - fi - if [ "$i" == "1" ]; then - nextone="true" - fi + ret="" + for i in $(tmux list-panes -F "#{pane_active} #{pane_current_path}"); do + [ "$i" == "1" ] && nextone="true" && continue + [ "$i" == "0" ] && nextone="false" + [ "$nextone" == "true" ] && ret+="$i " done + echo "${ret%?}" } -main() -{ +main() { path=$(getPaneDir) # change '/home/user' to '~' - cwd=$(echo $path | sed "s;$HOME;~;g") + cwd="${path/"$HOME"/'~'}" - echo $cwd + echo "$cwd" } #run main driver program