Skip to content

Instantly share code, notes, and snippets.

@archenemies
Created November 11, 2015 15:03
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 archenemies/845fbfe2cca3026842fd to your computer and use it in GitHub Desktop.
Save archenemies/845fbfe2cca3026842fd to your computer and use it in GitHub Desktop.
# list files grouped by extension, and sorted in reverse chronological
# order, mostly
function dc () {
local dir=${1:-.}
local FIRST=1;
local d_;
local l_;
local files;
local exts;
local extfiles;
local extorder;
(cd $dir
IFS="
"
# d_=(ls --color=always -rtc)
# ls_='[[ "$#l" > 0 ]] && { [[ $FIRST -eq 0 ]] && {perl -le "print \"-\"x$COLUMNS"} || FIRST=0 } && $d_ -d $l'
files=(*~(*~)(N))
files=(${files:#\#*\#})
files=($(ls -tcd1 $files))
_lsgroup () {
if [[ "$#l" > 0 ]]; then
{ [[ $FIRST -eq 0 ]] &&
{perl -le "print \"-\"x$COLUMNS"} || FIRST=0 }
# only list files not already listed
# l=($(print -l $l | grep -Ff <(print -l $files)))
# llua@#zsh says: use l=( "${(@)l:*files}" ), this only
# makes a difference if there is an empty string in one
# of the arrays
l=(${l:*files})
ls --color=always -rtcd $l
# remove elements of l from $files
# files=($(print -l $files | grep -vFf <(print -l $l)))
files=(${files:|l})
fi
}
exts=($(print -l ${${(M)files:#*.*}##*.} | sort -u))
# echo exts=$exts
extfiles=(${(M)files:#*.*})
# echo extfiles=$extfiles
extorder=()
while [[ $#extfiles -gt 0 ]]; do
f=$extfiles[1];
ext=${f##*.}
extorder+=$ext
extfiles=(${extfiles:#*.$ext})
done
for ext in ${(Oa)extorder}; do
# l=(${(M)files:#*.$ext})
l=(*.$ext(N))
# files=(${files:#*.$ext})
# eval $ls_
_lsgroup
done
# l=($files)
# eval $ls_
l=(*~(*~)(*N))
_lsgroup
# l=($(print -l *~(*~)(*N) | grep -Ff <(print -l $files)));
# eval $ls_
# l=($(print -l *(/N) | grep -Ff <(print -l $files)));
l=(*(/N));
_lsgroup
# eval $ls_
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment