Skip to content

Commit

Permalink
added max length feature to cwd. tested on macos
Browse files Browse the repository at this point in the history
  • Loading branch information
Theoreticallyhugo committed Feb 2, 2025
1 parent dd1a7ab commit 01848e1
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions scripts/cwd.sh
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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"
}

Expand Down

0 comments on commit 01848e1

Please # to comment.