image support!!!
This commit is contained in:
parent
c291f35c95
commit
1fe82665ad
1
.gitignore
vendored
1
.gitignore
vendored
@ -6,3 +6,4 @@ result/
|
|||||||
./pkg
|
./pkg
|
||||||
./goGoFetch
|
./goGoFetch
|
||||||
/gogofetch-git-r14.ff1fcf9-1-x86_64.pkg.tar.zst
|
/gogofetch-git-r14.ff1fcf9-1-x86_64.pkg.tar.zst
|
||||||
|
./gogofetch-git
|
||||||
2
PKGBUILD
2
PKGBUILD
@ -7,7 +7,7 @@
|
|||||||
pkgname=gogofetch-git
|
pkgname=gogofetch-git
|
||||||
pkgver=r14.ff1fcf9
|
pkgver=r14.ff1fcf9
|
||||||
pkgrel=2
|
pkgrel=2
|
||||||
pkgdesc="fetch made with C++ rewritten to go for no reason"
|
pkgdesc="Fetch written in Go with image support"
|
||||||
arch=('x86_64')
|
arch=('x86_64')
|
||||||
url="git+https://codeberg.org/nekohepott/goGoFetch.git"
|
url="git+https://codeberg.org/nekohepott/goGoFetch.git"
|
||||||
license=('MIT')
|
license=('MIT')
|
||||||
|
|||||||
49
README.md
49
README.md
@ -1,15 +1,33 @@
|
|||||||
# Build
|
# Fetch written in Go with image support (only for foot and kitty)
|
||||||
to build:
|
|
||||||
|

