Skip to content

Commit c125907

Browse files
committedFeb 8, 2025
fixed wrong home dir substitution
1 parent 01848e1 commit c125907

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed
 

‎scripts/cwd.sh

+11-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env bash
22

33
current_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
4-
source $current_dir/utils.sh
4+
source "$current_dir/utils.sh"
55

66
# return current working directory of tmux pane
77
getPaneDir() {
@@ -18,20 +18,25 @@ getPaneDir() {
1818
main() {
1919
path=$(getPaneDir)
2020

21+
if [[ "$path" == "$HOME" ]]; then
22+
echo "~"
23+
exit 0
24+
fi
25+
2126
# change '/home/user' to '~'
22-
cwd="${path/"$HOME"/'~'}"
27+
cwd="${path/"${HOME}/"/'~/'}"
2328

2429
# check max number of subdirs to display. 0 means unlimited
25-
cwd_len=$(get_tmux_option "@dracula-cwd-length" "0")
30+
cwd_max_dirs=$(get_tmux_option "@dracula-cwd-max-dirs" "0")
2631

27-
if [[ "$cwd_len" -gt 0 ]]; then
32+
if [[ "$cwd_max_dirs" -gt 0 ]]; then
2833
base_to_erase=$cwd
29-
for ((i = 0 ; i < cwd_len ; i++)); do
34+
for ((i = 0 ; i < cwd_max_dirs ; i++)); do
3035
base_to_erase="${base_to_erase%/*}"
3136
done
3237
# / would have #base_to_erase of 0 and ~/ has #base_to_erase of 1. we want to exclude both cases
3338
if [[ ${#base_to_erase} -gt 1 ]]; then
34-
cwd=${cwd:${#base_to_erase}+1}
39+
cwd="…/${cwd:${#base_to_erase}+1}"
3540
fi
3641
fi
3742

0 commit comments

Comments
 (0)