From 01848e1c8403021d4575cdb0784a0ce5ede920a8 Mon Sep 17 00:00:00 2001 From: Theoreticallyhugo Date: Sun, 2 Feb 2025 23:53:34 +0100 Subject: [PATCH 1/4] added max length feature to cwd. tested on macos --- scripts/cwd.sh | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/scripts/cwd.sh b/scripts/cwd.sh index 5da448c8..b74dc1fe 100755 --- a/scripts/cwd.sh +++ b/scripts/cwd.sh @@ -1,5 +1,8 @@ #!/usr/bin/env bash +current_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +source $current_dir/utils.sh + # return current working directory of tmux pane getPaneDir() { nextone="false" @@ -18,6 +21,20 @@ main() { # change '/home/user' to '~' cwd="${path/"$HOME"/'~'}" + # check max number of subdirs to display. 0 means unlimited + cwd_len=$(get_tmux_option "@dracula-cwd-length" "0") + + if [[ "$cwd_len" -gt 0 ]]; then + base_to_erase=$cwd + for ((i = 0 ; i < cwd_len ; i++)); do + base_to_erase="${base_to_erase%/*}" + done + # / would have #base_to_erase of 0 and ~/ has #base_to_erase of 1. we want to exclude both cases + if [[ ${#base_to_erase} -gt 1 ]]; then + cwd=${cwd:${#base_to_erase}+1} + fi + fi + echo "$cwd" } From c12590730a5d7eab689f9a985fdc40b703e23cae Mon Sep 17 00:00:00 2001 From: Theoreticallyhugo Date: Sat, 8 Feb 2025 10:22:06 +0100 Subject: [PATCH 2/4] fixed wrong home dir substitution --- scripts/cwd.sh | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/scripts/cwd.sh b/scripts/cwd.sh index b74dc1fe..932b259b 100755 --- a/scripts/cwd.sh +++ b/scripts/cwd.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash current_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -source $current_dir/utils.sh +source "$current_dir/utils.sh" # return current working directory of tmux pane getPaneDir() { @@ -18,20 +18,25 @@ getPaneDir() { main() { path=$(getPaneDir) + if [[ "$path" == "$HOME" ]]; then + echo "~" + exit 0 + fi + # change '/home/user' to '~' - cwd="${path/"$HOME"/'~'}" + cwd="${path/"${HOME}/"/'~/'}" # check max number of subdirs to display. 0 means unlimited - cwd_len=$(get_tmux_option "@dracula-cwd-length" "0") + cwd_max_dirs=$(get_tmux_option "@dracula-cwd-max-dirs" "0") - if [[ "$cwd_len" -gt 0 ]]; then + if [[ "$cwd_max_dirs" -gt 0 ]]; then base_to_erase=$cwd - for ((i = 0 ; i < cwd_len ; i++)); do + for ((i = 0 ; i < cwd_max_dirs ; i++)); do base_to_erase="${base_to_erase%/*}" done # / would have #base_to_erase of 0 and ~/ has #base_to_erase of 1. we want to exclude both cases if [[ ${#base_to_erase} -gt 1 ]]; then - cwd=${cwd:${#base_to_erase}+1} + cwd="…/${cwd:${#base_to_erase}+1}" fi fi From b473719ecb518edd35fe02be22a21afbfb75b809 Mon Sep 17 00:00:00 2001 From: Theoreticallyhugo Date: Sat, 8 Feb 2025 10:41:40 +0100 Subject: [PATCH 3/4] add max number of chars --- scripts/cwd.sh | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/scripts/cwd.sh b/scripts/cwd.sh index 932b259b..bdcfbdf8 100755 --- a/scripts/cwd.sh +++ b/scripts/cwd.sh @@ -16,7 +16,7 @@ getPaneDir() { } main() { - path=$(getPaneDir) + path="$(getPaneDir)" if [[ "$path" == "$HOME" ]]; then echo "~" @@ -27,7 +27,7 @@ main() { cwd="${path/"${HOME}/"/'~/'}" # check max number of subdirs to display. 0 means unlimited - cwd_max_dirs=$(get_tmux_option "@dracula-cwd-max-dirs" "0") + cwd_max_dirs="$(get_tmux_option "@dracula-cwd-max-dirs" "0")" if [[ "$cwd_max_dirs" -gt 0 ]]; then base_to_erase=$cwd @@ -40,6 +40,11 @@ main() { fi fi + cwd_max_chars="$(get_tmux_option "@dracula-cwd-max-chars" "0")" + if [[ "${#cwd}" -gt "$cwd_max_chars" ]]; then + cwd="…/…${cwd:(- cwd_max_chars)}" + fi + echo "$cwd" } From 42b3179a2076adb18915f4bfe8de7113722820f5 Mon Sep 17 00:00:00 2001 From: Theoreticallyhugo Date: Sat, 8 Feb 2025 10:49:19 +0100 Subject: [PATCH 4/4] fix max chars 0 was not unlimited default --- scripts/cwd.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/cwd.sh b/scripts/cwd.sh index bdcfbdf8..777d533d 100755 --- a/scripts/cwd.sh +++ b/scripts/cwd.sh @@ -41,7 +41,7 @@ main() { fi cwd_max_chars="$(get_tmux_option "@dracula-cwd-max-chars" "0")" - if [[ "${#cwd}" -gt "$cwd_max_chars" ]]; then + if [[ "${cwd_max_chars}" -gt 0 && "${#cwd}" -gt "$cwd_max_chars" ]]; then cwd="…/…${cwd:(- cwd_max_chars)}" fi