Skip to content

Instantly share code, notes, and snippets.

@artem-bez
Last active December 15, 2015 12:39
Show Gist options
  • Select an option

  • Save artem-bez/d2a7dc2b15a7239c1be9 to your computer and use it in GitHub Desktop.

Select an option

Save artem-bez/d2a7dc2b15a7239c1be9 to your computer and use it in GitHub Desktop.
After changing working directory print directory listing if terminal is big enough to fit it, otherwise print $MOST_RECENT_LEN recently modified entries.
MOST_RECENT_LEN=20
function chpwd {
if [[ $(ls --format=vertical -w ${COLUMNS} | wc -l) -lt $((LINES - 1)) ]] {
ls
} else {
echo $(find . -maxdepth 1 | wc -l) entries. \
Showing $MOST_RECENT_LEN most recent \(ctime\)
ls -c | head -n$MOST_RECENT_LEN
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment