Skip to content

Instantly share code, notes, and snippets.

@zchee
Forked from yonchu/chpwd_for_zsh.sh
Last active August 29, 2015 14:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zchee/99a17b8f6e18ca433c68 to your computer and use it in GitHub Desktop.
Save zchee/99a17b8f6e18ca433c68 to your computer and use it in GitHub Desktop.
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