frontend-search.plugin.zsh 4.37 KB
Newer Older
Marc Cornellà's avatar
Marc Cornellà committed
1
alias angular='frontend angular'
Marc Cornellà's avatar
Marc Cornellà committed
2
3
4
alias angularjs='frontend angularjs'
alias bem='frontend bem'
alias bootsnipp='frontend bootsnipp'
5
alias bundlephobia='frontend bundlephobia'
Marc Cornellà's avatar
Marc Cornellà committed
6
7
alias caniuse='frontend caniuse'
alias codepen='frontend codepen'
Will Mendes's avatar
Will Mendes committed
8
alias compassdoc='frontend compassdoc'
Marc Cornellà's avatar
Marc Cornellà committed
9
10
11
alias cssflow='frontend cssflow'
alias dartlang='frontend dartlang'
alias emberjs='frontend emberjs'
12
alias flowtype='frontend flowtype'
Marc Cornellà's avatar
Marc Cornellà committed
13
alias fontello='frontend fontello'
14
alias github='frontend github'
Marc Cornellà's avatar
Marc Cornellà committed
15
alias html5please='frontend html5please'
16
alias jestjs='frontend jestjs'
Marc Cornellà's avatar
Marc Cornellà committed
17
18
19
alias jquery='frontend jquery'
alias lodash='frontend lodash'
alias mdn='frontend mdn'
20
alias nodejs='frontend nodejs'
Marc Cornellà's avatar
Marc Cornellà committed
21
alias npmjs='frontend npmjs'
22
alias packagephobia='frontend packagephobia'
Marc Cornellà's avatar
Marc Cornellà committed
23
24
25
26
alias qunit='frontend qunit'
alias reactjs='frontend reactjs'
alias smacss='frontend smacss'
alias stackoverflow='frontend stackoverflow'
27
alias typescript='frontend typescript'
Marc Cornellà's avatar
Marc Cornellà committed
28
alias unheap='frontend unheap'
29
alias vuejs='frontend vuejs'
Marc Cornellà's avatar
Marc Cornellà committed
30

31
function _frontend_fallback() {
32
33
34
35
  case "$FRONTEND_SEARCH_FALLBACK" in
    duckduckgo) echo "https://duckduckgo.com/?sites=$1&q=" ;;
    *) echo "https://google.com/search?as_sitesearch=$1&as_q=" ;;
  esac
36
37
}

38
function frontend() {
39
40
  emulate -L zsh

41
  # define search context URLS
42
43
  typeset -A urls
  urls=(
44
    angular        'https://angular.io/?search='
45
46
    angularjs      $(_frontend_fallback 'angularjs.org')
    bem            $(_frontend_fallback 'bem.info')
Janosch Schwalm's avatar
Janosch Schwalm committed
47
    bootsnipp      'https://bootsnipp.com/search?q='
48
    bundlephobia   'https://bundlephobia.com/result?p='
Janosch Schwalm's avatar
Janosch Schwalm committed
49
    caniuse        'https://caniuse.com/#search='
50
    codepen        'https://codepen.io/search/pens?q='
Will Mendes's avatar
Will Mendes committed
51
    compassdoc     'http://compass-style.org/search?q='
52
53
    cssflow        'http://www.cssflow.com/search?q='
    dartlang       'https://api.dartlang.org/apidocs/channels/stable/dartdoc-viewer/dart:'
54
55
    emberjs        $(_frontend_fallback 'emberjs.com/')
    flowtype       $(_frontend_fallback 'flow.org/en/docs/')
56
    fontello       'http://fontello.com/#search='
57
58
    github         'https://github.com/search?q='
    html5please    'https://html5please.com/#'
59
    jestjs         $(_frontend_fallback 'jestjs.io')
60
61
62
    jquery         'https://api.jquery.com/?s='
    lodash         'https://devdocs.io/lodash/index#'
    mdn            'https://developer.mozilla.org/search?q='
63
    nodejs         $(_frontend_fallback 'nodejs.org/en/docs/')
64
    npmjs          'https://www.npmjs.com/search?q='
65
    packagephobia  'https://packagephobia.now.sh/result?p='
66
    qunit          'https://api.qunitjs.com/?s='
67
68
    reactjs        $(_frontend_fallback 'reactjs.org/')
    smacss         $(_frontend_fallback 'smacss.com')
Janosch Schwalm's avatar
Janosch Schwalm committed
69
    stackoverflow  'https://stackoverflow.com/search?q='
70
    typescript     $(_frontend_fallback 'www.typescriptlang.org/docs')
71
    unheap         'http://www.unheap.com/?s='
72
    vuejs          $(_frontend_fallback 'vuejs.org')
73
  )
74

75
76
  # show help for command list
  if [[ $# -lt 2 ]]
77
  then
78
      print -P "Usage: frontend %Ucontext%u %Uterm%u [...%Umore%u] (or just: %Ucontext%u %Uterm%u [...%Umore%u])"
div_bhasin's avatar
div_bhasin committed
79
      print -P ""
80
81
82
      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 ""
83
      print -P "  angular, angularjs, bem, bootsnipp, caniuse, codepen, compassdoc, cssflow, packagephobia"
84
85
      print -P "  dartlang, emberjs, fontello, flowtype, github, html5please, jestjs, jquery, lodash,"
      print -P "  mdn, npmjs, nodejs, qunit, reactjs, smacss, stackoverflow, unheap, vuejs, bundlephobia"
86
87
88
      print -P ""
      print -P "For example: frontend npmjs mocha (or just: npmjs mocha)."
      print -P ""
89
90
91
      return 1
  fi

92
  # check whether the search context is supported
93
  if [[ -z "$urls[$1]" ]]
94
  then
95
96
97
98
    echo "Search context \"$1\" currently not supported."
    echo ""
    echo "Valid contexts are:"
    echo ""
99
    echo "  angular, angularjs, bem, bootsnipp, caniuse, codepen, compassdoc, cssflow, packagephobia"
100
101
    echo "  dartlang, emberjs, fontello, github, html5please, jest, jquery, lodash,"
    echo "  mdn, npmjs, nodejs, qunit, reactjs, smacss, stackoverflow, unheap, vuejs, bundlephobia"
102
103
104
105
    echo ""
    return 1
  fi

106
  # build search url:
Marc Cornellà's avatar
Marc Cornellà committed
107
  # join arguments passed with '%20', then append to search context URL
108
  # TODO substitute for proper urlencode method
div_bhasin's avatar
div_bhasin committed
109
  url="${urls[$1]}${(j:%20:)@[2,-1]}"
110

111
  echo "Opening $url ..."
112

113
  open_command "$url"
114
}