Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit e54d6da

Browse files
committedApr 16, 2015
[zsh] Shorten _truncated_ls by using more builtins
- Fixed off-by-one issue with _right_align, causing a remaining space at the right-most side. - Avoid `wc -m` by using ${#var} syntax - Avoid the loop in _right_align by using printf - Use herestrings to avoid calls to `echo -E` - There shouldn't ever be more than 3 forks caused by running `cd` now. Hopefully this should keep cd from hanging for a second when my machine is under heavy load.
1 parent 1f3df2a commit e54d6da

File tree

1 file changed

+4
-8
lines changed

1 file changed

+4
-8
lines changed
 

Diff for: ‎zsh/commands/filesystem.zsh

+4-8
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,10 @@ _truncated_ls() {
5050
--format=across \
5151
--color=always \
5252
--width=$COLUMNS)"
53-
local RAW_LS_LINES="$(builtin echo -E "$RAW_LS_OUT" | wc -l)"
53+
local RAW_LS_LINES="$(command wc -l <<< "$RAW_LS_OUT")"
5454

5555
if [[ $RAW_LS_LINES -gt $LS_LINES ]]; then
56-
builtin echo -E "$RAW_LS_OUT" | head -n $(($LS_LINES - 1))
56+
command head -n $(($LS_LINES - 1)) <<< "$RAW_LS_OUT"
5757
_right_align "... $(($RAW_LS_LINES - $LS_LINES + 1)) lines hidden"
5858
else
5959
builtin echo -E "$RAW_LS_OUT"
@@ -62,12 +62,8 @@ _truncated_ls() {
6262

6363
# right align text and echo it; helper function for _truncated_ls
6464
_right_align() {
65-
local PADDING=$(($COLUMNS - $(builtin echo "$1" | wc -m)))
66-
if [[ $PADDING -gt 0 ]]; then
67-
for i in {1..$PADDING}; do
68-
builtin echo -n " "
69-
done
70-
fi
65+
local PADDING=$(($COLUMNS - ${#1}))
66+
[[ $PADDING -gt 0 ]] && builtin printf "%${PADDING}s"
7167
builtin echo "$1"
7268
}
7369

0 commit comments

Comments
 (0)
Please sign in to comment.