Compare commits
2 commits
1e7b7d1614
...
bb8520e7a3
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bb8520e7a3 | ||
|
|
660dfc1b9c |
1 changed files with 40 additions and 32 deletions
72
flake.nix
72
flake.nix
|
|
@ -32,7 +32,7 @@
|
|||
default = pkgs.ocamlPackages.buildDunePackage {
|
||||
pname = "inshellah";
|
||||
version = "0.1";
|
||||
src = ./.;
|
||||
src = pkgs.lib.cleanSource ./.;
|
||||
nativeBuildInputs = [ pkgs.git ];
|
||||
buildInputs = with pkgs.ocamlPackages; [
|
||||
dune_3
|
||||
|
|
@ -57,40 +57,48 @@
|
|||
imports = [ ./nix/module.nix ];
|
||||
programs.inshellah.package = self.packages.${pkgs.stdenv.hostPlatform.system}.default;
|
||||
programs.inshellah.snippet = ''
|
||||
let inshellah_complete = { |spans|
|
||||
let completions = inshellah complete ...$spans | from json
|
||||
# special case nix completions, for `nix run nixpkgs#..` type input
|
||||
let additional = if ($completions == null and
|
||||
($spans | length) > 0 and $spans.0 == "nix") {
|
||||
$env.NIX_GET_COMPLETIONS = ($spans | length) - 1
|
||||
let nix_output = $spans | run-external $in | split row -r '\n' | str trim | skip 1
|
||||
let entries = $nix_output |
|
||||
if (($in | length) < 6 and
|
||||
($spans | last) =~ "[a-zA-Z][a-zA-Z0-9_-]*#[a-zA-Z][a-zA-Z0-9_-]*") {
|
||||
hide-env NIX_GET_COMPLETIONS
|
||||
$env.NIX_ALLOW_UNFREE = 1
|
||||
$env.NIX_ALLOW_BROKEN = 1
|
||||
$in | par-each { |e|
|
||||
try {
|
||||
{ value: $e, description: (^nix eval --impure $e --apply "f: f.meta.description" err> /dev/null) }
|
||||
} catch {} finally {
|
||||
{ value: $e, description: "" }
|
||||
let inshellah_complete = { |spans|
|
||||
let completions = (^inshellah complete ...$spans) | from json
|
||||
# dynamic completions
|
||||
let additional = if ($completions == null and
|
||||
($spans | length) > 0) {
|
||||
match $spans.0 {
|
||||
"nix" => {
|
||||
$env.NIX_GET_COMPLETIONS = ($spans | length) - 1
|
||||
let nix_output = $spans | run-external $in | split row -r '\n' | str trim | skip 1
|
||||
let entries = if (($nix_output | length) < 6 and
|
||||
($spans | last) =~ "[a-zA-Z][a-zA-Z0-9_-]*#[a-zA-Z][a-zA-Z0-9_-]*") {
|
||||
hide-env NIX_GET_COMPLETIONS
|
||||
$env.NIX_ALLOW_UNFREE = 1
|
||||
$env.NIX_ALLOW_BROKEN = 1
|
||||
$nix_output | par-each { |e|
|
||||
try {
|
||||
{ value: $e, description: (^nix eval --impure $e --apply "f: f.meta.description" err> /dev/null) }
|
||||
} catch {} finally {
|
||||
{ value: $e, description: "" }
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$nix_output | each { |e| { value: $e, description: "" } }
|
||||
}
|
||||
$entries
|
||||
}
|
||||
"systemctl" => {
|
||||
if ($spans | length) < 3 { null } else {
|
||||
let kw = $spans | last
|
||||
^systemctl list-units --all --no-pager --plain --full $"($kw)*"
|
||||
| detect columns
|
||||
| drop 7
|
||||
| headers
|
||||
| each { |r| {value: $r.UNIT, description: ($r.DESCRIPTION | default "")} }
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$in | each { |e| { value: $e, description: "" } }
|
||||
}
|
||||
$entries
|
||||
} else {
|
||||
null
|
||||
}
|
||||
$completions | append $additional
|
||||
}
|
||||
$env.config.completions.external = {
|
||||
enable: true
|
||||
max_results: 200
|
||||
completer: $inshellah_complete
|
||||
_ => { null }
|
||||
}
|
||||
} else { null }
|
||||
$completions | append $additional
|
||||
}
|
||||
$env.config.completions.external = {enable: true, max_results: 200, completer: $inshellah_complete}
|
||||
'';
|
||||
};
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue