Skip to content

Commit 01848e1

Browse files
added max length feature to cwd. tested on macos
1 parent dd1a7ab commit 01848e1

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

scripts/cwd.sh

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
#!/usr/bin/env bash
22

3+
current_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
4+
source $current_dir/utils.sh
5+
36
# return current working directory of tmux pane
47
getPaneDir() {
58
nextone="false"
@@ -18,6 +21,20 @@ main() {
1821
# change '/home/user' to '~'
1922
cwd="${path/"$HOME"/'~'}"
2023

24+
# check max number of subdirs to display. 0 means unlimited
25+
cwd_len=$(get_tmux_option "@dracula-cwd-length" "0")
26+
27+
if [[ "$cwd_len" -gt 0 ]]; then
28+
base_to_erase=$cwd
29+
for ((i = 0 ; i < cwd_len ; i++)); do
30+
base_to_erase="${base_to_erase%/*}"
31+
done
32+
# / would have #base_to_erase of 0 and ~/ has #base_to_erase of 1. we want to exclude both cases
33+
if [[ ${#base_to_erase} -gt 1 ]]; then
34+
cwd=${cwd:${#base_to_erase}+1}
35+
fi
36+
fi
37+
2138
echo "$cwd"
2239
}
2340

0 commit comments

Comments
 (0)