Last active
June 14, 2018 11:13
-
-
Save norpol/1ff30f0f614c38dccfabb4f9f62a73e6 to your computer and use it in GitHub Desktop.
chpwd ls improvement
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
# Put this into your ~/.zshrc | |
# Enables chpwd, which runs a command if you cd/pushd/popd... | |
# wrapper around ls, which ommits output if more than 1/3 of screen would be used | |
# Demo https://asciinema.org/a/123167 | |
ls_reduced() { | |
files="$(ls -tr --color=always -- "$(pwd)")" | |
lines="$(printf -- "%b" "${files}" | wc -l)" | |
term_height="$(tput lines)" | |
term_target_height="$((term_height/3))" | |
lines_ommited="$((lines-term_target_height))" | |
if [ "${lines}" -gt "${term_target_height}" ]; then | |
printf -- "%b" "${files}\n─ Ommited ${lines_ommited} additional lines ─\n" | tail -${term_target_height} | |
else | |
printf -- "%b" "${files}\n" | |
fi | |
} | |
chpwd() { ls_reduced; } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment