-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 4ffc41d
Showing
18 changed files
with
661 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
name: test | ||
on: | ||
workflow_dispatch: | ||
pull_request: | ||
branches: | ||
- main | ||
push: | ||
branches: | ||
- main | ||
jobs: | ||
test: | ||
name: Test | ||
runs-on: ubuntu-20.04 | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@master | ||
- name: Setup go | ||
uses: actions/setup-go@v2 | ||
with: | ||
go-version: "1.16.0" | ||
- name: Test all | ||
env: | ||
GO111MODULE: on | ||
run: | | ||
make test-coverage | ||
- name: Install goveralls | ||
env: | ||
GO111MODULE: off | ||
run: go get github.com/mattn/goveralls | ||
- name: Send coverage | ||
uses: shogo82148/actions-goveralls@v1 | ||
with: | ||
path-to-profile: covprofile |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
name: release | ||
on: | ||
workflow_dispatch: | ||
push: | ||
tags: | ||
- v*.*.* | ||
jobs: | ||
release: | ||
name: Release | ||
runs-on: ubuntu-20.04 | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@master | ||
- name: Setup go | ||
uses: actions/setup-go@v2 | ||
with: | ||
go-version: "1.16" | ||
- name: Run goreleaser | ||
uses: goreleaser/goreleaser-action@v2 | ||
env: | ||
GO111MODULE: on | ||
GITHUB_TOKEN: ${{ secrets.RELEASE_TOKEN }} | ||
with: | ||
version: latest | ||
args: release --rm-dist |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Binaries for programs and plugins | ||
*.exe | ||
*.exe~ | ||
*.dll | ||
*.so | ||
*.dylib | ||
|
||
# Test binary, built with `go test -c` | ||
*.test | ||
|
||
# Output of the go coverage tool, specifically when used with LiteIDE | ||
*.out | ||
|
||
# Dependency directories (remove the comment below to include it) | ||
# vendor/ | ||
|
||
covprofile | ||
bin/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
env: | ||
- GO111MODULE=on | ||
before: | ||
hooks: | ||
- go mod tidy | ||
builds: | ||
- env: | ||
- CGO_ENABLED=0 | ||
goos: | ||
- linux | ||
- darwin | ||
- windows | ||
goarch: | ||
- 386 | ||
- amd64 | ||
- arm64 | ||
archives: | ||
- replacements: | ||
darwin: Darwin | ||
linux: Linux | ||
windows: Windows | ||
386: i386 | ||
amd64: x86_64 | ||
format_overrides: | ||
- goos: windows | ||
format: zip | ||
files: | ||
- none* | ||
changelog: | ||
skip: true | ||
brews: | ||
- name: alfrednize | ||
tap: | ||
owner: chroju | ||
name: homebrew-tap | ||
token: | ||
url_template: "https://github.com/chroju/alfrednize/releases/download/{{ .Tag }}/{{ .ArtifactName }}" | ||
description: "alfrednize is a so simple command to generate JSON for Alfred." | ||
homepage: "https://github.com/chroju/alfrednize" | ||
license: "MIT" | ||
test: | | ||
system "#{bin}/alfrednize --version" | ||
install: | | ||
bin.install "alfrednize" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# CHANGELOG | ||
|
||
## 0.1.0 (2021/04/29) | ||
|
||
Initial version. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2021 chroju | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
BINARY_NAME=alfrednize | ||
|
||
.PHONY: install test lint crossbuild clean | ||
|
||
install: | ||
go install | ||
|
||
lint: | ||
go mod tidy | ||
gofmt -s -l . | ||
golint ./... | ||
go vet ./... | ||
|
||
test: lint | ||
go test -v ./... | ||
|
||
crossbuild: test | ||
gox -os="linux darwin windows" -arch="386 amd64" -output "bin/remo_{{.OS}}_{{.Arch}}/{{.Dir}}" | ||
|
||
mod: | ||
go mod download | ||
|
||
build: | ||
go build -o bin/alfrednize | ||
|
||
clean: | ||
go clean | ||
rm -f $(BINARY_NAME) | ||
rm -f bin/ | ||
|
||
test-coverage: mod | ||
go test -race -covermode atomic -coverprofile=covprofile ./... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
alfrednize | ||
========== | ||
|
||
[![release badge](https://img.shields.io/github/v/release/chroju/alfrednize.svg)](https://github.com/chroju/alfrednize/releases) | ||
[![test badge](https://github.com/chroju/alfrednize/workflows/test/badge.svg)](https://github.com/chroju/alfrednize/actions?workflow=test) | ||
[![Coverage Status](https://coveralls.io/repos/github/chroju/alfrednize/badge.svg?branch=main)](https://coveralls.io/github/chroju/alfrednize?branch=main) | ||
|
||
alfrednize is a so simple command to generate JSON for [Alfred](https://www.alfredapp.com/). | ||
|
||
Usage | ||
----- | ||
|
||
Use with standard input. `alfrednize` converts multiline strings to JSON with [Alfred Script Filter JSON Format](https://www.alfredapp.com/help/workflows/inputs/script-filter/json/). | ||
|
||
```json | ||
$ echo -e 'foo\nbar\nbaz' | alfrednize | jq | ||
{ | ||
"items": [ | ||
{ | ||
"uid": "foo", | ||
"title": "foo", | ||
"subtitle": "", | ||
"arg": "foo", | ||
"match": "foo", | ||
"autocomplete": "foo" | ||
}, | ||
{ | ||
"uid": "bar", | ||
"title": "bar", | ||
"subtitle": "", | ||
"arg": "bar", | ||
"match": "bar", | ||
"autocomplete": "bar" | ||
}, | ||
{ | ||
"uid": "baz", | ||
"title": "baz", | ||
"subtitle": "", | ||
"arg": "baz", | ||
"match": "baz", | ||
"autocomplete": "baz" | ||
} | ||
] | ||
} | ||
``` | ||
|
||
Use with Script Filter in Alfred as follows. | ||
|
||
![Script Filter Sample](./images/script_filter_sample.png) | ||
![Alfred Sample](./images/alfred_sample.png) | ||
|
||
## Install | ||
|
||
### Homebrew | ||
|
||
```bash | ||
$ brew install chroju/tap/alfrednize | ||
``` | ||
|
||
### Download binary | ||
|
||
Download the latest binary from [here](https://github.com/chroju/alfrednize/releases) and place it in the some directory specified by `$PATH`. | ||
|
||
### go get | ||
|
||
If you have set up Go environment, you can also install `alfrednize` with `go get` command. | ||
|
||
``` | ||
$ go get github.com/chroju/alfrednize | ||
``` | ||
|
||
### LICENSE | ||
|
||
[MIT](https://github.com/chroju/alfrednize/LICENSE) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package ui | ||
|
||
import ( | ||
"bufio" | ||
"io" | ||
"os" | ||
"syscall" | ||
|
||
"golang.org/x/crypto/ssh/terminal" | ||
) | ||
|
||
// UI is a command line UI interface | ||
type UI interface { | ||
In() []string | ||
Out() io.Writer | ||
ErrOut() io.Writer | ||
} | ||
|
||
type cmdUI struct{} | ||
|
||
// NewCmdUI generate new UI for command line | ||
func NewCmdUI() UI { | ||
ui := &cmdUI{} | ||
return ui | ||
} | ||
|
||
func (ui *cmdUI) In() []string { | ||
if terminal.IsTerminal(int(syscall.Stdin)) { | ||
return nil | ||
} | ||
|
||
scanner := bufio.NewScanner(os.Stdin) | ||
var items []string | ||
|
||
for scanner.Scan() { | ||
items = append(items, scanner.Text()) | ||
} | ||
|
||
return items | ||
} | ||
|
||
func (ui *cmdUI) Out() io.Writer { | ||
return os.Stdout | ||
} | ||
|
||
func (ui *cmdUI) ErrOut() io.Writer { | ||
return os.Stderr | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package alfrednize | ||
|
||
import "encoding/json" | ||
|
||
type alfredFormat struct { | ||
Items []alfredFormatItem `json:"items"` | ||
} | ||
|
||
// AlfredFormatItem represents alfred script filter JSON format item. | ||
type alfredFormatItem struct { | ||
UID string `json:"uid"` | ||
Title string `json:"title"` | ||
SubTitle string `json:"subtitle"` | ||
Arg string `json:"arg"` | ||
Match string `json:"match"` | ||
AutoComplete string `json:"autocomplete"` | ||
} | ||
|
||
// Alfrednize convert from strings to Alfred format JSON | ||
func Alfrednize(items []string) ([]byte, error) { | ||
if len(items) == 0 { | ||
return nil, nil | ||
} | ||
alfredItems := make([]alfredFormatItem, len(items)) | ||
for i, v := range items { | ||
alfredItems[i] = alfredFormatItem{ | ||
UID: v, | ||
Title: v, | ||
Arg: v, | ||
Match: v, | ||
AutoComplete: v, | ||
} | ||
} | ||
alfred := &alfredFormat{ | ||
Items: alfredItems, | ||
} | ||
|
||
result, err := json.Marshal(alfred) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return result, nil | ||
} |
Oops, something went wrong.