-
-
Save zchee/7250f0a027e5a7f042af 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 ignore entries starting with .. | |
# -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') | |
case "${OSTYPE}" in | |
freebsd*|darwin*) | |
if type gls > /dev/null 2>&1; then | |
cmd_ls='gls' | |
else | |
# -G : Enable colorized output. | |
opt_ls=('-aCFG') | |
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