-
-
Save zchee/99a17b8f6e18ca433c68 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
chpwd() { | |
ls_abbrev | |
} | |
ls_abbrev() { | |
# -A : Do not show . and .. | |
# -C : Force multi-column output. | |
# -F : Append indicator (one of */=>@|) to entries.\ | |
local cmd_ls='ls' | |
local -a opt_ls | |
opt_ls=('-ACF' '--color=always' '--ignore=.DS_Store') | |
case "${OSTYPE}" in | |
freebsd*|darwin*) | |
if type gls > /dev/null 2>&1; then | |
cmd_ls='gls' | |
else | |
# -G : Enable colorized output. | |
opt_ls=('-ACGF --ignore=.DS_Store') | |
fi | |
;; | |
esac | |
local ls_result | |
ls_result=$(CLICOLOR_FORCE=1 COLUMNS=$COLUMNS command $cmd_ls ${opt_ls[@]} | sed $'/^\e\[[0-9;]*m$/d') | |
local ls_lines=$(echo "$ls_result" | wc -l | tr -d ' ') | |
if [ $ls_lines -gt 10 ]; then | |
echo "$ls_result" | head -n 5 | |
echo '...' | |
echo "$ls_result" | tail -n 5 | |
echo "$(command ls -1 -A | wc -l | tr -d ' ') files exist" | |
else | |
echo "$ls_result" | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment