Created
November 11, 2015 15:56
-
-
Save archenemies/7b51ef6fb061b0738df1 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
# list files grouped by extension, and sorted in reverse chronological | |
# order, mostly | |
function dc () { | |
local dir=${1:-.} | |
local FIRST=1; | |
local l f files exts extfiles extorder; | |
(cd $dir | |
IFS=" | |
" | |
files=(*~(*~)(N)) | |
files=(${files:#\#*\#}) | |
files=($(ls -tcd1 $files)) | |
# list a group of files, printing a --- separator after the | |
# first call. restrict to contents of $files, and remove our | |
# output from $files afterwards | |
_lsgroup () { | |
# zsh array expansion is much faster than grep -Ff | |
# llua@#zsh says: use l=( "${(@)l:*files}" ) (but this only | |
# makes a difference if there is an empty string in one of | |
# the arrays) | |
# filter $l through $files | |
l=(${l:*files}) | |
# remove elements of $l from $files | |
files=(${files:|l}) | |
if [[ "$#l" > 0 ]]; then | |
{ [[ $FIRST -eq 0 ]] && | |
{perl -le "print \"-\"x$COLUMNS"} || FIRST=0 } | |
ls --color=always -rtcd $l | |
fi | |
} | |
# make a list of extensions, in order of most recently appearing | |
# first. TODO: remove extensions with odd characters, which may | |
# not actually be extensions | |
extfiles=(${(M)files:#*.*}) | |
dirs=(*(-/N)) # remove directories from extension list | |
extfiles=(${extfiles:|dirs}) | |
extorder=() | |
while [[ $#extfiles -gt 0 ]]; do | |
f=$extfiles[1]; | |
ext=${f##*.} | |
extorder+=$ext | |
extfiles=(${extfiles:#*.$ext}) | |
done | |
# now display files with each extension in our list | |
for ext in ${(Oa)extorder}; do | |
l=(*.$ext(N-^/)) # exclude directories | |
_lsgroup | |
done | |
# files with no extension, not matching next two groups | |
rest=(*(-*N) *(-/N)) | |
l=(${files:|rest}) | |
_lsgroup | |
# executables (- means dereference symlinks) | |
l=(*(-*N)) | |
_lsgroup | |
# directories | |
l=(*(-/N)); | |
_lsgroup | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Produces output like this: