Skip to content

Commit

Permalink
fixed wrong home dir substitution
Browse files Browse the repository at this point in the history
  • Loading branch information
Theoreticallyhugo committed Feb 8, 2025
1 parent 01848e1 commit c125907
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions scripts/cwd.sh
Original file line number Diff line number Diff line change
@@ -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() {
Expand All @@ -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

Expand Down

0 comments on commit c125907

Please sign in to comment.