Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
NixOS
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Nicolas Lenz
NixOS
Commits
09cf3625
Verified
Commit
09cf3625
authored
4 months ago
by
Nicolas Lenz
Browse files
Options
Downloads
Patches
Plain Diff
feat: add nushell utils with vipe
parent
58081844
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
home/shell.nix
+2
-1
2 additions, 1 deletion
home/shell.nix
res/nushell/utils.nu
+35
-0
35 additions, 0 deletions
res/nushell/utils.nu
with
37 additions
and
1 deletion
home/shell.nix
+
2
−
1
View file @
09cf3625
...
...
@@ -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"
...
...
This diff is collapsed.
Click to expand it.
res/nushell/utils.nu
0 → 100644
+
35
−
0
View file @
09cf3625
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
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment