~kaction/config

59e61027018d27fb8fcf0f9fea5708c2d88532e5 — Dmitry Bogatov 11 months ago 65f16bb
Add new derivation "selectors" into the universe

This derivation provides commands that allows interactively choose an
object using fzy(1) utility. These commands open pretty search window to
choose object, and print object on stdout when choice is made. It is
more fancy and more Unix-y approach than bash-completion and friends.

This commit adds 3 commands: %bug, %commit and %file, which allow
selecting identifier of bug from `git bug` list, git commit hash and
file git repository, correspondingly.

There is known issue(a80ec49) that search window behaves poorly when
strings to choose from are longer than terminal width.
3 files changed, 32 insertions(+), 0 deletions(-)

M flake.nix
M universe/default.nix
A universe/selectors/default.nix
M flake.nix => flake.nix +1 -0
@@ 122,6 122,7 @@
            };
          srht-ui = call ./universe/srht-ui;
          ssh-env = call ./universe/ssh-env;
          selectors = call ./universe/selectors;

          system-wide = callPackage ./system-v2 { };
          tempfile = pkgs.pkgsStatic.callPackage ./universe/tempfile { };

M universe/default.nix => universe/default.nix +1 -0
@@ 71,6 71,7 @@ let
      reuse # automatic management of copyright headers.
      rsync
      srht-ui
      selectors
      strace # When things break, and they break all the time.
      surfraw
      tig

A universe/selectors/default.nix => universe/selectors/default.nix +30 -0
@@ 0,0 1,30 @@
{ fzy, git, git-bug, substituteAll, execline, busybox, runCommandLocal
, writeScript }:
let
  bug = writeScript "bug-selector" ''
    #!${execline}/bin/execlineb -WS0
    pipeline { ${git-bug}/bin/git-bug ls $@ }
    pipeline { ${fzy}/bin/fzy }
    ${busybox}/bin/cut -d " " -f1
  '';
  commit = writeScript "commit-selector" ''
    #!${execline}/bin/execlineb -WS0
    pipeline {
      ${git}/bin/git
        log --date=short
            --format="%h %cd %s"
            --since="last month" $@
    } pipeline { ${fzy}/bin/fzy }
    ${busybox}/bin/cut -d " " -f1
  '';
  file = writeScript "file-selector" ''
    #!${execline}/bin/execlineb -WS0
    pipeline { ${git}/bin/git ls-files $@ }
    ${fzy}/bin/fzy
  '';
in runCommandLocal "selectors" { } ''
  mkdir -p $out/bin
  ln -sf ${bug} $out/bin/%bug
  ln -sf ${commit} $out/bin/%commit
  ln -sf ${file} $out/bin/%file
''