bang

package module
v0.0.0-...-bb63b08 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 13, 2020 License: MIT Imports: 8 Imported by: 0

README

bang

GoDoc

Browser launcher, heavily inspired by DuckDuckGo's !bangs.

Search for cat pictures on Google Images:

bang gi cat pictures
# opens a browser to 'cat pictures' on Google Images

Queries can also be piped through stdin if a hyphen is passed in as the argument, and the -url flag can be used to print the bang's URL to stdout rather than launching a browser.

$ echo "cat pictures" | bang -url gi -
https://www.google.com/search?tbm=isch&q=cat+pictures
$ echo "reddit cat pictures" | bang -url -
https://www.reddit.com/search?q=cat+pictures

The system's URL opener will be used by default, but if set, the BROWSER environment variable will be executed with the chosen bang's URL passed as the final argument.

Installation

To get everything and install the CLI into your GOPATH:

go get -u github.com/travis-g/bang/...

The CLI is available from within cmd/bang.

Config

The CLI looks for a config file named bangs.(json|yml|yaml|toml|hcl) in the following locations, in order:

~/.config/bang/
~/.config/
./ (current directory)

Each key of the config file should be the unique name of a Bang, with the following properties:

  • description (string: <req>) is a friendly description for the Bang.
  • escape_method (int: 0) defines how the query is escaped prior to it being substituted within the Bang's format:
    • 0 - Escapes with url.QueryEscape: cat picturescat+pictures. This is the default method.
    • 1 - Pass-through without escaping: cat picturescat pictures
    • 2 - Escapes with url.PathEscape: cat picturescat%20pictures
  • format (string: <req>) defines the template used to create the Bang's resulting query string. Use {{{s}}} to denote where the query should be substituted.

Example YAML config file entry for GoDoc:

godoc:
  # try it: bang godoc github.com/travis-g/bang
  description: GoDoc
  escape_method: 1
  format: "https://godoc.org/{{{s}}}"

See the bang.proto file for the Bang object format.

Documentation

Overview

Package bang implements browser-launching URL shortcuts.

Index

Constants

This section is empty.

Variables

View Source
var Bang_EscapeMethod_name = map[int32]string{
	0: "QUERY_ESCAPE",
	1: "PASS_THROUGH",
	2: "PATH_ESCAPE",
}
View Source
var Bang_EscapeMethod_value = map[string]int32{
	"QUERY_ESCAPE": 0,
	"PASS_THROUGH": 1,
	"PATH_ESCAPE":  2,
}
View Source
var Bangs = map[string]Bang{}

Bangs is the registration list of all Bangs. We use a map[string] here for faster lookups at runtime than digging through slices.

Functions

func Filter

func Filter(vs map[string]Bang, f func(string) bool) map[string]Bang

Filter filters a map of Bangs based on a predicate.

fmt.Println(Filter(Bangs, func(v string) bool {
  return strings.Contains(strings.ToLower(v), strings.ToLower("Bing"))
}))

func ListBangs

func ListBangs(bangs map[string]Bang) string

ListBangs enumerates the Bangs of a map of Bangs.

func SliceToMap

func SliceToMap(slice []Bang) (bangs map[string]Bang)

SliceToMap returns a map of Bangs based on the input slice's Bangs' names.

Types

type Bang

type Bang struct {
	// Name of the Bang, which is used as its ID.
	Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"`
	// Format of the Bang, where '{{{s}}}' will be substituted with the escaped
	// query string.
	Format string `protobuf:"bytes,2,opt,name=format,proto3" json:"format,omitempty"`
	// Description is a summary of the Bang.
	Description          string            `protobuf:"bytes,3,opt,name=description,proto3" json:"description,omitempty"`
	EscapeMethod         Bang_EscapeMethod `` /* 126-byte string literal not displayed */
	XXX_NoUnkeyedLiteral struct{}          `json:"-"`
	XXX_unrecognized     []byte            `json:"-"`
	XXX_sizecache        int32             `json:"-"`
}

func MapToNamedBangs

func MapToNamedBangs(bangs map[string]Bang) (slice []Bang)

MapToNamedBangs returns a slice of Bangs with their names set according to keys from an input map.

func (*Bang) Descriptor

func (*Bang) Descriptor() ([]byte, []int)

func (*Bang) GetDescription

func (m *Bang) GetDescription() string

func (*Bang) GetEscapeMethod

func (m *Bang) GetEscapeMethod() Bang_EscapeMethod

func (*Bang) GetFormat

func (m *Bang) GetFormat() string

func (*Bang) GetName

func (m *Bang) GetName() string

func (*Bang) ProtoMessage

func (*Bang) ProtoMessage()

func (*Bang) Reset

func (m *Bang) Reset()

func (*Bang) String

func (m *Bang) String() string

func (*Bang) URL

func (b *Bang) URL(q string) string

URL returns the direct query URL for a Bang.

func (*Bang) XXX_DiscardUnknown

func (m *Bang) XXX_DiscardUnknown()

func (*Bang) XXX_Marshal

func (m *Bang) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*Bang) XXX_Merge

func (m *Bang) XXX_Merge(src proto.Message)

func (*Bang) XXX_Size

func (m *Bang) XXX_Size() int

func (*Bang) XXX_Unmarshal

func (m *Bang) XXX_Unmarshal(b []byte) error

type Bang_EscapeMethod

type Bang_EscapeMethod int32

EscapeMethod is the type of escaping to be used when escaping non-URL safe characters, like spaces and quotes.

const (
	// Escapes the input with url.QueryEscape: "cat pictures" => "cat+pictures"
	Bang_QUERY_ESCAPE Bang_EscapeMethod = 0
	// Does no escaping: "cat pictures" => "cat pictures"
	Bang_PASS_THROUGH Bang_EscapeMethod = 1
	// Escapes the input with url.PathEscape: "cat pictures" => "cat%20pictures"
	Bang_PATH_ESCAPE Bang_EscapeMethod = 2
)

func (Bang_EscapeMethod) EnumDescriptor

func (Bang_EscapeMethod) EnumDescriptor() ([]byte, []int)

func (Bang_EscapeMethod) String

func (x Bang_EscapeMethod) String() string

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL