mirror of
https://github.com/Jguer/yay
synced 2024-09-01 06:08:39 +00:00
New print option, added new completion syntax, fixed fish completion
This commit is contained in:
parent
14f83053a5
commit
42889821d3
74
cmd.go
74
cmd.go
|
@ -5,13 +5,11 @@ import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var cmdArgs = makeArguments()
|
var cmdArgs = makeArguments()
|
||||||
|
@ -291,6 +289,8 @@ func handleCmd() (changedConfig bool, err error) {
|
||||||
passToPacman(cmdArgs)
|
passToPacman(cmdArgs)
|
||||||
case "G", "getpkgbuild":
|
case "G", "getpkgbuild":
|
||||||
err = handleGetpkgbuild()
|
err = handleGetpkgbuild()
|
||||||
|
case "P", "print":
|
||||||
|
err = handlePrint()
|
||||||
case "Y", "--yay":
|
case "Y", "--yay":
|
||||||
err = handleYay()
|
err = handleYay()
|
||||||
default:
|
default:
|
||||||
|
@ -314,9 +314,6 @@ func handleConfig(option string) (changedConfig bool) {
|
||||||
config.CleanAfter = true
|
config.CleanAfter = true
|
||||||
case "noafterclean":
|
case "noafterclean":
|
||||||
config.CleanAfter = false
|
config.CleanAfter = false
|
||||||
// case "printconfig":
|
|
||||||
// fmt.Printf("%#v", config)
|
|
||||||
// os.Exit(0)
|
|
||||||
// case "gendb":
|
// case "gendb":
|
||||||
// err = createDevelDB()
|
// err = createDevelDB()
|
||||||
// if err != nil {
|
// if err != nil {
|
||||||
|
@ -339,14 +336,6 @@ func handleConfig(option string) (changedConfig bool) {
|
||||||
config.SortMode = TopDown
|
config.SortMode = TopDown
|
||||||
case "--bottomup":
|
case "--bottomup":
|
||||||
config.SortMode = BottomUp
|
config.SortMode = BottomUp
|
||||||
// case "complete":
|
|
||||||
// config.Shell = "sh"
|
|
||||||
// complete()
|
|
||||||
// os.Exit(0)
|
|
||||||
// case "fcomplete":
|
|
||||||
// config.Shell = fishShell
|
|
||||||
// complete()
|
|
||||||
// os.Exit(0)
|
|
||||||
// case "help":
|
// case "help":
|
||||||
// usage()
|
// usage()
|
||||||
// os.Exit(0)
|
// os.Exit(0)
|
||||||
|
@ -367,12 +356,31 @@ func handleVersion() {
|
||||||
fmt.Printf("yay v%s\n", version)
|
fmt.Printf("yay v%s\n", version)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func handlePrint() (err error) {
|
||||||
|
switch {
|
||||||
|
case cmdArgs.existsArg("d", "defaultconfig"):
|
||||||
|
fmt.Printf("%#v", config)
|
||||||
|
case cmdArgs.existsArg("n", "numberupgrades"):
|
||||||
|
case cmdArgs.existsArg("u", "upgrades"):
|
||||||
|
case cmdArgs.existsArg("c", "complete"):
|
||||||
|
switch {
|
||||||
|
case cmdArgs.existsArg("f", "fish"):
|
||||||
|
complete("fish")
|
||||||
|
default:
|
||||||
|
complete("sh")
|
||||||
|
}
|
||||||
|
case cmdArgs.existsArg("d", "defaultconfig"):
|
||||||
|
default:
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func handleYay() (err error) {
|
func handleYay() (err error) {
|
||||||
//_, options, targets := cmdArgs.formatArgs()
|
//_, options, targets := cmdArgs.formatArgs()
|
||||||
if cmdArgs.existsArg("h", "help") {
|
if cmdArgs.existsArg("h", "help") {
|
||||||
usage()
|
usage()
|
||||||
} else if cmdArgs.existsArg("printconfig") {
|
|
||||||
fmt.Printf("%#v", config)
|
|
||||||
} else if cmdArgs.existsArg("gendb") {
|
} else if cmdArgs.existsArg("gendb") {
|
||||||
err = createDevelDB()
|
err = createDevelDB()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -382,12 +390,6 @@ func handleYay() (err error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
} else if cmdArgs.existsArg("complete") {
|
|
||||||
config.Shell = "sh"
|
|
||||||
complete()
|
|
||||||
} else if cmdArgs.existsArg("fcomplete") {
|
|
||||||
config.Shell = "fish"
|
|
||||||
complete()
|
|
||||||
} else if cmdArgs.existsArg("stats") {
|
} else if cmdArgs.existsArg("stats") {
|
||||||
err = localStatistics()
|
err = localStatistics()
|
||||||
} else if cmdArgs.existsArg("cleandeps") {
|
} else if cmdArgs.existsArg("cleandeps") {
|
||||||
|
@ -640,36 +642,6 @@ func numberMenu(pkgS []string, flags []string) (err error) {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Complete provides completion info for shells
|
|
||||||
func complete() error {
|
|
||||||
path := completionFile + config.Shell + ".cache"
|
|
||||||
info, err := os.Stat(path)
|
|
||||||
if os.IsNotExist(err) || time.Since(info.ModTime()).Hours() > 48 {
|
|
||||||
os.MkdirAll(filepath.Dir(completionFile), 0755)
|
|
||||||
out, errf := os.Create(path)
|
|
||||||
if errf != nil {
|
|
||||||
return errf
|
|
||||||
}
|
|
||||||
|
|
||||||
if createAURList(out) != nil {
|
|
||||||
defer os.Remove(path)
|
|
||||||
}
|
|
||||||
erra := createRepoList(out)
|
|
||||||
|
|
||||||
out.Close()
|
|
||||||
return erra
|
|
||||||
}
|
|
||||||
|
|
||||||
in, err := os.OpenFile(path, os.O_RDWR|os.O_CREATE, 0644)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
defer in.Close()
|
|
||||||
|
|
||||||
_, err = io.Copy(os.Stdout, in)
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
// passToPacman outsorces execution to pacman binary without modifications.
|
// passToPacman outsorces execution to pacman binary without modifications.
|
||||||
func passToPacman(args *arguments) error {
|
func passToPacman(args *arguments) error {
|
||||||
var cmd *exec.Cmd
|
var cmd *exec.Cmd
|
||||||
|
|
|
@ -3,16 +3,17 @@ package main
|
||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
"time"
|
||||||
|
|
||||||
alpm "github.com/jguer/go-alpm"
|
alpm "github.com/jguer/go-alpm"
|
||||||
)
|
)
|
||||||
|
|
||||||
const fishShell = "fish"
|
|
||||||
|
|
||||||
//CreateAURList creates a new completion file
|
//CreateAURList creates a new completion file
|
||||||
func createAURList(out *os.File) (err error) {
|
func createAURList(out *os.File, shell string) (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
|
||||||
|
@ -25,7 +26,7 @@ func createAURList(out *os.File) (err error) {
|
||||||
for scanner.Scan() {
|
for scanner.Scan() {
|
||||||
fmt.Print(scanner.Text())
|
fmt.Print(scanner.Text())
|
||||||
out.WriteString(scanner.Text())
|
out.WriteString(scanner.Text())
|
||||||
if config.Shell == fishShell {
|
if shell == "fish" {
|
||||||
fmt.Print("\tAUR\n")
|
fmt.Print("\tAUR\n")
|
||||||
out.WriteString("\tAUR\n")
|
out.WriteString("\tAUR\n")
|
||||||
} else {
|
} else {
|
||||||
|
@ -38,7 +39,7 @@ func createAURList(out *os.File) (err error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
//CreatePackageList appends Repo packages to completion cache
|
//CreatePackageList appends Repo packages to completion cache
|
||||||
func createRepoList(out *os.File) (err error) {
|
func createRepoList(out *os.File, shell string) (err error) {
|
||||||
dbList, err := alpmHandle.SyncDbs()
|
dbList, err := alpmHandle.SyncDbs()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
|
@ -48,7 +49,7 @@ func createRepoList(out *os.File) (err error) {
|
||||||
_ = db.PkgCache().ForEach(func(pkg alpm.Package) error {
|
_ = db.PkgCache().ForEach(func(pkg alpm.Package) error {
|
||||||
fmt.Print(pkg.Name())
|
fmt.Print(pkg.Name())
|
||||||
out.WriteString(pkg.Name())
|
out.WriteString(pkg.Name())
|
||||||
if config.Shell == fishShell {
|
if shell == "fish" {
|
||||||
fmt.Print("\t" + pkg.DB().Name() + "\n")
|
fmt.Print("\t" + pkg.DB().Name() + "\n")
|
||||||
out.WriteString("\t" + pkg.DB().Name() + "\n")
|
out.WriteString("\t" + pkg.DB().Name() + "\n")
|
||||||
} else {
|
} else {
|
||||||
|
@ -61,3 +62,40 @@ func createRepoList(out *os.File) (err error) {
|
||||||
})
|
})
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Complete provides completion info for shells
|
||||||
|
func complete(shell string) error {
|
||||||
|
var path string
|
||||||
|
|
||||||
|
if shell == "fish" {
|
||||||
|
path = completionFile + "fish" + ".cache"
|
||||||
|
} else {
|
||||||
|
path = completionFile + "sh" + ".cache"
|
||||||
|
}
|
||||||
|
info, err := os.Stat(path)
|
||||||
|
|
||||||
|
if os.IsNotExist(err) || time.Since(info.ModTime()).Hours() > 48 {
|
||||||
|
os.MkdirAll(filepath.Dir(completionFile), 0755)
|
||||||
|
out, errf := os.Create(path)
|
||||||
|
if errf != nil {
|
||||||
|
return errf
|
||||||
|
}
|
||||||
|
|
||||||
|
if createAURList(out, shell) != nil {
|
||||||
|
defer os.Remove(path)
|
||||||
|
}
|
||||||
|
erra := createRepoList(out, shell)
|
||||||
|
|
||||||
|
out.Close()
|
||||||
|
return erra
|
||||||
|
}
|
||||||
|
|
||||||
|
in, err := os.OpenFile(path, os.O_RDWR|os.O_CREATE, 0644)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer in.Close()
|
||||||
|
|
||||||
|
_, err = io.Copy(os.Stdout, in)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
|
@ -28,7 +28,6 @@ type Configuration struct {
|
||||||
BuildDir string `json:"buildDir"`
|
BuildDir string `json:"buildDir"`
|
||||||
Editor string `json:"editor"`
|
Editor string `json:"editor"`
|
||||||
MakepkgBin string `json:"makepkgbin"`
|
MakepkgBin string `json:"makepkgbin"`
|
||||||
Shell string `json:"-"`
|
|
||||||
PacmanBin string `json:"pacmanbin"`
|
PacmanBin string `json:"pacmanbin"`
|
||||||
PacmanConf string `json:"pacmanconf"`
|
PacmanConf string `json:"pacmanconf"`
|
||||||
TarBin string `json:"tarbin"`
|
TarBin string `json:"tarbin"`
|
||||||
|
|
|
@ -132,6 +132,8 @@ func (parser *arguments) needRoot() bool {
|
||||||
//yay specific
|
//yay specific
|
||||||
case "Y", "yay":
|
case "Y", "yay":
|
||||||
return false
|
return false
|
||||||
|
case "P", "print":
|
||||||
|
return false
|
||||||
case "G", "getpkgbuild":
|
case "G", "getpkgbuild":
|
||||||
return false
|
return false
|
||||||
default:
|
default:
|
||||||
|
@ -315,6 +317,8 @@ func isOp(op string) bool {
|
||||||
//yay specific
|
//yay specific
|
||||||
case "Y", "yay":
|
case "Y", "yay":
|
||||||
return true
|
return true
|
||||||
|
case "P", "print":
|
||||||
|
return true
|
||||||
case "G", "getpkgbuild":
|
case "G", "getpkgbuild":
|
||||||
return true
|
return true
|
||||||
default:
|
default:
|
||||||
|
|
5
yay.fish
5
yay.fish
|
@ -5,18 +5,20 @@ set -l progname yay
|
||||||
|
|
||||||
set -l listinstalled "(pacman -Q | string replace ' ' \t)"
|
set -l listinstalled "(pacman -Q | string replace ' ' \t)"
|
||||||
# This might be an issue if another package manager is also installed (e.g. for containers)
|
# This might be an issue if another package manager is also installed (e.g. for containers)
|
||||||
set -l listall "(yay --fcomplete)"
|
set -l listall "(yay -Pcf)"
|
||||||
set -l listrepos "(__fish_print_pacman_repos)"
|
set -l listrepos "(__fish_print_pacman_repos)"
|
||||||
set -l listgroups "(pacman -Sg)\t'Package Group'"
|
set -l listgroups "(pacman -Sg)\t'Package Group'"
|
||||||
set -l listpacman "(__fish_print_packages)"
|
set -l listpacman "(__fish_print_packages)"
|
||||||
set -l noopt 'not __fish_contains_opt -s S -s D -s Q -s R -s U -s T -s F database query sync remove upgrade deptest files'
|
set -l noopt 'not __fish_contains_opt -s S -s D -s Q -s R -s U -s T -s F database query sync remove upgrade deptest files'
|
||||||
set -l database '__fish_contains_opt -s D database'
|
set -l database '__fish_contains_opt -s D database'
|
||||||
set -l getpkgbuild '__fish_contains_opt -s G getpkgbuild'
|
set -l getpkgbuild '__fish_contains_opt -s G getpkgbuild'
|
||||||
|
set -l print '__fish_contains_opt -s P print'
|
||||||
set -l query '__fish_contains_opt -s Q query'
|
set -l query '__fish_contains_opt -s Q query'
|
||||||
set -l remove '__fish_contains_opt -s R remove'
|
set -l remove '__fish_contains_opt -s R remove'
|
||||||
set -l sync '__fish_contains_opt -s S sync'
|
set -l sync '__fish_contains_opt -s S sync'
|
||||||
set -l upgrade '__fish_contains_opt -s U upgrade'
|
set -l upgrade '__fish_contains_opt -s U upgrade'
|
||||||
set -l files '__fish_contains_opt -s F files'
|
set -l files '__fish_contains_opt -s F files'
|
||||||
|
set -l yayspecific '__fish_contains_opt -s Y yay'
|
||||||
|
|
||||||
complete -c pacman -e
|
complete -c pacman -e
|
||||||
complete -c pacman -f
|
complete -c pacman -f
|
||||||
|
@ -28,6 +30,7 @@ complete -c $progname -n $noopt -a "-Q" -d "Query the package database"
|
||||||
complete -c $progname -s D -f -l database -n $noopt -d 'Modify the package database'
|
complete -c $progname -s D -f -l database -n $noopt -d 'Modify the package database'
|
||||||
complete -c $progname -s Q -f -l query -n $noopt -d 'Query the package database'
|
complete -c $progname -s Q -f -l query -n $noopt -d 'Query the package database'
|
||||||
complete -c $progname -s G -f -l getpkgbuild -n $noopt -d 'Get PKGBUILD from ABS or AUR'
|
complete -c $progname -s G -f -l getpkgbuild -n $noopt -d 'Get PKGBUILD from ABS or AUR'
|
||||||
|
complete -c $progname -s P -f -l print -n $noopt -d 'Print information'
|
||||||
complete -c $progname -s R -f -l remove -n $noopt -d 'Remove packages from the system'
|
complete -c $progname -s R -f -l remove -n $noopt -d 'Remove packages from the system'
|
||||||
complete -c $progname -s S -f -l sync -n $noopt -d 'Synchronize packages'
|
complete -c $progname -s S -f -l sync -n $noopt -d 'Synchronize packages'
|
||||||
complete -c $progname -s T -f -l deptest -n $noopt -d 'Check if dependencies are installed'
|
complete -c $progname -s T -f -l deptest -n $noopt -d 'Check if dependencies are installed'
|
||||||
|
|
Loading…
Reference in a new issue