aboutsummaryrefslogtreecommitdiff
path: root/config.dot/surfraw.link/elvi/wiktionary
blob: 5827d30cd7653b9c0b91c1e26d05b62e0c0c9d0b (plain)
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
#!/bin/sh
# elvis: wiktionary      -- Search the free dictionary wiktionary
# $Id$
# Author: Silvio Rhatto <rhatto@riseup.net>
# Original Author: Moritz Muehlenhoff <jmm@informatik.uni-bremen.de>
# Based on wikipedia elvi
. surfraw || exit 1

w3_config_hook () {
  def   SURFRAW_wiktionary_language	"$SURFRAW_lang"
}

w3_usage_hook () {
    cat <<EOF
Usage: $w3_argv0 [options] [search-string]
Description:
  Search the Wikipedia online encyclopedia
Local options:
  -language=ISOCODE | -l=ISOCODE  Two letter language code (resembles ISO country codes)
				  Default: en
				  Environment: SURFRAW_wiktionary_language, SURFRAW_lang

Examples:
  $w3_argv0 -language=en anything
EOF
  w3_global_usage
}

w3_parse_option_hook () {
  opt="$1"
  optarg="$2"
  case "$opt" in
    -language=*) setopt SURFRAW_wiktionary_language $optarg	;;
    -l=*)	       setopt SURFRAW_wiktionary_language	$optarg	;;
    *) return 1 ;;
  esac
  return 0
}

w3_config
# disable requoting, doesn't work with this elvi.
SURFRAW_quote_ifs=0
w3_parse_args "$@"

if [ -z "$SURFRAW_wiktionary_language" ]; then
  SURFRAW_wiktionary_language="en"
fi

prefix="https://${SURFRAW_wiktionary_language}.wiktionary.org/w/index.php?search="

if null "$w3_args"; then
  w3_browse_url "https://${SURFRAW_wiktionary_language}.wiktionary.org"
else
  escaped_args=`w3_url_of_arg $w3_args`

  w3_browse_url "${prefix}${escaped_args}"
fi