Giter VIP home page Giter VIP logo

nu_scripts's Introduction

Nushell Scripts

This is a place to share Nushell scripts with each other. If you'd like to share your scripts, fork this repository, and create a PR that adds it to the repo.

Sections

Running Scripts

You can run nushell scripts in a few different ways.

  1. You can type nu <script name>.
  2. From with nushell, you can type source <script name> and if the script is just a bunch of commands it will run the script. If the script is a custom command it will load those custom commands into your current scope so you can run them like any other command.

nu_scripts's People

Contributors

39555 avatar amtoine avatar aucacoyan avatar bobhy avatar e2dk4r avatar efx avatar ehdevries avatar fdncred avatar fj0r avatar fnuttens avatar hofer-julian avatar hyiltiz avatar ianmanske avatar kjelly avatar kubouch avatar maxim-uvarov avatar neur1n avatar ojarrisonn avatar rickcogley avatar schrieveslaach avatar sholderbach avatar skelly37 avatar sophiajt avatar stormasm avatar texastoland avatar tiggax avatar windsoilder avatar wingertge avatar yethal avatar zkat avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

nu_scripts's Issues

cd-path completion

The idea is to display all possible destinations for the c command, i.e. display all folders located in the $env.CDPATH variable's elements on TAB.

Like it works with cd but instead of just ls --all $env.PWD | where $it.type == dir, do it in each CDPATH-ed location.

I'll be playing with it in my spare time, just posting it here to discuss the concept, implementation and maybe to inspire someone :)

Job.nu script no longer works

See this line, where the command spawn takes command: block as an argument, but according to the error, "blocks are not supported as values," and rather one should "use 'closure' instead of 'block.'" But changing that line to command: closure also fails, with "cannot convert closure to a string."

I'm on nu 0.84.0.

Admin commands Question

I often use cmd to issue remote reboots of machines, ping, run traceroute and to force gpo updates. I use powershell to create scripts for the machines I manage. FYI- it's a windows environment. Does nu shell support those type of commands?

tokyo-night theme uses tokyo-storm palette

With the exception of the background, the colors of tokyo-night are a copy of tokyo-storm.

