Upgrade yt-dlp from version `stable@2024.05.27` to `stable@2024.07.09`
[sunny256-utils.git] / strip-nonexisting
blob610e286569c27c1af43ec0e2de5140e23f1c756c
1 #!/bin/sh
3 #==============================================================================
4 # strip-nonexisting
5 # File ID: 89302bf2-f33a-11e4-a2d5-000df06acc56
7 # Read a stream of \n-separated filenames from stdin and remove
8 # everything that's not plain files or symlinks that exist locally.
10 # Author: Øyvind A. Holm <sunny@sunbase.org>
11 # License: GNU General Public License version 2 or later.
12 #==============================================================================
14 progname=strip-nonexisting
15 VERSION=0.2.0
17 opt_help=0
18 opt_quiet=0
19 opt_verbose=0
20 while :; do
21 case "$1" in
22 -h|--help) opt_help=1; shift ;;
23 -q|--quiet) opt_quiet=$(($opt_quiet + 1)); shift ;;
24 -v|--verbose) opt_verbose=$(($opt_verbose + 1)); shift ;;
25 --version) echo $progname $VERSION; exit 0 ;;
26 --) shift; break ;;
28 if printf '%s\n' "$1" | grep -q ^-; then
29 echo "$progname: $1: Unknown option" >&2
30 exit 1
31 else
32 break
34 break ;;
35 esac
36 done
37 opt_verbose=$(($opt_verbose - $opt_quiet))
39 if test "$opt_help" = "1"; then
40 test $opt_verbose -gt 0 && { echo; echo $progname $VERSION; }
41 cat <<END
43 Read a stream of \\n-separated filenames from stdin and remove
44 everything that's not plain files or symlinks that exist locally.
46 Can be used with git-annex, for example:
48 git log --raw --since=1.week "\$@" | grep ^: | cut -f 2 | sort -u | \\
49 strip-nonexisting | xargs -d \\\\n git annex fsck --quiet
51 will run a "git annex fsck --quiet" on every file added less than one
52 week ago. git annex will refuse to run if it receives any invalid paths,
53 and that's ok.
55 Only files or symlinks will be listed. Everything else (directories,
56 fifos, device files, etc) is removed.
58 Usage: $progname [options]
60 Options:
62 -h, --help
63 Show this help.
64 -q, --quiet
65 Be more quiet. Can be repeated to increase silence.
66 -v, --verbose
67 Increase level of verbosity. Can be repeated.
68 --version
69 Print version information.
71 END
72 exit 0
75 while read f; do
76 test -f "$f" -o -L "$f" && echo "$f"
77 done
79 # vim: set ts=8 sw=8 sts=8 noet fo+=w tw=79 fenc=UTF-8 :