Skip to content

Commit de67a9a

Browse files
committed
Initial commit
0 parents  commit de67a9a

File tree

15 files changed

+1335
-0
lines changed

15 files changed

+1335
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
gm
2+
bin

LICENSE

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
The MIT License (MIT)
2+
Copyright © 2017 Masaki Ishiyama <[email protected]>
3+
4+
Permission is hereby granted, free of charge, to any person obtaining a copy
5+
of this software and associated documentation files (the “Software”), to deal
6+
in the Software without restriction, including without limitation the rights
7+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
copies of the Software, and to permit persons to whom the Software is
9+
furnished to do so, subject to the following conditions:
10+
11+
The above copyright notice and this permission notice shall be included in
12+
all copies or substantial portions of the Software.
13+
14+
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20+
THE SOFTWARE.

Makefile

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
TEST?=./...
2+
DEPS = $(shell go list -f '{{range .TestImports}}{{.}} {{end}}' ./...)
3+
4+
all: build
5+
6+
build: deps
7+
mkdir -p bin
8+
go build -o bin/gist
9+
10+
install: build
11+
install -m 755 ./bin/gist ~/bin/gist
12+
13+
deps:
14+
go get -d -v ./...
15+
echo $(DEPS) | xargs -n1 go get -d
16+
17+
test: deps
18+
go test $(TEST) $(TESTARGS) -timeout=3s -parallel=4
19+
go vet $(TEST)
20+
go test $(TEST) -race
21+
22+
.PHONY: all build deps test

