1
0
mirror of https://github.com/h7x4/nix-attr-search.git synced 2025-02-08 17:00:48 +01:00
nix-attr-search/internals/lib.nix
h7x4 f6217e4c54
Restructure project:
The project has grown quite a bit without me remembering
to make any commits...

Here's a summary of what has happened:

- Make the project friendly towards non-flake users
- Add searchers to be created: `nur-package-search`, `nix-lib-search`
- Add misc util scripts for formatting and testing code.
- Split templates into their own directory,
    as they get quite large after a while.

- Add colorized templates.
- Replace some of the xml tags with optionally colorized output.
- Add `--no-color` option
- Add json2nix script, which will convert the json-converted
    nix code back into nix.
2022-11-26 05:14:14 +01:00

60 lines
1.2 KiB
Nix

{ pkgs, lib, ... }: {
# Executables
jq = "${pkgs.jq}/bin/jq";
fzf = "${pkgs.fzf}/bin/fzf";
gomplate = "${pkgs.gomplate}/bin/gomplate";
nixfmt = "${pkgs.nixfmt}/bin/nixfmt";
bat = "${pkgs.bat}/bin/bat";
perl = "${pkgs.perl}/bin/perl";
# ANSI Colors
bold = "\\x1b[1m";
blinkred = "\\x1b[31;5m";
red = "\\x1b[31m";
green = "\\x1b[32m";
yellow = "\\x1b[33m";
blue = "\\x1b[34m";
magenta = "\\x1b[35m";
clear = "\\x1b[0m";
# Misc functionality
# flatten takes a string that might be formatted like this:
#
# ''
# A string
# with some random indents
#
# and
#
# newlines
# ''
#
# And turns it into this:
#
# ''
# A string
# with some random indents
# and
# newlines
# ''
#
# Useful for keeping track of gomplates logic
# while keeping the template flat
#
# flatten :: String -> String
flatten = with lib;
let
stripPrefixSpace = s:
if hasPrefix " " s then
stripPrefixSpace ((substring 1 (stringLength s)) s)
else
s;
in (flip pipe) [
(splitString "\n")
(remove "")
(map stripPrefixSpace)
(concatStringsSep "\n")
];
}