Skip to content

Commit 414e716

Browse files
authored
3.2
+ Use getopts(1) instead of manual parsing options + Add -n option (display only info) + Remove usage from readme
2 parents 0ecf5fd + d4598dd commit 414e716

File tree

2 files changed

+14
-24
lines changed

2 files changed

+14
-24
lines changed

README.rst

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -99,14 +99,7 @@ your favorite distros.
9999
Usage
100100
-----
101101

102-
::
103-
104-
syntax:
105-
disfetch [options]
106-
options:
107-
-h, --help prints this message
108-
-l, --logo sets distro logo to print
109-
-m, --mono, --monochrome enables monochrome mode
102+
See ``disfetch -h``.
110103

111104
----
112105

disfetch

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -40,27 +40,24 @@ help() {
4040
\x1B[1msyntax\x1B[0m:
4141
\tdisfetch \x1B[92m[options]\x1B[0m
4242
\x1B[1moptions\x1B[0m:
43-
\t\x1B[92m-h, --help\x1B[0m \x1B[93mprints this message\x1B[0m
44-
\t\x1B[92m-l, --logo\x1B[0m \x1B[93msets distro logo to print\x1B[0m
45-
\t\x1B[92m-m, --mono, --monochrome\x1B[0m \x1B[93menables monochrome mode\x1B[0m
43+
\t\x1B[92m-h\x1B[0m \x1B[93mprint this help\x1B[0m
44+
\t\x1B[92m-l <logo>\x1B[0m \x1B[93mset distro logo\x1B[0m
45+
\t\x1B[92m-m\x1B[0m \x1B[93mdon't use colors and formatting\x1B[0m
46+
\t\x1B[92m-n\x1B[0m \x1B[93mdisable decorations, display only info\x1B[0m
4647
\n"
4748
}
4849

4950
# parse arguments
50-
while [ -n "$1" ] && [ "$1" != -- ]; do
51-
case $1 in
52-
-h|--help)
53-
help; exit 0
54-
;;
55-
-l|--logo)
56-
LOGO="$2"
57-
;;
58-
-m|--mono|--monochrome)
59-
MONO=1
60-
;;
51+
while getopts "hl:mn" opt; do
52+
case "$opt" in
53+
h) help; exit 0;;
54+
l) LOGO="$OPTARG";;
55+
m) MONO=1;;
56+
n) INFO_ONLY=;;
57+
*) exit 1;;
6158
esac
62-
shift
6359
done
60+
shift $((OPTIND - 1))
6461

6562
###########################################
6663
# global stuff needed everywhere #
@@ -791,5 +788,5 @@ done
791788
# order: user@hostname, OS, kernel, arch, uptime, packages, shell, desktop
792789
for i in $(seq 8); do
793790
# shellcheck disable=SC2059 # can't do anything about it
794-
echo "$(elem "$i" "$LOGO") $(elem "$i" "$PALETTE")| $(elem "$i" "$INFO")"
791+
echo "${INFO_ONLY-"$(elem "$i" "$LOGO") $(elem "$i" "$PALETTE")| "}$(elem "$i" "$INFO")"
795792
done

0 commit comments

Comments
 (0)