Files
omarchy/dot_local/bin/executable_mtime-sort
T
Prad Nukala b18729f4a0 Initial import: chezmoi source for Omarchy (Hyprland)
Imported from prdlk/dotfiles master (efdd827), which supersedes the omarchy
branch (3031416). Drops the Umbriel, Noctalia, niri, CachyOS, macOS, and Blume
docs-site layers; docs/ is plain Markdown.
2026-11-02 09:14:11 -05:00

25 lines
1012 B
Bash
Executable File

#!/bin/sh
# Sort stdin lines newest-first by mtime — the base order of the television
# cables (tv then layers match quality and frecency on top).
#
# The path is each line's last tab-separated field (the whole line when it
# has no tab). With --repo, <path>/.git/index is stat'ed first, so a repo
# ranks by its last git activity rather than its directory mtime. Lines whose
# path does not exist are dropped; ties keep their input order.
#
# Usage: <lines> | mtime-sort [--repo]
exec perl -e '
my $repo = @ARGV && $ARGV[0] eq "--repo";
my ($i, @rows) = (0);
while (my $line = <STDIN>) {
chomp $line;
my $path = (split /\t/, $line)[-1];
next unless defined $path && length $path;
my $mtime;
$mtime = (stat "$path/.git/index")[9] if $repo;
$mtime = (stat $path)[9] unless defined $mtime;
push @rows, [$mtime, $i++, $line] if defined $mtime;
}
print "$_->[2]\n" for sort { $b->[0] <=> $a->[0] || $a->[1] <=> $b->[1] } @rows;
' -- "$@"