frontend-search.plugin.zsh 3.4 KB
Newer Older
Marc Cornellà's avatar
Marc Cornellà committed
1
2
3
4
5
6
alias angularjs='frontend angularjs'
alias aurajs='frontend aurajs'
alias bem='frontend bem'
alias bootsnipp='frontend bootsnipp'
alias caniuse='frontend caniuse'
alias codepen='frontend codepen'
Will Mendes's avatar
Will Mendes committed
7
alias compassdoc='frontend compassdoc'
Marc Cornellà's avatar
Marc Cornellà committed
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
alias cssflow='frontend cssflow'
alias dartlang='frontend dartlang'
alias emberjs='frontend emberjs'
alias fontello='frontend fontello'
alias html5please='frontend html5please'
alias jquery='frontend jquery'
alias lodash='frontend lodash'
alias mdn='frontend mdn'
alias npmjs='frontend npmjs'
alias qunit='frontend qunit'
alias reactjs='frontend reactjs'
alias smacss='frontend smacss'
alias stackoverflow='frontend stackoverflow'
alias unheap='frontend unheap'

23
function frontend() {
24
25
  emulate -L zsh

26
  # define search context URLS
27
28
29
30
31
  typeset -A urls
  urls=(
    angularjs      'https://google.com/search?as_sitesearch=angularjs.org&as_q='
    aurajs         'http://aurajs.com/api/#stq='
    bem            'https://google.com/search?as_sitesearch=bem.info&as_q='
Janosch Schwalm's avatar
Janosch Schwalm committed
32
33
34
    bootsnipp      'https://bootsnipp.com/search?q='
    caniuse        'https://caniuse.com/#search='
    codepen        'https://codepen.io/search?q='
Will Mendes's avatar
Will Mendes committed
35
    compassdoc     'http://compass-style.org/search?q='
36
37
    cssflow        'http://www.cssflow.com/search?q='
    dartlang       'https://api.dartlang.org/apidocs/channels/stable/dartdoc-viewer/dart:'
Janosch Schwalm's avatar
Janosch Schwalm committed
38
    emberjs        'https://emberjs.com/api/#stp=1&stq='
39
40
41
42
43
44
45
46
47
    fontello       'http://fontello.com/#search='
    html5please    'http://html5please.com/#'
    jquery         'https://api.jquery.com/?s='
    lodash         'https://devdocs.io/lodash/index#'
    mdn            'https://developer.mozilla.org/search?q='
    npmjs          'https://www.npmjs.com/search?q='
    qunit          'https://api.qunitjs.com/?s='
    reactjs        'https://google.com/search?as_sitesearch=facebook.github.io/react&as_q='
    smacss         'https://google.com/search?as_sitesearch=smacss.com&as_q='
Janosch Schwalm's avatar
Janosch Schwalm committed
48
    stackoverflow  'https://stackoverflow.com/search?q='
49
50
    unheap         'http://www.unheap.com/?s='
  )
51

52
53
  # show help for command list
  if [[ $# -lt 2 ]]
54
  then
55
56
57
58
59
      print -P "Usage: frontend %Ucontext%u %Uterm%u [...%Umore%u] (or just: %Ucontext%u %Uterm%u [...%Umore%u])"
      print -P ""
      print -P "%Uterm%u and what follows is what will be searched for in the %Ucontext%u website,"
      print -P "and %Ucontext%u is one of the following:"
      print -P ""
Will Mendes's avatar
Will Mendes committed
60
      print -P "  angularjs, aurajs, bem, bootsnipp, caniuse, codepen, compassdoc, cssflow,"
61
62
63
64
65
      print -P "  dartlang, emberjs, fontello, html5please, jquery, lodash, mdn, npmjs,"
      print -P "  qunit, reactjs, smacss, stackoverflow, unheap"
      print -P ""
      print -P "For example: frontend npmjs mocha (or just: npmjs mocha)."
      print -P ""
66
67
68
      return 1
  fi

69
  # check whether the search context is supported
70
  if [[ -z "$urls[$1]" ]]
71
  then
72
73
74
75
    echo "Search context \"$1\" currently not supported."
    echo ""
    echo "Valid contexts are:"
    echo ""
Will Mendes's avatar
Will Mendes committed
76
    echo "  angularjs, aurajs, bem, bootsnipp, caniuse, codepen, compassdoc, cssflow, "
77
78
    echo "  dartlang, emberjs, fontello, html5please, jquery, lodash, mdn, npmjs,  "
    echo "  qunit, reactjs, smacss, stackoverflow, unheap"
79
80
81
82
    echo ""
    return 1
  fi

83
  # build search url:
84
  # join arguments passed with '+', then append to search context URL
85
86
  # TODO substitute for proper urlencode method
  url="${urls[$1]}${(j:+:)@[2,-1]}"
87

88
  echo "Opening $url ..."
89

90
  open_command "$url"
91
}