2 # $MirOS: src/usr.bin/wtf/wtf,v 1.20 2012/08/18 04:48:46 tg Exp $
3 # $NetBSD: wtf,v 1.7 2000/11/21 00:18:52 soren Exp $
5 # Copyright © 2002, 2003, 2004, 2006, 2007, 2008, 2010, 2011, 2012
6 # Thorsten “mirabilos” Glaser <tg@mirbsd.org>
8 # Provided that these terms and disclaimer and all copyright notices
9 # are retained or reproduced in an accompanying document, permission
10 # is granted to deal in this work without restriction, including un‐
11 # limited rights to use, publicly perform, distribute, sell, modify,
12 # merge, give away, or sublicence.
14 # This work is provided “AS IS” and WITHOUT WARRANTY of any kind, to
15 # the utmost extent permitted by applicable law, neither express nor
16 # implied; without malicious intent or gross negligence. In no event
17 # may a licensor, author or contributor be held liable for indirect,
18 # direct, other damage, loss, or other issues arising in any way out
19 # of dealing in the work, even if advised of the possibility of such
20 # damage or existence of a defect, except proven that it results out
21 # of said person’s immediate fault when using the work as intended.
23 acronyms=${ACRONYMDB:-/usr/share/misc/acronyms}
26 print -u2 "usage: ${0##*/} [±adPpw] [-f dbfile] [is[t]] <acronym> [...]"
34 while getopts "adf:Ppt:w" ch; do
36 (+a) use_acronyms=0 ;;
40 (f) acronyms=$OPTARG ;;
53 [[ $1 = is || $1 = ist ]] && shift
56 if (( use_ports )); then
57 if [[ -s /usr/ports/INDEX ]]; then
58 # MirPorts Framework, OpenBSD ports tree
60 function ports_acquire_filtered {
61 while IFS='|' read a b c d e; do
62 [[ $a = *"$1"* ]] && \
63 print -r -- "$a|${d%% \(uses*}"
64 done </usr/ports/INDEX
66 function ports_acquire_unfiltered {
67 while IFS='|' read a b c d e; do
68 [[ $a$d = *"$1"* ]] && \
69 print -r -- "$a|${d%% \(uses*}"
70 done </usr/ports/INDEX
72 elif [[ -x $(whence -p yum) ]]; then
73 # Red Hat Yellowdog Updater Modified
75 function ports_acquire_filtered {
76 yum search -q -- "$1" | \
77 tr '\n' '
\ 1' | sed 's/
\ 1 *: / /g' | tr '
\ 1' '\n' | \
79 [[ $a = *"$1"* ]] && print -r -- "$a|$c"
82 function ports_acquire_unfiltered {
83 yum search -q -- "$1" | \
84 tr '\n' '
\ 1' | sed 's/
\ 1 *: / /g' | tr '
\ 1' '\n' | \
89 elif [[ -x $(whence -p apt-cache) ]]; then
90 # Debian Advanced Packaging Tool
92 function ports_acquire_filtered {
93 apt-cache search -- "$1" | while read a b c; do
94 [[ $a = *"$1"* ]] && print -r -- "$a|$c"
97 function ports_acquire_unfiltered {
98 apt-cache search -- "$1" | while read a b c; do
106 (1) alias ports_acquire=ports_acquire_filtered ;;
107 (2) alias ports_acquire=ports_acquire_unfiltered ;;
113 for target in "$@"; do
114 typeset -u tgsrch=$target
115 tgsrch=${tgsrch//ä/Ä}
116 tgsrch=${tgsrch//ö/Ö}
117 tgsrch=${tgsrch//ü/Ü}
119 if (( use_ports )); then
120 p=$(ports_acquire "$target")
122 print -r " - $binpkgs matching “$target”:"
123 print -r -- "$p" | sort -u | column -ts'|'
127 if (( use_acronyms )); then
129 while IFS= read -r line; do
130 [[ $line = "$tgsrch "* ]] || continue
131 (( found++ )) || print -r " $tgsrch:"
132 print -r -- "${line#* }"
134 if (( !found )); then
135 print -ru2 Gee… I don’t know what “"$tgsrch"” means…
140 (( use_dict || use_whatis )) && print " - other information sources"
142 (( use_dict )) && if whence -p dict >&-; then
143 dict "$target" || (( rv |= 2 ))
148 if (( use_whatis )); then
149 w=$(whatis "$target") || \
150 w="Sorry, no entry for a “$target” manual page"