-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsortopts
executable file
·78 lines (77 loc) · 1.71 KB
/
sortopts
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
#!/bin/bash
__short_rules="$1"
__long_rules="$2"
shift 2
findline() {
echo -e "$__long_rules" | while read -r __line; do
case "$__line" in "$1"[:]*) echo "${__line//[^:]/}" ;; esac
done
}
while [ "$#" -gt 0 ]; do
case "$1" in
--) __other+="$1¢"; shift
for __opt in $@; do
__other+="'$__opt'¢"
done
break
;;
--*=*) __long_1="${1%%=*}"
__long_2="${1#*=}"
__long_opts+="$__long_1¢'$__long_2'¢"
;;
--*) __long_opts+="$1¢"
case "$2" in --*|-*|"") : ;; *)
__long_opts+="'$2'¢"
shift
esac
;;
-*) __short_opts+="$1¢"
case "$2" in --*|-*|"") : ;; *)
__short_opts+="'$2'¢"
shift
esac
;;
*) __other+="'$1'¢"
;;
esac
shift
done
[ "$SHORTDASH" == 1 ] && __dash='-' || __dash=''
[ "$PARSER" == 1 ] && __d='|' || __d=' '
if [ "$OPTOUT" == 1 ]; then
eval 'echo "${__short_opts//¢/'$__d'}"'
eval 'echo "${__long_opts//¢/'$__d'}"'
eval 'echo "${__other//¢/'$__d'}"'
else
{ IFS='¢'; set -- ${__short_opts}; unset IFS; }
__i=1
getopt -u -- "$__short_rules" $@
{ IFS='¢'; set -- ${__long_opts}; unset IFS; }
__long_rules="${__long_rules//,/\\n}"
while [ "$#" -gt 0 ]; do
__arg="${1/--/}"
__sum="$(findline "$__arg")"
case "$1" in --*|-*) : ;; *) other+="'$1'¢"; shift; continue ;; esac
case "$__sum" in
:) case "$2" in
--*|-*)
echo "sortopts: $1 requires an argument" >&2 ;;
*) __long_args+="$1 $2¢"; shift ;;
esac
;;
::) case "$2" in
--*|-*)
__long_args+="$1¢" ;;
*) __long_args+="$1 $2¢"; shift ;;
esac
;;
"") __long_args+="$1¢"
case "$2" in --*|-*|"") : ;;
*) __other+="$2¢" ;; esac
;;
esac
shift
done
eval 'echo "${__long_args//¢/'$__d'}"'
eval 'echo "${__other//¢/'$__d'}"'
fi