-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfind-broken-symlinks
executable file
·50 lines (43 loc) · 1.55 KB
/
find-broken-symlinks
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
#!/usr/bin/env fish
# find-broken-symlinks - Get a list of symlinks whose target does not exist.
# This is basically just an easier-to-remember alias for `find -xtype l`.
argparse -n find-broken-symlinks 'h/help' 'd/directory=' 'e/exclude=+' -- $argv
if set -q _flag_h
echo "find-broken-symlinks - Get a list of symlinks whose target does not exist."
echo "Usage: find-broken-symlinks [arguments] [directory]"
echo
echo " -h/--help - Print help and exit."
echo " -d/--directory - Specify the directory to recursively search in (default: current directory)."
echo " -e/--exclude - Exclude a directory."
exit
end
set directory '.'
if set -q _flag_d
set directory "$_flag_d"
else if test (count $argv) -gt 0
if not string match -- '-*' "$argv[1]"
set directory "$argv[1]"
set argv $argv[2..]
end
end
if not test -d "$directory"
echo "$(status filename): Directory $directory does not exist."
exit 1
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
find "$directory" $exclude_args -xtype l $argv