Skip to content
This repository has been archived by the owner on Feb 3, 2021. It is now read-only.

Commit

Permalink
Allow for configuring truncate size
Browse files Browse the repository at this point in the history
  • Loading branch information
matchai committed Feb 6, 2018
1 parent 96a0f60 commit 5a6b489
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
5 changes: 2 additions & 3 deletions functions/__sf_section_dir.fish
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ function __sf_section_dir
__sf_util_set_default SPACEFISH_DIR_SHOW true
# __sf_util_set_default SPACEFISH_DIR_PREFIX "in "
__sf_util_set_default SPACEFISH_DIR_SUFFIX $SPACEFISH_PROMPT_DEFAULT_SUFFIX
# __sf_util_set_default SPACEFISH_DIR_TRUNC 3
__sf_util_set_default SPACEFISH_DIR_TRUNC 3
__sf_util_set_default SPACEFISH_DIR_TRUNC_REPO true
__sf_util_set_default SPACEFISH_DIR_COLOR (set_color --bold cyan)

Expand All @@ -32,8 +32,7 @@ function __sf_section_dir
else
set -l realhome ~
set -l tmp (string replace -r '^'"$realhome"'($|/)' '~$1' $PWD)
# TODO: Use $SPACEFISH_DIR_TRUNC to change truncation length
set dir (string replace -r '^.+/(.+/.+/.+)' '$1' $tmp)
set dir (__sf_util_truncate_dir $tmp $SPACEFISH_DIR_TRUNC)
end

echo -e -n -s \
Expand Down
13 changes: 13 additions & 0 deletions functions/__sf_util_truncate_dir.fish
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
function __sf_util_truncate_dir -d "Truncate a directory path" -a path truncate_to
if test $truncate_to -eq 0
echo $path
else
set -l folders (string split / $path)

if test (count $folders) -le $truncate_to
echo $path
else
echo (string join / $folders[(math 0 - $truncate_to)..-1])
end
end
end

0 comments on commit 5a6b489

Please sign in to comment.