std/c/: Delete the old Perl tests in src/t/, 0:84
[sunny256-utils.git] / list-extensions
blob9fb0f67a858e16c23cf517eff8edce28e3db8f5b
1 #!/usr/bin/env bash
3 #=======================================================================
4 # list-extensions
5 # File ID: eeac3f34-031b-11e5-aec1-2330d30b8995
7 # Read filenames or paths from stdin and output a list of used
8 # extensions, sorted by frequency.
10 # Author: Øyvind A. Holm <sunny@sunbase.org>
11 # License: GNU General Public License version 2 or later.
12 #=======================================================================
14 progname=list-extensions
15 VERSION=0.3.0
17 ARGS="$(getopt -o "\
22 " -l "\
23 help,\
24 ignore-case,\
25 quiet,\
26 verbose,\
27 version,\
28 " -n "$progname" -- "$@")"
29 test "$?" = "0" || exit 1
30 eval set -- "$ARGS"
32 opt_help=0
33 opt_ignore_case=0
34 opt_quiet=0
35 opt_verbose=0
36 while :; do
37 case "$1" in
38 -h|--help) opt_help=1; shift ;;
39 -i|--ignore-case) opt_ignore_case=1; shift ;;
40 -q|--quiet) opt_quiet=$(($opt_quiet + 1)); shift ;;
41 -v|--verbose) opt_verbose=$(($opt_verbose + 1)); shift ;;
42 --version) echo $progname $VERSION; exit 0 ;;
43 --) shift; break ;;
44 *) echo $progname: Internal error >&2; exit 1 ;;
45 esac
46 done
47 opt_verbose=$(($opt_verbose - $opt_quiet))
49 if test "$opt_help" = "1"; then
50 test $opt_verbose -gt 0 && { echo; echo $progname $VERSION; }
51 cat <<END
53 Read filenames or paths from stdin and output a list of used extensions,
54 sorted by frequency.
56 Usage: $progname [options]
58 Options:
60 -h, --help
61 Show this help.
62 -i, --ignore-case
63 Convert all A-Z to a-z before sort and count.
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 if test "$opt_ignore_case" = "1"; then
76 ign_str="tr A-Z a-z"
77 else
78 ign_str="cat"
81 perl -pe 's/^.*\/(.+?)$/$1/' |
82 grep '\.' |
83 rev |
84 cut -f 1 -d . |
85 rev |
86 $ign_str |
87 sort |
88 uniq -c |
89 sort -n