mirror of
https://github.com/Jguer/yay
synced 2024-09-14 13:51:12 +00:00
Merge pull request #584 from Morganamilo/completion-slow
Rework completion
This commit is contained in:
commit
74f4a44da6
14
cmd.go
14
cmd.go
|
@ -221,6 +221,11 @@ func handleConfig(option, value string) bool {
|
||||||
config.SortMode = TopDown
|
config.SortMode = TopDown
|
||||||
case "bottomup":
|
case "bottomup":
|
||||||
config.SortMode = BottomUp
|
config.SortMode = BottomUp
|
||||||
|
case "completioninterval":
|
||||||
|
n, err := strconv.Atoi(value)
|
||||||
|
if err == nil {
|
||||||
|
config.CompletionInterval = n
|
||||||
|
}
|
||||||
case "sortby":
|
case "sortby":
|
||||||
config.SortBy = value
|
config.SortBy = value
|
||||||
case "noconfirm":
|
case "noconfirm":
|
||||||
|
@ -361,13 +366,10 @@ func handlePrint() (err error) {
|
||||||
err = printUpdateList(cmdArgs)
|
err = printUpdateList(cmdArgs)
|
||||||
case cmdArgs.existsArg("w", "news"):
|
case cmdArgs.existsArg("w", "news"):
|
||||||
err = printNewsFeed()
|
err = printNewsFeed()
|
||||||
|
case cmdArgs.existsDouble("c", "complete"):
|
||||||
|
complete(true)
|
||||||
case cmdArgs.existsArg("c", "complete"):
|
case cmdArgs.existsArg("c", "complete"):
|
||||||
switch {
|
complete(false)
|
||||||
case cmdArgs.existsArg("f", "fish"):
|
|
||||||
complete("fish")
|
|
||||||
default:
|
|
||||||
complete("sh")
|
|
||||||
}
|
|
||||||
case cmdArgs.existsArg("s", "stats"):
|
case cmdArgs.existsArg("s", "stats"):
|
||||||
err = localStatistics()
|
err = localStatistics()
|
||||||
default:
|
default:
|
||||||
|
|
|
@ -2,7 +2,6 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
"fmt"
|
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
|
@ -13,7 +12,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
//CreateAURList creates a new completion file
|
//CreateAURList creates a new completion file
|
||||||
func createAURList(out *os.File, shell string) (err error) {
|
func createAURList(out *os.File) (err error) {
|
||||||
resp, err := http.Get("https://aur.archlinux.org/packages.gz")
|
resp, err := http.Get("https://aur.archlinux.org/packages.gz")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -24,22 +23,15 @@ func createAURList(out *os.File, shell string) (err error) {
|
||||||
|
|
||||||
scanner.Scan()
|
scanner.Scan()
|
||||||
for scanner.Scan() {
|
for scanner.Scan() {
|
||||||
fmt.Print(scanner.Text())
|
|
||||||
out.WriteString(scanner.Text())
|
out.WriteString(scanner.Text())
|
||||||
if shell == "fish" {
|
out.WriteString("\tAUR\n")
|
||||||
fmt.Print("\tAUR\n")
|
|
||||||
out.WriteString("\tAUR\n")
|
|
||||||
} else {
|
|
||||||
fmt.Print("\n")
|
|
||||||
out.WriteString("\n")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
//CreatePackageList appends Repo packages to completion cache
|
//CreatePackageList appends Repo packages to completion cache
|
||||||
func createRepoList(out *os.File, shell string) (err error) {
|
func createRepoList(out *os.File) (err error) {
|
||||||
dbList, err := alpmHandle.SyncDbs()
|
dbList, err := alpmHandle.SyncDbs()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
|
@ -47,15 +39,8 @@ func createRepoList(out *os.File, shell string) (err error) {
|
||||||
|
|
||||||
_ = dbList.ForEach(func(db alpm.Db) error {
|
_ = dbList.ForEach(func(db alpm.Db) error {
|
||||||
_ = db.PkgCache().ForEach(func(pkg alpm.Package) error {
|
_ = db.PkgCache().ForEach(func(pkg alpm.Package) error {
|
||||||
fmt.Print(pkg.Name())
|
|
||||||
out.WriteString(pkg.Name())
|
out.WriteString(pkg.Name())
|
||||||
if shell == "fish" {
|
out.WriteString("\t" + pkg.DB().Name() + "\n")
|
||||||
fmt.Print("\t" + pkg.DB().Name() + "\n")
|
|
||||||
out.WriteString("\t" + pkg.DB().Name() + "\n")
|
|
||||||
} else {
|
|
||||||
fmt.Print("\n")
|
|
||||||
out.WriteString("\n")
|
|
||||||
}
|
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
return nil
|
return nil
|
||||||
|
@ -63,33 +48,38 @@ func createRepoList(out *os.File, shell string) (err error) {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Complete provides completion info for shells
|
func updateCompletion(force bool) error {
|
||||||
func complete(shell string) error {
|
path := filepath.Join(cacheHome, "completion.cache")
|
||||||
var path string
|
|
||||||
|
|
||||||
if shell == "fish" {
|
|
||||||
path = filepath.Join(cacheHome, "aur_fish"+".cache")
|
|
||||||
} else {
|
|
||||||
path = filepath.Join(cacheHome, "aur_sh"+".cache")
|
|
||||||
}
|
|
||||||
info, err := os.Stat(path)
|
info, err := os.Stat(path)
|
||||||
|
|
||||||
if os.IsNotExist(err) || time.Since(info.ModTime()).Hours() > 48 {
|
if os.IsNotExist(err) || (config.CompletionInterval != -1 && time.Since(info.ModTime()).Hours() >= float64(config.CompletionInterval*24)) || force {
|
||||||
os.MkdirAll(filepath.Dir(path), 0755)
|
os.MkdirAll(filepath.Dir(path), 0755)
|
||||||
out, errf := os.Create(path)
|
out, errf := os.Create(path)
|
||||||
if errf != nil {
|
if errf != nil {
|
||||||
return errf
|
return errf
|
||||||
}
|
}
|
||||||
|
|
||||||
if createAURList(out, shell) != nil {
|
if createAURList(out) != nil {
|
||||||
defer os.Remove(path)
|
defer os.Remove(path)
|
||||||
}
|
}
|
||||||
erra := createRepoList(out, shell)
|
erra := createRepoList(out)
|
||||||
|
|
||||||
out.Close()
|
out.Close()
|
||||||
return erra
|
return erra
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Complete provides completion info for shells
|
||||||
|
func complete(force bool) error {
|
||||||
|
path := filepath.Join(cacheHome, "completion.cache")
|
||||||
|
|
||||||
|
err := updateCompletion(force)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
in, err := os.OpenFile(path, os.O_RDWR|os.O_CREATE, 0644)
|
in, err := os.OpenFile(path, os.O_RDWR|os.O_CREATE, 0644)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
78
config.go
78
config.go
|
@ -35,44 +35,45 @@ const (
|
||||||
|
|
||||||
// Configuration stores yay's config.
|
// Configuration stores yay's config.
|
||||||
type Configuration struct {
|
type Configuration struct {
|
||||||
BuildDir string `json:"buildDir"`
|
BuildDir string `json:"buildDir"`
|
||||||
Editor string `json:"editor"`
|
Editor string `json:"editor"`
|
||||||
EditorFlags string `json:"editorflags"`
|
EditorFlags string `json:"editorflags"`
|
||||||
MakepkgBin string `json:"makepkgbin"`
|
MakepkgBin string `json:"makepkgbin"`
|
||||||
MakepkgConf string `json:"makepkgconf"`
|
MakepkgConf string `json:"makepkgconf"`
|
||||||
PacmanBin string `json:"pacmanbin"`
|
PacmanBin string `json:"pacmanbin"`
|
||||||
PacmanConf string `json:"pacmanconf"`
|
PacmanConf string `json:"pacmanconf"`
|
||||||
TarBin string `json:"tarbin"`
|
TarBin string `json:"tarbin"`
|
||||||
ReDownload string `json:"redownload"`
|
ReDownload string `json:"redownload"`
|
||||||
ReBuild string `json:"rebuild"`
|
ReBuild string `json:"rebuild"`
|
||||||
AnswerClean string `json:"answerclean"`
|
AnswerClean string `json:"answerclean"`
|
||||||
AnswerDiff string `json:"answerdiff"`
|
AnswerDiff string `json:"answerdiff"`
|
||||||
AnswerEdit string `json:"answeredit"`
|
AnswerEdit string `json:"answeredit"`
|
||||||
AnswerUpgrade string `json:"answerupgrade"`
|
AnswerUpgrade string `json:"answerupgrade"`
|
||||||
GitBin string `json:"gitbin"`
|
GitBin string `json:"gitbin"`
|
||||||
GpgBin string `json:"gpgbin"`
|
GpgBin string `json:"gpgbin"`
|
||||||
GpgFlags string `json:"gpgflags"`
|
GpgFlags string `json:"gpgflags"`
|
||||||
MFlags string `json:"mflags"`
|
MFlags string `json:"mflags"`
|
||||||
SortBy string `json:"sortby"`
|
SortBy string `json:"sortby"`
|
||||||
GitFlags string `json:"gitflags"`
|
GitFlags string `json:"gitflags"`
|
||||||
RemoveMake string `json:"removemake"`
|
RemoveMake string `json:"removemake"`
|
||||||
RequestSplitN int `json:"requestsplitn"`
|
RequestSplitN int `json:"requestsplitn"`
|
||||||
SearchMode int `json:"-"`
|
SearchMode int `json:"-"`
|
||||||
SortMode int `json:"sortmode"`
|
SortMode int `json:"sortmode"`
|
||||||
SudoLoop bool `json:"sudoloop"`
|
CompletionInterval int `json:"completionrefreshtime"`
|
||||||
TimeUpdate bool `json:"timeupdate"`
|
SudoLoop bool `json:"sudoloop"`
|
||||||
NoConfirm bool `json:"-"`
|
TimeUpdate bool `json:"timeupdate"`
|
||||||
Devel bool `json:"devel"`
|
NoConfirm bool `json:"-"`
|
||||||
CleanAfter bool `json:"cleanAfter"`
|
Devel bool `json:"devel"`
|
||||||
GitClone bool `json:"gitclone"`
|
CleanAfter bool `json:"cleanAfter"`
|
||||||
Provides bool `json:"provides"`
|
GitClone bool `json:"gitclone"`
|
||||||
PGPFetch bool `json:"pgpfetch"`
|
Provides bool `json:"provides"`
|
||||||
UpgradeMenu bool `json:"upgrademenu"`
|
PGPFetch bool `json:"pgpfetch"`
|
||||||
CleanMenu bool `json:"cleanmenu"`
|
UpgradeMenu bool `json:"upgrademenu"`
|
||||||
DiffMenu bool `json:"diffmenu"`
|
CleanMenu bool `json:"cleanmenu"`
|
||||||
EditMenu bool `json:"editmenu"`
|
DiffMenu bool `json:"diffmenu"`
|
||||||
CombinedUpgrade bool `json:"combinedupgrade"`
|
EditMenu bool `json:"editmenu"`
|
||||||
UseAsk bool `json:"useask"`
|
CombinedUpgrade bool `json:"combinedupgrade"`
|
||||||
|
UseAsk bool `json:"useask"`
|
||||||
}
|
}
|
||||||
|
|
||||||
var version = "7.885"
|
var version = "7.885"
|
||||||
|
@ -163,6 +164,7 @@ func defaultSettings(config *Configuration) {
|
||||||
config.MFlags = ""
|
config.MFlags = ""
|
||||||
config.GitFlags = ""
|
config.GitFlags = ""
|
||||||
config.SortMode = BottomUp
|
config.SortMode = BottomUp
|
||||||
|
config.CompletionInterval = 7
|
||||||
config.SortBy = "votes"
|
config.SortBy = "votes"
|
||||||
config.SudoLoop = false
|
config.SudoLoop = false
|
||||||
config.TarBin = "bsdtar"
|
config.TarBin = "bsdtar"
|
||||||
|
|
|
@ -312,6 +312,8 @@ func install(parser *arguments) error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
go updateCompletion(false)
|
||||||
|
|
||||||
err = downloadPkgBuildsSources(do.Aur, do.Bases, incompatible)
|
err = downloadPkgBuildsSources(do.Aur, do.Bases, incompatible)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
Loading…
Reference in a new issue