It would be nice to have the higher-contrast moon and night variants. You can see the original Tokyo Night theme variants here. I've looked around in this repository, but it's not apparent to me how to contribute themes (I assume there's some build step), so here a request instead.

Thanks!

winget-completions.nu with problems?

I've tried to use the winget-completions.nu completions in my config

use C:\Users\username\git-completions.nu *

but when I now start nushell I'm getting the following error:

Error: nu::parser::unknown_command

  × Unknown command.
    ╭─[C:\Users\username\winget-completions.nu:11:1]
 11 │ export extern "winget install" [
 12 │     query?: string@"nu-complete winget install name",
    ·                    ────────────────┬────────────────
    ·                                    ╰── unknown command
 13 │     --query(-q): string@"nu-complete winget install name", # The query used to search for a package
    ╰────

export extern "winget install" [

conda.nu: Support for --prefix flags

Currently, the conda.nu script supports named conda envs. But it would be great if we could get support for local conda environments (aka created with --prefix flag, like conda env create -p .venv/)

Categories

I was thinking, it would be a good idea to split the scripts into directories / categories / topics.

Module `rbenv` can't export command named same as module.

When I try to use the rbenv.nu, using the use path/to/rbenv.nu * as it says on the README, I get the following error:

Error: nu::parser::named_as_module

  × Can't export command named same as the module.
    ╭─[/Users/m.manzanares/clones/fork/nu_scripts/modules/rbenv/rbenv.nu:10:1]
 10 │
 11 │ export def-env rbenv [
    ·                ──┬──
    ·                  ╰── can't export from module rbenv
 12 │     command?: string@'nu-complete rbenv',
    ╰────
  help: Module rbenv can't export command named the same as the module. Either change the module name, or export `main` command.```

Add a basic level of CI for this repo

As Nushell is still making regular breaking changes the scripts in this repository have a tendency to go out of date in a subtle way that needs updating as soon as you try to use them. In some cases we manage to update the scripts when performing the breaking changes but sometimes this is forgot.

As this repo should be informative about the state of the art of Nushell and help form what idiomatic Nushell looks in the wild, we should try to verify as best as possible that the scripts here can be used with the current release of Nushell. (Conversely for nushell development this could serve as a canary-in-the-breaking-changes-mine)

We have the nu-check command to try to parse a piece of code. This could serve as a basic means to verify things still at least parse correctly.

As a ton of scripts depend on externals we don't necessarily have installed in the CI environment there may be a limit to what we can verify.

Duplicated git aliases

Currently, there are git aliases defined both in aliases/git/ and git/. Maybe those should be unified?

Performance issues on man completions

Basically the title. Completions can take up to a second or more, a quick count reveals I have 57124 manpage entries on my system. The initial completion taking a while may be reasonable, however, I believe what makes it not reasonable is attempting to do something along the lines of

  • man git-<tab> (examine results)
  • c takes a few seconds to appear again, then any subsequent additional characters triggers a complete regeneration of search list. This makes typing the rest of the manpage name unreasonably slow.

I have a handful of suggestions to make this better, namely caching at minimum entries in man -w so there is not nearly as much filesystem traversal, but I wanted to get opinions.

Include fetched remote branches in git custom-completions

Often enough, I run something like git rebase --onto origin/main 7fla28h or git switch origin/my_colleagues_feature. For this, it would be helpful that the custom-completions for git included not only local branches but also the fetched branches from remotes.

I tested it out and the PR would be a small change. Do you agree or is there another reason why remote branches are excluded? If they are always shown after the local branches, it should also not distract too much.

nu_conda list should show which environments are activated

It would be nice if the nu_conda list command in the nu_conda module would show which environment is activated.

I modified and will submit a PR to change the behavior from outputting (example on my system):

➜ nu_conda list
╭──────┬─────────────────────────────────────╮
│ base │ /home/marchall/.anaconda3           │
│ data │ /home/marchall/.anaconda3/envs/data │
╰──────┴─────────────────────────────────────╯

to:

➜ nu_conda list
╭───┬──────┬────────┬─────────────────────────────────────╮
│ # │ name │ active │                path                 │
├───┼──────┼────────┼─────────────────────────────────────┤
│ 0 │ base │ false  │ /home/marchall/.anaconda3           │
│ 1 │ data │ true   │ /home/marchall/.anaconda3/envs/data │
╰───┴──────┴────────┴─────────────────────────────────────╯

Also, this way you get a pipeable output instead of just printing $env.CONDA_ENVS.

Add missing scoop completions

Command Status

  • x means completed
  • - means not completed
? Command Summary
- alias Manage scoop aliases
x bucket Manage Scoop buckets
x cache Show or clear the download cache
x cat Show content of specified manifest. If available, bat will be used to pretty-print the JSON.
x checkup Check for potential problems
x cleanup Cleanup apps by removing old versions
x config Get or set configuration values
x create Create a custom app manifest
x depends List dependencies for an app, in the order they'll be installed
x download Download apps in the cache folder and verify hashes
x export Exports installed apps, buckets (and optionally configs) in JSON format
- help Show help for a command
x hold Hold an app to disable updates
x home Opens the app homepage
x import Imports apps, buckets and configs from a Scoopfile in JSON format
x info Display information about an app
x install Install apps
x list List installed apps
x prefix Returns the path to the specified app
x reset Reset an app to resolve conflicts
x search Search available apps
- shim Manipulate Scoop shims
x status Show status and check for new app versions
x unhold Unhold an app to enable updates
x uninstall Uninstall an app
x update Update apps, or Scoop itself
x virustotal Look for app's hash or url on virustotal.com
x which Locate a shim/executable (similar to 'which' on Linux)

I will do it.

Auto_venv breaks due to recent nushell breaking changes

The auto_venv script would look at the current folder and all its parent folders .. one by one to find the hook file and set up the virtual environment.

Something about building the command as a string then evaluating it later is not working since the latest 0.82.1 change.

image

I dug around but could not find the root cause, and this impacts my daily drive. Any idea what is happening here?

Nuscript's for Pacman

Related problem

Hi lovely folks 🌞

So I had the joy to see Nushell in action for the first time recently, and I have to say, I am quite impressed with the neat output.

What I am also impressed by, is the immense complication, it can bring, when I want to launch a command that shows nicely. 😄

As you can see, is it suggested, that we could have a script, that helps with common pacman queries.

Next to the shown ones, I also like to introduce you to the pkgfile command, that helps with packaging.

Screenshot_20230915_223925

This could clearly take some order 😃

Describe the solution you'd like

Clear output for pacman out of the box

See the solution in the linked example 👍🏻

Describe alternatives you've considered

Doing it by hand 😉

[proposal] basic ci

A folder that expects structure (see #40) would benefit from basic CI.

Before embarking, should we add CI? If so, what should CI check?

ideas

  • lint trailing whitespace from .nu files
  • reasonability tests? Many one liners expect context, but can nu do static analysis?

[new script] is dark_mode mac

Looking for feedback before PR.

Proposal

export def 'is dark_mode mac' []: nothing -> bool {
  do { ^defaults read -g AppleInterfaceStyle } | complete | $in.exit_code == 0
}

# in my config.nu
if not (mac is_dark_mode) {
  print 'Light theme enabled 🔆'
  $env.config.color_config = $light_theme
}

How it works in Bash

> # light mode: errors and stderr
> defaults read -g AppleInterfaceStyle
defaults[49472:1750663] 
The domain/default pair of (kCFPreferencesAnyApplication, AppleInterfaceStyle) does not exist

> # dark mode: stdout
> defaults read -g AppleInterfaceStyle
Dark

Example alias from my global Git config:

[alias]
delta = !delta $(defaults read -g AppleInterfaceStyle &>/dev/null || echo --light)

git branch cleanup returns errors.

When calling git branch-cleanup, it returns this error:

 × Lists are not automatically spread when calling external commands
    ╭─[C:\Users\Stijn\AppData\Roaming\nushell\scripts\git_branch_cleanup.nu:88:55]
 87 │
 88 │   run-external --redirect-stdout "git" "symbolic-ref" $args
    ·                                                       ──┬──
    ·                                                         ╰── Spread operator (...) is necessary to spread lists
 89 │   | str trim
    ╰────
  help: Either convert the list to a string or use the spread operator, like so: ...$args

I tried adding a spread operator, but that broke the script. Any ideas on how to fix it?

micromamba support

I adapted the conda script to also support micromamba. i am not a nushell expert, so i am hesitant to make a PR out of it, but wanted to first post it here for other people to find.

BTW i first needed to create a scripts folder and uncomment the command in the env.nu file to actually make it load the module

export-env {
  $env.CONDA_BASE_PATH = (if ((sys).host.name == "Windows") {$env.Path} else {$env.PATH})

  mut info = (
      if not (which micromamba | is-empty) {
        (micromamba env list --json | from json)
      } else if not (which conda | is-empty) {
        (conda info --envs --json | from json)
      } else {
        ('{"root_prefix": "", "envs": ""}' | from json)
      })
  $info.root_prefix = (micromamba info --json | from json)."base environment"

  $env.CONDA_ROOT = $info.root_prefix

  $env.CONDA_ENVS = ($info.envs | reduce -f {} {|it, acc|
      if $it == $env.CONDA_ROOT {
        $acc | upsert "base" $it
      } else {
        $acc | upsert ($it | path basename) $it
      }})

  $env.CONDA_CURR = null
}

export def-env activate [name: string] {
  if ($env.CONDA_ROOT | is-empty) {
    print "Neither Conda nor Mamba is valid."
    return
  }

  if not ($name in $env.CONDA_ENVS) {
    print $"Environment ($name) is invalid. Available:"
    print $env.CONDA_ENVS
    return
  }

  let new_path = (
    if ((sys).host.name == "Windows") {
      update-path-windows ($env.CONDA_ENVS | get $name)
    } else {
      update-path-linux ($env.CONDA_ENVS | get $name)
    })

  load-env ({CONDA_CURR: $name} | merge $new_path)
}

export def-env deactivate [] {
  if ($env.CONDA_ROOT | is-empty) {
    print "Neither Conda nor Mamba is valid."
    return
  }

  $env.CONDA_CURR = null

  load-env {Path: $env.CONDA_BASE_PATH, PATH: $env.CONDA_BASE_PATH}
}

export def-env list [] {
  print $env.CONDA_ENVS
}

def update-path-linux [env_path: path] {
  let env_path = [
    $env_path,
    ([$env_path, "bin"] | path join)
  ]

  return {
    Path: ($env.PATH | prepend $env_path),
    PATH: ($env.PATH | prepend $env_path)
  }
}

def update-path-windows [env_path: path] {
  let env_path = [
    $env_path,
    ([$env_path, "Scripts"] | path join),
  ]

  return {
    Path: ($env.Path | prepend $env_path),
    PATH: ($env.Path | prepend $env_path)
  }
}

i just changed the mamba executable, adapted the command and quickfixed the mutable variable.

Help Wanted: Port the `before_v.060` scripts

It would be great to get all the "old" scripts ported to the latest version of nushell. Anyone want to help with it?

The steps would be something like this:

  1. Take a script or folder from the nu_scripts/before_v0.60 path
  2. Copy it and/or create the folder and copy it to the root of the repo
  3. In the newly created copied script/folder, update the nushell syntax to support the latest nushell
  4. Submit a PR. One at a time or a bunch at a time.

Any takers?

A `nushell` wrapper for `virtualenv`

Hi everyone 👋 😋

i've been using virtualenv to manage python virtual environments for a long time, with projects such as virtualenvwrapper on bash or virtualfish on fish 😋

i could not find anything on this repo, nor on the discord 🤔
and i miss a nice wrapper for virtualenv in nushell 😕

i've recently created a new project which is called amtoine/virtnualenv for now and i'll work on that as soon as i have some time 😌

no idea if that could be merged into nu_scripts, please let me know your thoughts on that project 😉

cheers 🎉 👋

`use` of `parse-help` throws `nu::parser::expected_keyword`

this:

use ~/Developer/nu_scripts/custom-completions/auto-generate/parse-fish.nu

throws this:

Error: nu::parser::expected_keyword

  × Expected keyword.
    ╭─[/Users/daniel/Developer/nu_scripts/custom-completions/auto-generate/parse-fish.nu:86:1]
 86 │ 
 87 │ let quote = '"' # "
    · ─┬─
    ·  ╰── expected def, const, def-env, extern, extern-wrapped, alias, use, module, export or export-env keyword
 88 │ 
    ╰────

conda.nu not working

This PR introduces a breaking change that causes errors on the following nu versions

error:

Error: nu::parser::parse_mismatch

  × Parse mismatch during operation.
    ╭─[C:\Users\Administrator\nu_scripts\modules\virtual_environments\conda.nu:85:1]
 85 │
 86 │     $env.PROMPT_COMMAND = if $env.CONDA_OLD_PROMPT_COMMAND == $nothing {
    ·                              ──────────────┬──────────────
    ·                                            ╰── expected operator
 87 │         $env.PROMPT_COMMAND
    ╰────

nushell env:

key value
version 0.82.0
branch
commit_hash ecdb023e2f6cb17445ae799206e464b2daef3d71
build_os windows-x86_64
build_target x86_64-pc-windows-msvc
rust_version rustc 1.68.2 (9eb3afe9e 2023-03-27)
rust_channel 1.68.2-x86_64-pc-windows-msvc
cargo_version cargo 1.68.2 (6feb7c9cf 2023-03-26)
build_time 2023-06-27 17:33:52 +00:00
build_rust_channel release
allocator standard
features default, sqlite, trash, which, zip
installed_plugins custom-value update, from vcf, gstat, inc, query xml

If change $nu.PROMPT_COMMAND to let-env PROMPT_COMMAND will continue to work

image

PR 816 Broke Anaconda Activation Support on Windows

Today I came across the Anaconda activation scripts and chose to use the nu_conda_2 variant. After following the setup instructions, I could not get the command to work. At best, when I removed conda from my path, I could type conda conda activate X to run the activate function.

Looking into the history of the file, yesterday (what are the odds?) a PR went in which was intended to make the command: conda activate instead of activate. This was #816, by @MilesCranmer.

My initial guess is that Miles uses linux while I am using Windows, which means nushell is behaving differently on the two platforms for this specific case.

This script should be updated to possibly support both variants (before and after #816), because I had to go to a previous version of the file to get it to work on Windows. With the previous version, conda activate works as expected on Windows

image

Problems in auto generated custom-completion files

Some auto generated custom-completion files have syntax errors.
As an example the git.nu has syntax errors in following locations:

[# Display the manual of a git command

# Print out ref names
extern "git short\tHide\ prefixes full\tShow\ full\ ref\ names auto\tHide\ prefixes\ if\ printed\ to\ terminal no\tDon\\t\ display\ ref" [
...args
]

Related: #256 #257

Automatic TOC generation

Just to log the discussion from #1 here.

Would be good to have a) a table of contents listing all scripts, b) some system to generate it automatically so we don't have to update it manually.

[0.83.1] format breaks for (maybe?) constructed records

[WSL: Ubuntu-22.04] ~
nu ➯ ls | get 0 | describe
record<name: string, type: string, size: filesize, modified: date>

[WSL: Ubuntu-22.04] ~
nu ➯ ls | get 0 | format "{name}"
Downloads

[WSL: Ubuntu-22.04] ~
nu ➯ {name: "Downloads"} | describe
record<name: string>

[WSL: Ubuntu-22.04] ~
nu ➯ {name: "Downloads"} | format "{name}"
Error: nu::parser::input_type_mismatch

  × Command does not support record<name: string> input.
   ╭─[entry #12:1:1]
 1 │ {name: "Downloads"} | format "{name}"
   ·                       ───┬──
   ·                          ╰── command doesn't support record<name: string> input
   ╰────

Something's wrong here :)
(Worked fine in 0.82.0)

add the theme collection from `lemnos/themes.sh`

Hello there 👋 😋

this issue is simply a forwarded message from the discord server of nushell

fdncred:
it would be cool is someone wrote a script to parse these files and make nushell themes https://github.com/lemnos/theme.sh/tree/master/themes

The task

the idea would be to parse the files in lemnos/themes.sh into usable nushell themes.

According to the help of the themes.sh script and looking at some of the themes, all the theme files should have the same format, i,e,

color0: #4d4d4d
color1: #4d4d4d
...
color15: #4d4d4d
foreground: #dcdccc
background: #3f3f3f
cursor: #dcdccc

A nice place to put the final nushell theme files could be ./themes/ 👌

Cheers 👋 😋

Showcase: nutils: Utilities for Nu

Hello,

I just wanted to showcase my ongoing project, nutils. It's a collection of utilities and wrappers to replace programs provided by traditional POSIX-compatible utility libraries.

So far I have:

  • df: Basic functionality and --all flag.
Output
╭───┬────────────────┬───────────┬───────────┬───────────┬─────────┬────────────────╮
│ # │   filesystem   │   size    │   used    │   avail   │  used%  │   mountpoint   │
├───┼────────────────┼───────────┼───────────┼───────────┼─────────┼────────────────┤
│ 0 │ devtmpfs       │ 791.7 MiB │       0 B │ 791.7 MiB │       0 │ /dev           │
│ 1 │ tmpfs          │   7.7 GiB │  76.5 MiB │   7.7 GiB │  0.9668 │ /dev/shm       │
│ 2 │ tmpfs          │   3.9 GiB │   7.3 MiB │   3.9 GiB │  0.1839 │ /run           │
│ 3 │ tmpfs          │   7.7 GiB │ 408.0 KiB │   7.7 GiB │  0.0050 │ /run/wrappers  │
│ 4 │ none           │   2.0 GiB │  83.3 MiB │   1.9 GiB │  4.0678 │ /              │
│ 5 │ /dev/nvme0n1p2 │ 476.4 GiB │  25.9 GiB │ 450.5 GiB │  5.4462 │ /nix           │
│ 6 │ /dev/nvme0n1p1 │ 510.7 MiB │  82.7 MiB │ 428.0 MiB │ 16.1978 │ /boot/efi      │
│ 7 │ tmpfs          │   1.5 GiB │  96.0 KiB │   1.5 GiB │  0.0059 │ /run/user/1000 │
╰───┴────────────────┴───────────┴───────────┴───────────┴─────────┴────────────────╯
  • lsr: A replacement to tree and ls -r which displays in recursive tables.
Output
╭───┬────────────────┬────────────────────────────────────╮
│ # │      name      │              contents              │
├───┼────────────────┼────────────────────────────────────┤
│ 0 │ nixos-inserter │ ╭───┬────────────────┬──────────╮  │
│   │                │ │ # │      name      │ contents │  │
│   │                │ ├───┼────────────────┼──────────┤  │
│   │                │ │ 0 │ LICENSE        │    ❎    │  │
│   │                │ │ 1 │ README.md      │    ❎    │  │
│   │                │ │ 2 │ nixos-inserter │    ❎    │  │
│   │                │ ╰───┴────────────────┴──────────╯  │
│ 1 │ nutils         │ ╭───┬─────────────────┬──────────╮ │
│   │                │ │ # │      name       │ contents │ │
│   │                │ ├───┼─────────────────┼──────────┤ │
│   │                │ │ 0 │ CONTRIBUTING.md │    ❎    │ │
│   │                │ │ 1 │ LICENSE         │    ❎    │ │
│   │                │ │ 2 │ README.md       │    ❎    │ │
│   │                │ │ 3 │ nutils.nu       │    ❎    │ │
│   │                │ ╰───┴─────────────────┴──────────╯ │
╰───┴────────────────┴────────────────────────────────────╯
  • who
Output
╭───┬───────┬───────┬───────────┬───────┬──────┬────────────────╮
│ # │ name  │  tty  │   date    │ idle  │ pid  │    comment     │
├───┼───────┼───────┼───────────┼───────┼──────┼────────────────┤
│ 0 │ dch82 │ seat0 │ a day ago │ ?     │ 2588 │ (login screen) │
│ 1 │ dch82 │ tty2  │ a day ago │ 18:47 │ 2588 │ (tty2)         │
╰───┴───────┴───────┴───────────┴───────┴──────┴────────────────╯

Conda documentation

I am just starting out with Nushell and I love the speed of it and its functional approach to doing things. I am setting up the conda plugin and I have two (newby) questions:

  1. Why are there two Conda scripts? On the surface they are very similar.
  2. It is not immediately clear to me how to enable these scripts by default. The nu_conda script says to "put it in the modules folder in the config folder" but if I put the file in ~/.config/nushell/modules, nothing happens. I looked in the env.nu file and found that putting it in the scripts folder enables me to enable it using use nu_conda.nu, but I would like it to always be on.

Update: I got it working by putting the following in the config, put it is a hardcoded path and feels like a hack

use ~/.config/nushell/scripts/nu_conda.nu

Auto-generated tar.nu has a syntax error

Error: nu::parser::parse_mismatch (link)

  × Parse mismatch during operation.
    ╭─[C:\Users\me\Documents\nu_scripts\custom-completions\auto-generate\completions\tar.nu:10:1]
 10 │   --get(-x)                                       # Extract from archive
 11 │   --help(-\?)                                     # Display short option summary
    ·  ─────┬─────
    ·       ╰── expected short flag
 12 │   --usage                                 # List available options
    ╰────

How to get args passed after the script?

If I ran try.sh foo in the console, I can get the foo input by $1.
And How to get args passed after the nu script?

nu try.nu foo bar

How can I get the param foo and bar ? Thanks.

Missing flag argument in git aliases

Trying to load nu­­­­­_alias_git.nu fails at

export alias gcam = git commit --all --message

with

Error: nu::parser::missing_flag_param

  × Missing flag argument.
    ╭─[C:\…\nu_scripts\aliases\git\nu_alias_git.nu:47:1]
 47 │ export alias gcans! = git commit --verbose --all --signoff --no-edit --amend
 48 │ export alias gcam = git commit --all --message
    ·                                      ────┬────
    ·                                          ╰── flag missing string argument
 49 │ export alias gcsm = git commit --signoff --message
    ╰────

Micromamba support

In order to support micromamba, I changed the completion in the conda.nu module to:

def get-envs [] {
    micromamba env list --json | from json | get envs | each { |p| { path: $p, name: ($p | path basename) } }
}

def 'nu-complete conda envs' [] {
    get-envs | get name
}

and the first lines of export def-env activate to:

let envs = (get-envs)
let env_dir = ($envs | where name == $env_name | get path | first)

zoxide: Error: nu::shell::access_beyond_end (link)

❯ z
Error: nu::shell::access_beyond_end (link)

  × Row number too large (max: 0).
    ╭─[~/code/forks/nu_scripts/prompt/zoxide-eq.nu:86:1]
 86 │         # } else {
 87 │             cd (zoxide query --exclude ($env.PWD) -- $rest.0 | str collect | str trim)
    ·                                                            ┬
    ·                                                            ╰── index too large (max: 0)
 88 │         # }
    ╰────

`main` branch CI is not working as expected

Since #771 , PR CI is working properly, but main branch CI is passing... weird, I expected it to fail because there are a bunch of files that don't pass the parser check.
When I read the CI log, I found that no file was checked:

Run nu ./check-files.nu
💚 All files checked!

And after I replicate the case in my local,

use toolkit.nu *; generate-file-list --full"
checking all files...

This generate a empty list of files.

This is probably the cause:

mut $files = glob **/*.nu --exclude [before_v0.60/**]

If you remove the mut, glob fails the parser. I need to investigate how glob works

The direnv hooks are very confusing

The direnv instructions contradict upstream direnv docs which recommend:

{ ||
    if (which direnv | is-empty) {
        return
    }

    direnv export json | from json | default {} | load-env
}

Which generate env variables and adds them to current env.
However, in hooks here the environment is being read from .env or .env.yaml:

def direnv [] {
    [
        {
            condition: {|before, after| ($before != $after) and ($after | path join .env.yaml | path exists) }
            code: "
                open .env.yaml | load-env
            "
        }
        {
            condition: {|before, after| ($before != $after) and ($after | path join '.env' | path exists) }
            code: "
                open .env
                | lines
                | parse -r '(?P<k>.+?)=(?P<v>.+)'
                | reduce -f {} {|x, acc| $acc | upsert $x.k $x.v}
                | load-env
            "
        }
    ]
}

And it doesn't explain what .env or .env.yaml are expected to contain for this to work?

Conda Module with Better Performance

I implemented a conda.nu module for activating and deactivating conda envs but I'm not sure if this is suitable for a PR since it is quite different from the existing one:

  1. The original Path/PATH environment variable, root directory of Conda and available envs are cached once calling use conda.nu.
  2. Mamba is supported and preferred over Conda, but the supporting might be incomplete since I've dive into their differences.
  3. There is not option to change your prompt. One must use $env.CONDA_CURR to customize the prompt.

On my PC, using this new module to activate a Conda env costs ~20ms while the old one costs ~1500ms (by checking $env.CMD_DURATION_MS). The code is listed and attached.

export-env {
  let-env CONDA_BASE_PATH = (if ((sys).host.name == "Windows") {$env.Path} else {$env.PATH})

  let info = (
      if not (which mamba | is-empty) {
        (mamba info --envs --json | from json)
      } else if not (which conda | is-empty) {
        (conda info --envs --json | from json)
      } else {
        ('{"root_prefix": "", "envs": ""}' | from json)
      })

  let-env CONDA_ROOT = $info.root_prefix

  let-env CONDA_ENVS = ($info.envs | reduce -f {} {|it, acc|
      if $it == $info.root_prefix {
        $acc | upsert "base" $it
      } else {
        $acc | upsert ($it | path basename) $it
      }})

  let-env CONDA_CURR = null
}

export def-env activate [name: string] {
  if ($env.CONDA_ROOT | is-empty) {
    echo "Neither Conda nor Mamba is valid."
    return
  }

  if not $name in $env.CONDA_ENVS {
    echo $"Environment ($name) is invalid. Available:"
    echo $env.CONDA_ENVS
    return
  }

  let new_path = (
    if ((sys).host.name == "Windows") {
      update-path-windows ($env.CONDA_ENVS | get $name)
    } else {
      update-path-linux ($env.CONDA_ENVS | get $name)
    })

  load-env ({CONDA_CURR: $name} | merge $new_path)
}

export def-env deactivate [] {
  if ($env.CONDA_ROOT | is-empty) {
    echo "Neither Conda nor Mamba is valid."
    return
  }

  let-env CONDA_CURR = null

  load-env {Path: $env.CONDA_BASE_PATH, PATH: $env.CONDA_BASE_PATH}
}

def update-path-linux [env_path: path] {
  let env_path = [
    $env_path,
    ([$env_path, "bin"] | path join)
  ]

  return {
    Path: ($env.PATH | prepend $env_path),
    PATH: ($env.PATH | prepend $env_path)
  }
}

def update-path-windows [env_path: path] {
  let env_path = [
    $env_path,
    ([$env_path, "Scripts"] | path join),
  ]

  return {
    Path: ($env.Path | prepend $env_path),
    PATH: ($env.Path | prepend $env_path),
  }
}

conda.txt

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.