From 7c5f6f2553bdc1762492f3ebd24f0a1b3233001e Mon Sep 17 00:00:00 2001 From: al1-ce Date: Fri, 25 Nov 2022 01:09:12 +0300 Subject: [PATCH] config + dub --- README.md | 39 +++++++++++++--- dub.json | 8 +++- readme/screenshot_special_bw.png | Bin 0 -> 18106 bytes src/pkm/app.d | 59 ++++++++++++++++++++--- src/pkm/config.d | 77 +++++++++++++++++++++++++++++++ src/pkm/search.d | 70 ++++++++++++++++------------ 6 files changed, 209 insertions(+), 44 deletions(-) create mode 100644 readme/screenshot_special_bw.png create mode 100644 src/pkm/config.d diff --git a/README.md b/README.md index 59cd16e..56f8473 100644 --- a/README.md +++ b/README.md @@ -24,9 +24,15 @@ Compilation of this repository requires [dlang](https://dlang.org). 1. Go to [releases](https://github.com/al1-ce/pkm/releases) and download binary. 2. Copy downloaded binary `./bin/pkm` to somewhere in your path, for example `~/.local/bin/` - +### 2.3 AUR - +Not implemented yet + +### 2.4 dub + +1. Fetch package with `dub fetch pkm` +2. Run with `dub run pkm -b release -- [args...]` +3. Build and install into `/usr/bin` with `dub build -b release -c install` ## Commands @@ -48,7 +54,25 @@ If you want to perform any of following command only on AUR then add `--aur` or | stats | Print system statistics. | `yay -Ps` | pkgbuild | Print PKGBUILD file | `yay -Gp [packages...]` - +## Config + +pkm can be configured with config file located at `~/.config/pkm/conf.yaml` or `~/.pkm.yaml` one at `~` takes prority. + +| Name | Type | Description | Default | +| :----| :--- | :---------- | :------ | +| yaypath | string | Custom path to yay binary. | Guessed with `which` | +| yaysearch | bool | Disable custom pkm search. | `false` | +| color | bool | Should search be printed in color.
Will not work if `yaysearch` is `true`. | `true` | +| auronly | bool | Should yay search only AUR. | `false` | + +Example config: + +```yaml +# conf.yaml +yaypath: ~/.local/bin/yay +yaysearch: yes +auronly: yes +``` ## How to read search All available `pkm` commands are calling `yay` with corresponding flags. This is true for search, but pkm also performs special operations to customise and improve yay's search. @@ -61,16 +85,17 @@ package-name [a] [o] [i] version/installed-version package-size/votes install- ``` ![](readme/screenshot_special.png) +![](readme/screenshot_special_bw.png) Here's small table to assist you in reading it: | Field | Meaning | Special notes | | :- | :- | :- | | package-name | Name of package. | | -| [a] | Is package orphaned. | Highlighted in red when true. "A" stands for abandoned. | -| [a] | Is package outdated. | Highlighted in red when true. | -| [a] | Is package installed. | Highlighted in green when true. | -| version | Version of package. | If installed version is different from current verison then field shows installed version hightlighed in light magenta. | +| [a] | Is package orphaned. | Highlighted in red when true. If color is disabled displayed as [ ]. "A" stands for abandoned. | +| [o] | Is package outdated. | Highlighted in red when true. If color is disabled displayed as [ ]. | +| [i] | Is package installed. | Highlighted in green when true. If color is disabled displayed as [ ]. | +| version | Version of package. | If installed version is different from current verison then field shows installed version hightlighed in light magenta. If color is disabled version diff shown with `@` at start. | | package-size/votes | See notes. | If package from AUR: Package votes.
If package not from AUR: Package size. | package-size/votes | See notes. | If package from AUR: Package popularity.
If package not from AUR: Installation size. | [repo] | Repository of package. | Repository name is cropped to 3 symbols. diff --git a/dub.json b/dub.json index 207dd17..da8742b 100644 --- a/dub.json +++ b/dub.json @@ -10,5 +10,11 @@ "license": "MIT License", "name": "pkm", "targetName": "pkm", - "targetPath": "bin" + "targetPath": "bin/", + "configurations": [{ + "name": "install", + "targetName": "pkm", + "targetPath": "bin", + "postBuildCommands": ["echo Copying binary to /usr/bin && sudo mv bin/pkm /usr/bin/pkm"] + }] } \ No newline at end of file diff --git a/readme/screenshot_special_bw.png b/readme/screenshot_special_bw.png new file mode 100644 index 0000000000000000000000000000000000000000..5137cfbd0081c26a5526f8d4de1c87b01f4c2c4b GIT binary patch literal 18106 zcmZsDWmH^Qv}SM(65JuUOK^7x?oJUPxVuB};3T-aySoMtR=5*_6z;B5q`Tkio|zxi zf^`e-<;Xst?Fv&;ka~-VkND=zo3|gO#Z}(CfvN|8FAWb1ejV^@QGW9V!p=fWOv%F7 z_{|%dZ!X_DWJQ&62mCAz^U;+9#RCH+0!1;!ZA=0qf|5lvA^=^GLQFSwWECQ^fs<$r zm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9 +1,13 @@ import std.stdio; import std.getopt; import std.array: popFront, join; -import std.process: execute, environment, executeShell, Config, spawnProcess, wait; +import std.process: execute, environment, executeShell, spawnProcess, wait; +import std.algorithm: canFind; +import std.file: readText, tempDir, remove, exists; +import std.path: buildNormalizedPath, absolutePath, expandTilde, baseName; import pkm.search; +import pkm.config; import sily.getopt; @@ -27,7 +31,9 @@ import sily.getopt; // stats | yay -Ps // pkgbuild | yay -G term | yay -Gp term -private const string _version = "pkm v1.0.0"; +private const string _version = "pkm v1.1.0"; + +string fixPath(string path) { return path.buildNormalizedPath.expandTilde.absolutePath; } int main(string[] args) { version(Windows) { @@ -70,19 +76,58 @@ int main(string[] args) { return 0; } - string yay = "/usr/bin/yay"; + string[] configPath = [ + "~/.pkm.yaml".fixPath, + "~/.config/pkm/conf.yaml".fixPath, + ]; + Config conf = getConfig(configPath); + + string yay = ""; + bool yayDefined = false; + string cyay = conf.yaypath.fixPath; + if (cyay != "" && ( + (cyay.exists && cyay.baseName == "yay") || + (exists(cyay ~ "/yay")))) { + yayDefined = true; + yay = cyay; + } else if (cyay != "") { + writefln("Cannot find yay in \"%s\". \nAttempting to guess yay location.", conf.yaypath); + yay = "/usr/bin/yay"; + } + + if (!yayDefined) { + string tmpFile = tempDir ~ "/" ~ "pkm-yay-path.txt"; + tmpFile = tmpFile.buildNormalizedPath.absolutePath; + + auto processOut = File(tmpFile, "w+"); + wait(spawnProcess(["which", "yay"], std.stdio.stdin, processOut)); + processOut.close(); + string _out = tmpFile.readText(); + remove(tmpFile); + + if (_out.canFind("which: no yay in")) { + writeln("Error: cannot find yay."); + return 1; + } else { + yay = _out; + } + } string[] ops = args.dup; ops.popFront(); // removes [0] command ops.popFront(); // removes 'command' - if (optAur) { + if (optAur || conf.auronly) { ops ~= ["--aur"]; } switch (args[1]) { case "search": - return search(ops); + if (conf.yaysearch) { + return wait(spawnProcess([yay, "-Ss"] ~ ops)); + } else { + return search(ops, conf.color); + } case "list": return wait(spawnProcess([yay, "-Q"])); case "info": @@ -107,7 +152,7 @@ int main(string[] args) { case "pkgbuild": return wait(spawnProcess([yay, "-Gp"] ~ ops)); default: - writefln("Unknown command \"%s\".", args[1]); - return 1; + writefln("Unknown command \"%s\". Executing as is.", args[1]); + return wait(spawnProcess([yay] ~ ops)); } } diff --git a/src/pkm/config.d b/src/pkm/config.d new file mode 100644 index 0000000..2b49dca --- /dev/null +++ b/src/pkm/config.d @@ -0,0 +1,77 @@ +module pkm.config; + +import std.conv: to; +import std.file: exists; +import std.stdio: writeln; + +import dyaml; + +Config getConfig(string[] paths) { + foreach (path; paths) { + if (path.exists) { + return __getConfig(path); + } + } + return Config(); +} + +Config __getConfig(string configPath) { + Node root; + try { + root = Loader.fromFile(configPath).load(); + } catch (YAMLException e) { + return Config(); + } + + Config conf; + + if (root.type != NodeType.mapping) return conf; + + root.getKey!string(&conf.yaypath, "yaypath"); + root.getKey!bool(&conf.yaysearch, "yaysearch"); + root.getKey!bool(&conf.color, "color"); + root.getKey!bool(&conf.auronly, "auronly"); + + return conf; +} + +string configGetGlobal(string configPath, string field) { + Node root = Loader.fromFile(configPath).load(); + + if (root.type != NodeType.mapping) return ""; + if (!root.containsKeyAs!string(field)) return ""; + + return root[field].as!string; +} + +private bool containsKeyType(Node node, string key, NodeType type) { + if (node.containsKey(key)) { + if (node[key].type == type) { + return true; + } + } + return false; +} + +private bool containsKeyAs(T)(Node node, string key) { + if (node.containsKey(key)) { + if (node[key].convertsTo!T) { + return true; + } + } + return false; +} + +private void getKey(T)(Node node, T* variable, string field) { + if (node.containsKeyAs!T(field)) { + *variable = node[field].as!T; + } +} + + +struct Config { + string yaypath = ""; + bool yaysearch = false; + bool color = true; + bool auronly = false; +} \ No newline at end of file diff --git a/src/pkm/search.d b/src/pkm/search.d index 3de5733..8c51293 100644 --- a/src/pkm/search.d +++ b/src/pkm/search.d @@ -26,7 +26,7 @@ private auto reg = regex( r"(?:\s\((Orphaned)\))?(?:\s\(Out-of-date:\s(.*?)\))?" ~ r"(?:\s\((Installed)(?:\:\s(.*?))?\))?(?:\s{6}|\s{5})(.*)(?:\r|\n|\z)", "gm"); -int search(string[] terms) { +int search(string[] terms, bool color) { string yay = "/usr/bin/yay"; string tmpFile = tempDir ~ "/" ~ "pkm-yay-search-output.txt"; tmpFile = tmpFile.buildNormalizedPath.absolutePath; @@ -43,7 +43,7 @@ int search(string[] terms) { return pidErr; } - printPackages(tmpFile, terms); + printPackages(tmpFile, terms, color); remove(tmpFile); @@ -55,7 +55,7 @@ int search(string[] terms) { // repo/name version (size|aur-votes) [group]? (orphaned) // 7 8 9 10 // (outofdate) (installed: (version)) \n (description) -void printPackages(string tmpFile, string[] searchTerms) { +void printPackages(string tmpFile, string[] searchTerms, bool color) { string contents = readText(tmpFile); Pkg[] pkgs = []; @@ -98,19 +98,19 @@ void printPackages(string tmpFile, string[] searchTerms) { })(pkgs); foreach (pkg; pkgs) { - printPackage(pkg); + printPackage(pkg, color); } } -void printPackage(Pkg pkg) { +void printPackage(Pkg pkg, bool color) { // if (!(pkg.isOrphaned || pkg.isInstalled || pkg.isOutdated)) return; winsize w; ioctl(0, TIOCGWINSZ, &w); int terminalWidth = w.ws_col; - string installstr = "[i]"; - string orphanedstr = "[a]"; - string outdatedstr = "[o]"; + string installstr = color || pkg.isInstalled ? "[i]" : "[ ]"; + string orphanedstr = color || pkg.isOrphaned ? "[a]" : "[ ]"; + string outdatedstr = color || pkg.isOutdated ? "[o]" : "[ ]"; ulong flagsLength = installstr.length + orphanedstr.length + outdatedstr.length + 2; ulong installPos = 1; @@ -122,37 +122,37 @@ void printPackage(Pkg pkg) { write(' '.repeat(installPos)); if (pkg.isOrphaned) { - write(FG.ltred ~ orphanedstr ~ FG.reset); + writecol(FG.ltred, color,orphanedstr); } else { // write(' '.repeat(orphanedstr.length)); - write(FG.dkgray ~ orphanedstr ~ FG.reset); + writecol(FG.dkgray, color, orphanedstr); } write(' '); if (pkg.isOutdated) { - write(FG.ltred ~ outdatedstr ~ FG.reset); + writecol(FG.ltred, color, outdatedstr); } else { // write(' '.repeat(outdatedstr.length)); - write(FG.dkgray ~ outdatedstr ~ FG.reset); + writecol(FG.dkgray, color, outdatedstr); } write(' '); if (pkg.isInstalled) { - write(FG.ltgreen ~ installstr ~ FG.reset); + writecol(FG.ltgreen, color, installstr); } else { // write(' '.repeat(installstr.length)); - write(FG.dkgray ~ installstr ~ FG.reset); + writecol(FG.dkgray, color, installstr); } write(' '); - ulong verlen = pkg.installedVersion != "" ? pkg.installedVersion.length : pkg.ver.length; + ulong verlen = pkg.installedVersion != "" ? pkg.installedVersion.length + (color ? 0 : 1) : pkg.ver.length; if (pkg.installedVersion != "") { - write(FG.ltmagenta ~ pkg.installedVersion ~ FG.reset); + writecol(FG.ltmagenta, color, (color ? "" : "@") ~ pkg.installedVersion); } else { - write(FG.cyan ~ pkg.ver ~ FG.reset); + writecol(FG.cyan, color, pkg.ver); } ulong reposize = "[aur]".length + 1; @@ -182,34 +182,46 @@ void printPackage(Pkg pkg) { if (popul >= 20.0) colpop = FG.ltcyan; if (popul >= 30.0) colpop = FG.ltgreen; if (popul >= 40.0) colpop = FG.ltblue; - write(colvot ~ pkg.aurvotes ~ FG.reset); + writecol(colvot, color, pkg.aurvotes); write(' '); - write(colpop ~ pkg.aurpopul ~ FG.reset); + writecol(colpop, color, pkg.aurpopul); } else { - write(FG.reset ~ pkg.pkgsize ~ FG.reset); + writecol(FG.reset, color, pkg.pkgsize); write(' '); - write(FG.reset ~ pkg.inssize ~ FG.reset); + writecol(FG.reset, color, pkg.inssize); } write(' '); + FG repocol = FG.reset; switch (pkg.repo) { - case "aur": write(FG.ltblue ~ ""); break; - case "core": write(FG.ltyellow ~ ""); break; - case "extra": write(FG.ltgreen ~ ""); break; - case "community": write(FG.ltmagenta ~ ""); break; + case "aur": repocol = FG.ltblue; break; + case "core": repocol = FG.ltyellow; break; + case "extra": repocol = FG.ltgreen; break; + case "community": repocol = FG.ltmagenta; break; default: if (pkg.repo.canFind("testing")) { - write(FG.ltred ~ ""); + repocol = FG.ltred; } else { - write(FG.ltcyan); + repocol = FG.ltcyan; } break; } - write("[" ~ pkg.repo[0..3] ~ "]"); - write(FG.reset ~ ""); + writecol(repocol, color, "[" ~ pkg.repo[0..3] ~ "]"); writeln(); writeln(" " ~ pkg.description); // writeln(); } + +void writecol(FG col, bool enabled, string args) { + if (enabled) { + write(col ~ args ~ FG.reset); + } else { + write(args); + } +} + +void writelncol(FG col, bool enabled, string args) { + writecol(col, enabled, args ~ "\n"); +} \ No newline at end of file