-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdirdiff
executable file
·80 lines (67 loc) · 2.72 KB
/
dirdiff
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#!/usr/bin/env fish
# dirdiff - List files that only exist in one of the two specified dirs.
# This script supports comparing directories over SSH, i.e.: dirdiff /path/to/dir host:/path/to/dir
set -- script "$(path basename (status filename))"
argparse -n "$script" 'h/help' 'a/only-a' 'b/only-b' 'B/both' 'd/maxdepth=' 'ignore=+' -- $argv
if set -q _flag_h
echo "$script - List files that only exist in one of the two specified dirs."
echo "Usage: $script [arguments] directory-a directory-b"
echo
echo " -h/--help - Print help and exit."
echo " -a/--only-a - Print only the items in directory A that aren't in B."
echo " -b/--only-b - Print only the items in directory B that aren't in A."
echo " -B/--both - Print only the items that appear in both directories."
echo " -d/--maxdepth - Set the maximum directory depth to recurse into. Equivalent to find's -maxdepth argument."
echo " -i/--ignore - Specify files to ignore (this argument can be provided multiple times)."
exit
end
set dir_a $argv[1]
set dir_b $argv[2]
set find_flags
if set -q _flag_d
set -a find_flags -maxdepth "$_flag_d"
end
if set -q _flag_i
set ignore $_flag_i
end
function note -d "Echo a note to stderr."
warn -t $script -l info $argv[1]
end
function get-files -d "Get the list of files. If a directory is provided, get a list of the files in that directory. If a filename is provided, read the lines of that file and use them as the list of files."
set -l input (path resolve $argv[1])
if test -d $input
set -l -- not_args -not \( (for ig in $ignore; printf '-name\n%s\n' $ig; end) \)
find $input $find_flags -not -wholename $input -not -path "*/.git/*" -not -name '.git' (if test (count $not_args) -gt 3; printf '%s\n' %not_args; end) | string replace --regex '^'(string escape --style=regex "$input" | string trim --chars '/' --right)'/' ''
else if test -f $input
xargs -a $input -d '\n' basename
else if string match '*:*' $input
string match -qr '(?<host>[^:]+):(?<directory>.+)' $input
ssh -o PermitLocalCommand=no -o ClearAllForwardings=yes $host "find $directory $find_flags -exec basename {} \\;" 2>/dev/null
end
end
set dir_a_files (get-files $dir_a)
set dir_b_files (get-files $dir_b)
if set -q _flag_B
note "In both directories:"
for i in $dir_a_files
if contains $i $dir_b_files
echo $i
end
end
end
if set -q _flag_a
note "Only in $dir_a:"
for i in $dir_a_files
if not contains $i $dir_b_files
echo $i
end
end
end
if set -q _flag_b
note "Only in $dir_b:"
for i in $dir_b_files
if not contains $i $dir_a_files
echo $i
end
end
end