README.md

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
<img src="https://raw.githubusercontent.com/b4b4r07/i/master/gist/logo.png" width="200">
2+
3+
> A simple gist editor for CLI
4+
>
5+
> <img src="https://octodex.github.com/images/megacat-2.png" width="200">
6+
7+
## Pros
8+
9+
- Simple and intuitive
10+
- Just select and edit gist you want
11+
- Can use any editors what you want
12+
- Work with [peco](https://github.com/peco/peco) and [fzf](https://github.com/junegunn/fzf)
13+
- Automatically synchronized after editing
14+
- Customizable
15+
- A few options and small TOML
16+
- Easy to install
17+
- Go! single binary
18+
19+
***DEMO***
20+
21+
<img src="https://raw.githubusercontent.com/b4b4r07/i/master/gist/demo.gif" width="500">
22+
23+
## Usage
24+
25+
Currently gist supports the following commands:
26+
27+
```console
28+
$ gist help
29+
gist - A simple gist editor for CLI
30+
31+
Usage:
32+
gist [flags]
33+
gist [command]
34+
35+
Available Commands:
36+
config Config the setting file
37+
delete Delete gist files
38+
edit Edit the gist file and sync after
39+
new Create a new gist
40+
open Open user's gist
41+
42+
Flags:
43+
-v, --version show the version and exit
44+
45+
Use "gist [command] --help" for more information about a command.
46+
```
47+
48+
### Configurations
49+
50+
Well-specified options and user-specific settings can be described in a toml file. It can be changed with the `gist set` command.
51+
52+
```toml
53+
[Core]
54+
Editor = "vim"
55+
selectcmd = "fzf-tmux --multi:fzf:peco:percol"
56+
tomlfile = "/Users/b4b4r07/.config/gist/config.toml"
57+
user = "b4b4r07"
58+
59+
[Gist]
60+
token = "your_github_token"
61+
dir = "/Users/b4b4r07/.config/gist/files"
62+
63+
[Flag]
64+
open_url = false
65+
private = false
66+
verbose = true
67+
show_spinner = true
68+
```
69+
70+
This behavior was heavily inspired by [mattn/memo](https://github.com/mattn/memo), thanks!
71+
72+
## Installation
73+
74+
```console
75+
$ go get github.com/b4b4r07/gist
76+
```
77+
78+
## Versus
79+
80+
There are many other implements as the gist client (called "gister") such as the following that works on command-line:
81+
82+
- <https://github.com/defunkt/gist>
83+
- <https://github.com/jdowner/gist>
84+
- ...
85+
86+
## License
87+
88+
MIT
89+
90+
## Author
91+
92+
b4b4r07

cmd/config.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package cmd
2+
3+
import (
4+
"path/filepath"
5+
6+
"github.com/b4b4r07/gist/config"
7+
"github.com/b4b4r07/gist/util"
8+
"github.com/spf13/cobra"
9+
)
10+
11+
var confCmd = &cobra.Command{
12+
Use: "config",
13+
Short: "Config the setting file",
14+
Long: "Config the setting file with your editor (default: vim)",
15+
RunE: conf,
16+
}
17+
18+
func conf(cmd *cobra.Command, args []string) error {
19+
editor := config.Conf.Core.Editor
20+
tomlfile := config.Conf.Core.TomlFile
21+
if tomlfile == "" {
22+
dir, _ := config.GetDefaultDir()
23+
tomlfile = filepath.Join(dir, "config.toml")
24+
}
25+
return util.RunCommand(editor, tomlfile)
26+
}
27+
28+
func init() {
29+
RootCmd.AddCommand(confCmd)
30+
}

cmd/delete.go

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
package cmd
2+
3+
import (
4+
"log"
5+
6+
"github.com/b4b4r07/gist/config"
7+
"github.com/b4b4r07/gist/gist"
8+
"github.com/b4b4r07/gist/util"
9+
"github.com/spf13/cobra"
10+
)
11+
12+
var deleteCmd = &cobra.Command{
13+
Use: "delete",
14+
Short: "Delete gist files",
15+
Long: "Delete gist files on the remote",
16+
RunE: delete,
17+
}
18+
19+
func delete(cmd *cobra.Command, args []string) error {
20+
var err error
21+
22+
gist, err := gist.New(config.Conf.Gist.Token)
23+
if err != nil {
24+
return err
25+
}
26+
27+
gfs, err := gist.GetRemoteFiles()
28+
if err != nil {
29+
return err
30+
}
31+
32+
selectedLines, err := util.Filter(gfs.Text)
33+
if err != nil {
34+
return err
35+
}
36+
37+
var ids []string
38+
for _, line := range selectedLines {
39+
if line == "" {
40+
continue
41+
}
42+
parsedLine, err := util.ParseLine(line)
43+
if err != nil {
44+
continue
45+
}
46+
ids = append(ids, gfs.ExtendID(parsedLine.ID))
47+
}
48+
49+
ids = util.UniqueArray(ids)
50+
for _, id := range ids {
51+
err = gist.Delete(id)
52+
if err != nil {
53+
log.Printf("[ERROR] %v", err)
54+
}
55+
}
56+
57+
return nil
58+
}
59+
60+
func init() {
61+
RootCmd.AddCommand(deleteCmd)
62+
}

cmd/edit.go

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
package cmd
2+
3+
import (
4+
"path/filepath"
5+
6+
"github.com/b4b4r07/gist/config"
7+
"github.com/b4b4r07/gist/gist"
8+
"github.com/b4b4r07/gist/util"
9+
"github.com/spf13/cobra"
10+
)
11+
12+
var editCmd = &cobra.Command{
13+
Use: "edit",
14+
Short: "Edit the gist file and sync after",
15+
Long: "Edit the gist file and sync after",
16+
RunE: edit,
17+
}
18+
19+
func edit(cmd *cobra.Command, args []string) error {
20+
var err error
21+
22+
gist, err := gist.New(config.Conf.Gist.Token)
23+
if err != nil {
24+
return err
25+
}
26+
27+
gfs, err := gist.GetRemoteFiles()
28+
if err != nil {
29+
return err
30+
}
31+
32+
selectedLines, err := util.Filter(gfs.Text)
33+
if err != nil {
34+
return err
35+
}
36+
37+
for _, line := range selectedLines {
38+
if line == "" {
39+
continue
40+
}
41+
var url string
42+
parsedLine, err := util.ParseLine(line)
43+
if err != nil {
44+
continue
45+
}
46+
47+
file := filepath.Join(config.Conf.Gist.Dir, gfs.ExtendID(parsedLine.ID), parsedLine.Filename)
48+
err = gist.Edit(file)
49+
if err != nil {
50+
return err
51+
}
52+
53+
// TODO: FIXME: gist.Edit
54+
if config.Conf.Flag.OpenURL {
55+
util.Open(url)
56+
}
57+
}
58+
59+
return nil
60+
}
61+
62+
func init() {
63+
RootCmd.AddCommand(editCmd)
64+
editCmd.Flags().BoolVarP(&config.Conf.Flag.OpenURL, "open", "o", false, "Open with the default browser")
65+
}

0 commit comments

Comments
 (0)