-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrecently
executable file
·48 lines (42 loc) · 1.56 KB
/
recently
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/usr/bin/env fish
# recently - Recursively list the contents of this directory in modification order, most recent first.
set -- script "$(path basename (status filename))"
argparse -n "$script" 'h/help' 'e/exclude=+' -- $argv
if set -q _flag_h
echo "$script - Recursively list the contents of this directory in modification order, most recent first."
echo "Usage: $script [find-arguments]"
echo
echo " -h/--help - Print help and exit."
echo " -e/--exclude - Exclude a directory."
exit
end
if command -qs bfs
set find bfs
set -e extra_args
# set extra_args "-color" # FIX: this is broken right now. only provide this argument when we know we're not being piped to another command.
else
set find find
set extra_args ""
end
if set -q _flag_e
set -l path_flag
for path in $_flag_e
set path (string replace (pwd) '.' (path resolve "$path"))
if string match --quiet '/*' "$path"
echo "$script: --exclude must specify a directory within the current ($(pwd))." >&2
exit 1
end
if not string match --quiet './*' "$path"
set path "./$path"
end
set path (string trim -c '/*' "$path")'/*'
set -a -- path_flag -path "$path" -or
end
set -- exclude_args -not \( $path_flag[..-2] -prune \)
end
# %T@ = file's last modification time in seconds since Jan 1 1970, with fractional part
# %p = file's name.
command $find . $exclude_args $argv $extra_args -type f -printf '%T@ %p\n' |
sort -k 1 -n |
string match --regex --groups-only '^\\S+\\s+(.+)$' |
tac