|
||||||
|
|
||||||
|
# Install
|
||||||
|
you can get gogofetch on AUR!
|
||||||
|
```bash
|
||||||
|
yay -S gogofetch-git
|
||||||
```
|
```
|
||||||
go build main.go
|
|
||||||
|
# Usage
|
||||||
|
basic usage:
|
||||||
|
```bash
|
||||||
|
gogofetch
|
||||||
```
|
```
|
||||||
to run:
|
to show custom image (only png supported btw):
|
||||||
|
```bash
|
||||||
|
gogofetch -i *absolute_path*
|
||||||
```
|
```
|
||||||
./main
|
to show custom image and set custom width:
|
||||||
|
```bash
|
||||||
|
gogofetch -i *absolute_path* -w 250
|
||||||
|
```
|
||||||
|
to show help message:
|
||||||
|
```bash
|
||||||
|
gogofetch -h
|
||||||
```
|
```
|
||||||
|
|
||||||
# NixOS
|
# NixOS
|
||||||
credits to melvi for this
|
credits to melvi for flake
|
||||||
|
|
||||||
to build with nix:
|
to build with nix:
|
||||||
```bash
|
```bash
|
||||||
@ -19,7 +37,6 @@ to run with nix:
|
|||||||
```
|
```
|
||||||
nix run
|
nix run
|
||||||
```
|
```
|
||||||
|
|
||||||
to install with nixos:
|
to install with nixos:
|
||||||
|
|
||||||
1. Add to inputs:
|
1. Add to inputs:
|
||||||
@ -40,5 +57,19 @@ home.packages = [
|
|||||||
```
|
```
|
||||||
3. Run rebuild and then you can run fetch with *gogofetch* command
|
3. Run rebuild and then you can run fetch with *gogofetch* command
|
||||||
|
|
||||||
# Screenshots
|
|
||||||

|
# Build
|
||||||
|
to build:
|
||||||
|
```
|
||||||
|
git clone https://codeberg.org/nekohepott/goGoFetch
|
||||||
|
cd goGoFetch
|
||||||
|
go build main.go
|
||||||
|
```
|
||||||
|
and run:
|
||||||
|
```
|
||||||
|
./main
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
BIN
assets/arch.png
(Stored with Git LFS)
Normal file
BIN
assets/arch.png
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
assets/debian.png
(Stored with Git LFS)
Normal file
BIN
assets/debian.png
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
assets/linux.png
(Stored with Git LFS)
Normal file
BIN
assets/linux.png
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
assets/nixos.png
(Stored with Git LFS)
Normal file
BIN
assets/nixos.png
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
assets/screenshot.png
(Stored with Git LFS)
BIN
assets/screenshot.png
(Stored with Git LFS)
Binary file not shown.
7
go.mod
7
go.mod
@ -1,3 +1,10 @@
|
|||||||
module goGoFetch
|
module goGoFetch
|
||||||
|
|
||||||
go 1.26
|
go 1.26
|
||||||
|
|
||||||
|
require github.com/mattn/go-sixel v0.0.8
|
||||||
|
|
||||||
|
require (
|
||||||
|
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646 // indirect
|
||||||
|
github.com/soniakeys/quant v1.0.0 // indirect
|
||||||
|
)
|
||||||
|
|||||||
8
go.sum
Normal file
8
go.sum
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
github.com/BurntSushi/toml v1.6.0 h1:dRaEfpa2VI55EwlIW72hMRHdWouJeRF7TPYhI+AUQjk=
|
||||||
|
github.com/BurntSushi/toml v1.6.0/go.mod h1:ukJfTF/6rtPPRCnwkur4qwRxa8vTRFBF0uk2lLoLwho=
|
||||||
|
github.com/mattn/go-sixel v0.0.8 h1:H0bBGQVOJoSvzvtTgCInxvg1IZiNlTcIIIx8A6uvjpQ=
|
||||||
|
github.com/mattn/go-sixel v0.0.8/go.mod h1:wbDSbrwpykVI1qEHyjZYsDgaJTwpVg9wSwmmh2slnBw=
|
||||||
|
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646 h1:zYyBkD/k9seD2A7fsi6Oo2LfFZAehjjQMERAvZLEDnQ=
|
||||||
|
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646/go.mod h1:jpp1/29i3P1S/RLdc7JQKbRpFeM1dOBd8T9ki5s+AY8=
|
||||||
|
github.com/soniakeys/quant v1.0.0 h1:N1um9ktjbkZVcywBVAAYpZYSHxEfJGzshHCxx/DaI0Y=
|
||||||
|
github.com/soniakeys/quant v1.0.0/go.mod h1:HI1k023QuVbD4H8i9YdfZP2munIHU4QpjsImz6Y6zds=
|
||||||
100
main.go
100
main.go
@ -2,22 +2,37 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
|
"bytes"
|
||||||
|
"encoding/base64"
|
||||||
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"image"
|
||||||
|
"image/png"
|
||||||
|
_ "image/png"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/mattn/go-sixel"
|
||||||
|
"github.com/nfnt/resize"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
Reset = "\033[0m"
|
Reset = "\033[0m"
|
||||||
GreenBold = "\033[1;32m"
|
Blue = "\033[1;34m"
|
||||||
BlueBright = "\033[94m"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var dist string
|
var dist string
|
||||||
|
|
||||||
|
var logoMap = map[string]string{
|
||||||
|
"Arch Linux": "assets/arch.png",
|
||||||
|
"Debian": "assets/debian.png",
|
||||||
|
"NixOS": "assets/nixos.png",
|
||||||
|
"default": "assets/linux.png",
|
||||||
|
}
|
||||||
|
|
||||||
func getDist() string {
|
func getDist() string {
|
||||||
f, _ := os.Open("/etc/os-release")
|
f, _ := os.Open("/etc/os-release")
|
||||||
defer func(f *os.File) {
|
defer func(f *os.File) {
|
||||||
@ -161,24 +176,51 @@ func getPkgs() string {
|
|||||||
return "unknown"
|
return "unknown"
|
||||||
}
|
}
|
||||||
|
|
||||||
func getAscii() string {
|
//func getAscii() string {
|
||||||
var ascii string
|
// var ascii string
|
||||||
if strings.HasPrefix(dist, "Arch") {
|
// if strings.HasPrefix(dist, "Arch") {
|
||||||
content := " _ _ _\n /\\ | | | | (_)\n / \\ _ __ ___| |__ | | _ _ __ _ ___ __\n / /\\ \\ | '__/ __| '_ \\ | | | | '_ \\| | | \\ \\/ /\n / ____ \\| | | (__| | | | | |____| | | | | |_| |> <\n /_/ \\_\\_| \\___|_| |_| |______|_|_| |_|\\__,_/_/\\_\\\n"
|
// content := " _ _ _\n /\\ | | | | (_)\n / \\ _ __ ___| |__ | | _ _ __ _ ___ __\n / /\\ \\ | '__/ __| '_ \\ | | | | '_ \\| | | \\ \\/ /\n / ____ \\| | | (__| | | | | |____| | | | | |_| |> <\n /_/ \\_\\_| \\___|_| |_| |______|_|_| |_|\\__,_/_/\\_\\\n"
|
||||||
ascii = fmt.Sprintf(content)
|
// ascii = fmt.Sprintf(content)
|
||||||
return ascii
|
// return ascii
|
||||||
|
// }
|
||||||
|
// if strings.HasPrefix(dist, "Debian") {
|
||||||
|
// content := " _____ _ _\n | __ \\ | | (_)\n | | | | ___ | |__ _ __ _ _ __\n | | | | / _ \\ | '_ \\ | | / _` | | '_ \\\n | |__| | | __/ | |_) | | | | (_| | | | | |\n |_____/ \\___| |_.__/ |_| \\__,_| |_| |_|\n"
|
||||||
|
// ascii = fmt.Sprintf(content)
|
||||||
|
// return ascii
|
||||||
|
// }
|
||||||
|
// if strings.HasPrefix(dist, "NixOS") {
|
||||||
|
// content := " _ _ _ ____ _____\n | \\ | (_) / __ \\ / ____|\n | \\| |___ _| | | | (___\n | . ` | \\ \\/ / | | |\\___ \\\n | |\\ | |> <| |__| |____) |\n |_| \\_|_/_/\\_\\\\____/|_____/\n"
|
||||||
|
// ascii = fmt.Sprintf(content)
|
||||||
|
// return ascii
|
||||||
|
// }
|
||||||
|
// return "unknown"
|
||||||
|
//}
|
||||||
|
|
||||||
|
func printLogo(path string, Width uint) {
|
||||||
|
file, _ := os.Open(path)
|
||||||
|
defer func(file *os.File) {
|
||||||
|
err := file.Close()
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
}
|
}
|
||||||
if strings.HasPrefix(dist, "Debian") {
|
}(file)
|
||||||
content := " _____ _ _\n | __ \\ | | (_)\n | | | | ___ | |__ _ __ _ _ __\n | | | | / _ \\ | '_ \\ | | / _` | | '_ \\\n | |__| | | __/ | |_) | | | | (_| | | | | |\n |_____/ \\___| |_.__/ |_| \\__,_| |_| |_|\n"
|
img, _, _ := image.Decode(file)
|
||||||
ascii = fmt.Sprintf(content)
|
resizedImg := resize.Resize(Width, 0, img, resize.Lanczos3)
|
||||||
return ascii
|
if os.Getenv("KITTY_PID") != "" || os.Getenv("TERM") == "xterm-kitty" {
|
||||||
|
var buf bytes.Buffer
|
||||||
|
err := png.Encode(&buf, resizedImg)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
enc := base64.StdEncoding.EncodeToString(buf.Bytes())
|
||||||
|
fmt.Printf("\033_Gf=100,a=T;%s\033\\\n", enc)
|
||||||
|
} else {
|
||||||
|
err := sixel.NewEncoder(os.Stdout).Encode(resizedImg)
|
||||||
|
fmt.Printf("\n")
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
}
|
}
|
||||||
if strings.HasPrefix(dist, "NixOS") {
|
|
||||||
content := " _ _ _ ____ _____\n | \\ | (_) / __ \\ / ____|\n | \\| |___ _| | | | (___\n | . ` | \\ \\/ / | | |\\___ \\\n | |\\ | |> <| |__| |____) |\n |_| \\_|_/_/\\_\\\\____/|_____/\n"
|
|
||||||
ascii = fmt.Sprintf(content)
|
|
||||||
return ascii
|
|
||||||
}
|
}
|
||||||
return "unknown"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
@ -186,9 +228,14 @@ func main() {
|
|||||||
Label string
|
Label string
|
||||||
Value string
|
Value string
|
||||||
}
|
}
|
||||||
|
dist := getDist()
|
||||||
|
defaultLogo, ok := logoMap[dist]
|
||||||
|
if !ok {
|
||||||
|
defaultLogo = logoMap["default"]
|
||||||
|
}
|
||||||
|
|
||||||
stats := []Info{
|
stats := []Info{
|
||||||
{"dist", getDist()},
|
{"dist", dist},
|
||||||
{"host", getHostname()},
|
{"host", getHostname()},
|
||||||
{"cpu", getCpu()},
|
{"cpu", getCpu()},
|
||||||
{"krnl", getKernel()},
|
{"krnl", getKernel()},
|
||||||
@ -196,14 +243,19 @@ func main() {
|
|||||||
{"gpu", getGpu()},
|
{"gpu", getGpu()},
|
||||||
{"pkgs", getPkgs()},
|
{"pkgs", getPkgs()},
|
||||||
}
|
}
|
||||||
fmt.Print(BlueBright)
|
|
||||||
fmt.Printf(getAscii())
|
logoPath := flag.String("i", defaultLogo, "Absolute or relative path to the logo image (only png)")
|
||||||
fmt.Print(Reset)
|
width := flag.Int("w", 200, "Logo width in lines (400 IS MAXIMUM FOR KITTY VALUES ABOVE WILL CRASH TERMINAL)")
|
||||||
fmt.Printf("\n")
|
flag.Parse()
|
||||||
fmt.Println("---------------------------")
|
if _, err := os.Stat(*logoPath); os.IsNotExist(err) {
|
||||||
|
fmt.Printf("Image '%s' not found\n", *logoPath)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
printLogo(*logoPath, uint(*width))
|
||||||
|
|
||||||
for _, s := range stats {
|
for _, s := range stats {
|
||||||
fmt.Printf("> %s%s%s: %s\n", GreenBold, s.Label, Reset, s.Value)
|
fmt.Printf("~ %s%s%s: %s\n", Blue, s.Label, Reset, s.Value)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user