Skip to content
Snippets Groups Projects
Verified Commit 09cf3625 authored by Nicolas Lenz's avatar Nicolas Lenz :snowflake:
Browse files

feat: add nushell utils with vipe

parent 58081844
No related branches found
No related tags found
No related merge requests found
......@@ -4,7 +4,7 @@ Config for shell and prompt.
- nushell default config with documentation comments: see `config nu --default`
*/
{ inputs, lib, config, ... }:
{ inputs, lib, config, res, ... }:
{
# nushell is a typed shell
......@@ -27,6 +27,7 @@ Config for shell and prompt.
then "use ${completionsDir}/${command.dir}/${command.file}-completions.nu *"
else "use ${completionsDir}/${command}/${command}-completions.nu *";
in ''
use ${res + /nushell/utils.nu} *
${lib.strings.concatMapStringsSep "\n" useCompletion [
"bat" "btm" "just" "make" "man" "nano" "nix" "npm" "poetry" "rg" "typst" "vscode"
{ dir = "yarn"; file = "yarn-v4"; } "zellij"
......
use std/assert
export def "assert not null" [value: any, message = "Value may not be null.": string] {
assert ($value != null) $message --error-label {
text: $"($value) is null, but shouldn't be",
span: (metadata $value).span,
}
}
# Pipes through a string, allowing to edit it on the way using your editor.
# Based on vipe from moreutils, see: https://man.archlinux.org/man/vipe.1
export def vipe [
--suffix: string # Specifies a file extension to be used for the temporary file. Useful to get your editor to recognize the file type correctly.
]: string -> string {
let tempFile: string = if $suffix == null {
mktemp --tmpdir vipe.XXXXXXXX
} else {
mktemp --tmpdir --suffix $suffix vipe.XXXXXXXX
}
$in | default "" | save --force $tempFile
let editor: string = $env.EDITOR? | default ($env.VISUAL?)
assert not null $editor "No editor defined in environment."
^$editor $tempFile
let result: string = if ($tempFile | path exists) {
open $tempFile
} else {
null
}
rm -f $tempFile
return $result
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment