diff --git a/.all-contributorsrc b/.all-contributorsrc index db7b1021..ce38430d 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -365,8 +365,21 @@ "name": "Matei Alexandru Gardus", "avatar_url": "https://avatars0.githubusercontent.com/u/11583824?v=4", "profile": "http://stormfirefox1.github.io", - "contributions": [ - ] + "contributions": [] + }, + { + "login": "Seanstoppable", + "name": "Sean Smith", + "avatar_url": "https://avatars2.githubusercontent.com/u/1523955?v=4", + "profile": "https://github.com/Seanstoppable", + "contributions": [] + }, + { + "login": "kaskavalci", + "name": "Halil Kaskavalci", + "avatar_url": "https://avatars1.githubusercontent.com/u/1646238?v=4", + "profile": "http://kaskavalci.com", + "contributions": [] } ] } diff --git a/README.md b/README.md index 30b8ec9e..5c1f6441 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ -[![All Contributors](https://img.shields.io/badge/all_contributors-51-orange.svg?style=flat-square)](#contributors) +[![All Contributors](https://img.shields.io/badge/all_contributors-53-orange.svg?style=flat-square)](#contributors) [![Build Status](https://travis-ci.com/senorprogrammer/wtf.svg?branch=master)](https://travis-ci.com/senorprogrammer/wtf) [![Gitter Chat](https://badges.gitter.im/wtfutil/Lobby.svg)](https://gitter.im/wtfutil/Lobby?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) [![Twitter](https://img.shields.io/badge/follow-on%20twitter-blue.svg)](https://twitter.com/wtfutil) @@ -71,7 +71,7 @@ project: | [
Lineu Felipe](https://github.com/darkSasori)
| [
Konstantin](https://github.com/kvj)
| [
Brendan O'Leary](http://www.brendanoleary.com)
| [
bertl4398](https://github.com/bertl4398)
| [
Ferenc-](https://github.com/Ferenc-)
| [
Rohan Verma](http://rohanverma.net)
| | [
Tim Fitzgerald](https://github.com/fimtitzgerald)
| [
Federico Ruggi](https://github.com/ruggi)
| [
Craig Woodward](https://github.com/ctwoodward)
| [
ReadmeCritic](https://twitter.com/ReadmeCritic)
| [
Eugene](https://github.com/jdevelop)
| [
Kenny Wu](https://github.com/Trinergy)
| | [
Renán Romero](http://www.romeroruiz.com)
| [
Bastian Groß](https://github.com/sticreations)
| [
nicholas-eden](https://github.com/nicholas-eden)
| [
Dan Rabinowitz](https://github.com/danrabinowitz)
| [
David Missmann](https://github.com/dvdmssmnn)
| [
Mathias Weber](https://github.com/mweb)
| -| [
TheRedSpy15](https://github.com/TheRedSpy15)
| [
Harald Nordgren](https://www.linkedin.com/in/harald-nordgren-44778192)
| [
Matei Alexandru Gardus](http://stormfirefox1.github.io)
| +| [
TheRedSpy15](https://github.com/TheRedSpy15)
| [
Harald Nordgren](https://www.linkedin.com/in/harald-nordgren-44778192)
| [
Matei Alexandru Gardus](http://stormfirefox1.github.io)
| [
Sean Smith](https://github.com/Seanstoppable)
| [
Halil Kaskavalci](http://kaskavalci.com)
| ## Acknowledgments diff --git a/git/display.go b/git/display.go index aedbf36c..34b143c2 100644 --- a/git/display.go +++ b/git/display.go @@ -18,7 +18,7 @@ func (widget *Widget) display() { title := fmt.Sprintf("%s - [green]%s[white]", widget.Name, repoData.Repository) widget.View.SetTitle(widget.ContextualTitle(title)) - str := wtf.SigilStr(len(widget.Data), widget.Idx, widget.View) + "\n" + str := wtf.SigilStr(len(widget.GitRepos), widget.Idx, widget.View) + "\n" str = str + " [red]Branch[white]\n" str = str + fmt.Sprintf(" %s", repoData.Branch) str = str + "\n" diff --git a/git/widget.go b/git/widget.go index 672c9754..934f2f01 100644 --- a/git/widget.go +++ b/git/widget.go @@ -4,6 +4,10 @@ import ( "github.com/gdamore/tcell" "github.com/rivo/tview" "github.com/senorprogrammer/wtf/wtf" + "io/ioutil" + "log" + "sort" + "strings" ) const HelpText = ` @@ -28,9 +32,9 @@ type Widget struct { wtf.MultiSourceWidget wtf.TextWidget - app *tview.Application - Data []*GitRepo - pages *tview.Pages + app *tview.Application + GitRepos []*GitRepo + pages *tview.Pages } func NewWidget(app *tview.Application, pages *tview.Pages) *Widget { @@ -59,7 +63,7 @@ func (widget *Widget) Checkout() { checkoutFctn := func() { text := form.GetFormItem(0).(*tview.InputField).GetText() - repoToCheckout := widget.Data[widget.Idx] + repoToCheckout := widget.GitRepos[widget.Idx] repoToCheckout.checkout(text) widget.pages.RemovePage("modal") widget.app.SetFocus(widget.View) @@ -72,7 +76,7 @@ func (widget *Widget) Checkout() { } func (widget *Widget) Pull() { - repoToPull := widget.Data[widget.Idx] + repoToPull := widget.GitRepos[widget.Idx] repoToPull.pull() widget.Refresh() @@ -81,7 +85,10 @@ func (widget *Widget) Pull() { func (widget *Widget) Refresh() { repoPaths := wtf.ToStrs(wtf.Config.UList("wtf.mods.git.repositories")) - widget.Data = widget.gitRepos(repoPaths) + widget.GitRepos = widget.gitRepos(repoPaths) + sort.Slice(widget.GitRepos, func(i, j int) bool { + return widget.GitRepos[i].Path < widget.GitRepos[j].Path + }) widget.display() } @@ -141,28 +148,84 @@ func (widget *Widget) modalFrame(form *tview.Form) *tview.Frame { } func (widget *Widget) currentData() *GitRepo { - if len(widget.Data) == 0 { + if len(widget.GitRepos) == 0 { return nil } - if widget.Idx < 0 || widget.Idx >= len(widget.Data) { + if widget.Idx < 0 || widget.Idx >= len(widget.GitRepos) { return nil } - return widget.Data[widget.Idx] + return widget.GitRepos[widget.Idx] } func (widget *Widget) gitRepos(repoPaths []string) []*GitRepo { repos := []*GitRepo{} for _, repoPath := range repoPaths { - repo := NewGitRepo(repoPath) - repos = append(repos, repo) + if strings.HasSuffix(repoPath, "/") { + repos = append(repos, findGitRepositories(make([]*GitRepo, 0), repoPath)...) + + } else { + repo := NewGitRepo(repoPath) + repos = append(repos, repo) + } } return repos } +func findGitRepositories(repositories []*GitRepo, directory string) []*GitRepo { + directory = strings.TrimSuffix(directory, "/") + + files, err := ioutil.ReadDir(directory) + if err != nil { + log.Fatal(err) + } + + var path string + + for _, file := range files { + if file.IsDir() { + path = directory + "/" + file.Name() + if file.Name() == ".git" { + path = strings.TrimSuffix(path, "/.git") + repo := NewGitRepo(path) + repositories = append(repositories, repo) + continue + } + if file.Name() == "vendor" || file.Name() == "node_modules" { + continue + } + repositories = findGitRepositories(repositories, path) + } + } + + return repositories +} + +func (widget *Widget) Next() { + widget.Idx = widget.Idx + 1 + if widget.Idx == len(widget.GitRepos) { + widget.Idx = 0 + } + + if widget.DisplayFunction != nil { + widget.DisplayFunction() + } +} + +func (widget *Widget) Prev() { + widget.Idx = widget.Idx - 1 + if widget.Idx < 0 { + widget.Idx = len(widget.GitRepos) - 1 + } + + if widget.DisplayFunction != nil { + widget.DisplayFunction() + } +} + func (widget *Widget) keyboardIntercept(event *tcell.EventKey) *tcell.EventKey { switch string(event.Rune()) { case "/": diff --git a/hackernews/widget.go b/hackernews/widget.go index a2e19c70..deb7e9f8 100644 --- a/hackernews/widget.go +++ b/hackernews/widget.go @@ -2,12 +2,13 @@ package hackernews import ( "fmt" - "github.com/gdamore/tcell" - "github.com/rivo/tview" - "github.com/senorprogrammer/wtf/wtf" "net/url" "strconv" "strings" + + "github.com/gdamore/tcell" + "github.com/rivo/tview" + "github.com/senorprogrammer/wtf/wtf" ) const HelpText = ` @@ -22,6 +23,7 @@ const HelpText = ` arrow up: Select the previous story in the list return: Open the selected story in a browser + c: Open the comments of the article ` type Widget struct { @@ -151,6 +153,14 @@ func (widget *Widget) openStory() { } } +func (widget *Widget) openComments() { + sel := widget.selected + if sel >= 0 && widget.stories != nil && sel < len(widget.stories) { + story := &widget.stories[widget.selected] + wtf.OpenFile(fmt.Sprintf("https://news.ycombinator.com/item?id=%d", story.ID)) + } +} + func (widget *Widget) unselect() { widget.selected = -1 widget.display() @@ -169,6 +179,9 @@ func (widget *Widget) keyboardIntercept(event *tcell.EventKey) *tcell.EventKey { case "r": widget.Refresh() return nil + case "c": + widget.openComments() + return nil } switch event.Key() {