File: github

package info (click to toggle)
surfraw 2.3.0-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 1,624 kB
  • sloc: sh: 7,977; perl: 824; makefile: 277
file content (67 lines) | stat: -rwxr-xr-x 1,559 bytes parent folder | download | duplicates (3)
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
59
60
61
62
63
64
65
66
67
#!/bin/sh
# elvis: github		-- Search GitHub (https://github.com)
# Author: jason ryan • https://jasonwryan.com

. surfraw || exit 1

w3_config_hook () {
def   SURFRAW_git_type        "$SURFRAW_type"
def   SURFRAW_git_lang         any
}

w3_usage_hook () {
    cat <<EOF

Usage: $w3_argv0 [options] [search-string]
Description:
	Search Github (https://github.com)

	Local options:
	-l=LANGUAGE   |  -lang=LANGUAGE
	Languages are case sensitive, eg., C, Shell, Python etc.
	Languages with spaces must be conjoined with a "+", eg, Common+Lisp
	Default: Any

	-type=SEARCH  | -t=SEARCH
	every  |   Everything
	repo   |   Repositories
	user   |   Users
	code   |   Code
	           Default: Everything

EOF
    w3_global_usage
}

w3_parse_option_hook () {
    opt="$1"
    optarg="$2"
    case "$opt" in
	-t*=*)       setopt   SURFRAW_git_type   $optarg ;;
	-l*=*)       setopt   SURFRAW_git_lang   $optarg ;;
	*) return 1 ;;
    esac
    return 0
}
w3_config
w3_parse_args "$@"
# w3_args now contains list of arguments

# type of search selected
case "$SURFRAW_git_type" in
	every)  type="Everything"    	;;
	repo)   type="Repositories"  	;;
	user)   type="Users"         	;;
	code)   type="Code"          	;;
	*)      type="Everything"    	;;
esac

# No arguments parsed
if [ -z "$w3_args" ]; then
	w3_browse_url "https://github.com"
else
	# Language and/or search type selected
	escaped_args=$(w3_url_of_arg $w3_args)
	w3_browse_url "https://github.com/search?q=${escaped_args}&repo=&langOverride=&start_value=1&type=${type}&language=${SURFRAW_git_lang}"
fi