Giter Site home page Giter Site logo

nu_scripts's Introduction

Nushell

Crates.io Build Status Nightly Build Discord The Changelog #363 @nu_shell GitHub commit activity GitHub contributors

A new type of shell.

Example of nushell

Table of Contents

Status

This project has reached a minimum-viable-product level of quality. Many people use it as their daily driver, but it may be unstable for some commands. Nu's design is subject to change as it matures.

Learning About Nu

The Nushell book is the primary source of Nushell documentation. You can find a full list of Nu commands in the book, and we have many examples of using Nu in our cookbook.

We're also active on Discord and Twitter; come and chat with us!

Installation

To quickly install Nu:

# Linux and macOS
brew install nushell
# Windows
winget install nushell

To use Nu in GitHub Action, check setup-nu for more detail.

Detailed installation instructions can be found in the installation chapter of the book. Nu is available via many package managers:

Packaging status

For details about which platforms the Nushell team actively supports, see our platform support policy.

Configuration

The default configurations can be found at sample_config which are the configuration files one gets when they startup Nushell for the first time.

It sets all of the default configuration to run Nushell. From here one can then customize this file for their specific needs.

To see where config.nu is located on your system simply type this command.

$nu.config-path

Please see our book for all of the Nushell documentation.

Philosophy

Nu draws inspiration from projects like PowerShell, functional programming languages, and modern CLI tools. Rather than thinking of files and data as raw streams of text, Nu looks at each input as something with structure. For example, when you list the contents of a directory what you get back is a table of rows, where each row represents an item in that directory. These values can be piped through a series of steps, in a series of commands called a 'pipeline'.

Pipelines

In Unix, it's common to pipe between commands to split up a sophisticated command over multiple steps. Nu takes this a step further and builds heavily on the idea of pipelines. As in the Unix philosophy, Nu allows commands to output to stdout and read from stdin. Additionally, commands can output structured data (you can think of this as a third kind of stream). Commands that work in the pipeline fit into one of three categories:

  • Commands that produce a stream (e.g., ls)
  • Commands that filter a stream (e.g., where type == "dir")
  • Commands that consume the output of the pipeline (e.g., table)

Commands are separated by the pipe symbol (|) to denote a pipeline flowing left to right.

> ls | where type == "dir" | table
╭────┬──────────┬──────┬─────────┬───────────────╮
│ #  │   name   │ type │  size   │   modified    │
├────┼──────────┼──────┼─────────┼───────────────┤
│  0 │ .cargo   │ dir  │     0 B │ 9 minutes ago │
│  1 │ assets   │ dir  │     0 B │ 2 weeks ago   │
│  2 │ crates   │ dir  │ 4.0 KiB │ 2 weeks ago   │
│  3 │ docker   │ dir  │     0 B │ 2 weeks ago   │
│  4 │ docs     │ dir  │     0 B │ 2 weeks ago   │
│  5 │ images   │ dir  │     0 B │ 2 weeks ago   │
│  6 │ pkg_mgrs │ dir  │     0 B │ 2 weeks ago   │
│  7 │ samples  │ dir  │     0 B │ 2 weeks ago   │
│  8 │ src      │ dir  │ 4.0 KiB │ 2 weeks ago   │
│  9 │ target   │ dir  │     0 B │ a day ago     │
│ 10 │ tests    │ dir  │ 4.0 KiB │ 2 weeks ago   │
│ 11 │ wix      │ dir  │     0 B │ 2 weeks ago   │
╰────┴──────────┴──────┴─────────┴───────────────╯

Because most of the time you'll want to see the output of a pipeline, table is assumed. We could have also written the above:

> ls | where type == "dir"

Being able to use the same commands and compose them differently is an important philosophy in Nu. For example, we could use the built-in ps command to get a list of the running processes, using the same where as above.

> ps | where cpu > 0
╭───┬───────┬───────────┬───────┬───────────┬───────────╮
│ # │  pid  │   name    │  cpu  │    mem    │  virtual  │
├───┼───────┼───────────┼───────┼───────────┼───────────┤
│ 0 │  2240 │ Slack.exe │ 16.40 │ 178.3 MiB │ 232.6 MiB │
│ 1 │ 16948 │ Slack.exe │ 16.32 │ 205.0 MiB │ 197.9 MiB │
│ 2 │ 17700 │ nu.exe    │  3.77 │  26.1 MiB │   8.8 MiB │
╰───┴───────┴───────────┴───────┴───────────┴───────────╯

Opening files

Nu can load file and URL contents as raw text or structured data (if it recognizes the format). For example, you can load a .toml file as structured data and explore it:

> open Cargo.toml
╭──────────────────┬────────────────────╮
│ bin              │ [table 1 row]      │
│ dependencies     │ {record 25 fields} │
│ dev-dependencies │ {record 8 fields}  │
│ features         │ {record 10 fields} │
│ package          │ {record 13 fields} │
│ patch            │ {record 1 field}   │
│ profile          │ {record 3 fields}  │
│ target           │ {record 3 fields}  │
│ workspace        │ {record 1 field}   │
╰──────────────────┴────────────────────╯

We can pipe this into a command that gets the contents of one of the columns:

> open Cargo.toml | get package
╭───────────────┬────────────────────────────────────╮
│ authors       │ [list 1 item]                      │
│ default-run   │ nu                                 │
│ description   │ A new type of shell                │
│ documentation │ https://www.nushell.sh/book/       │
│ edition       │ 2018                               │
│ exclude       │ [list 1 item]                      │
│ homepage      │ https://www.nushell.sh             │
│ license       │ MIT                                │
│ metadata      │ {record 1 field}                   │
│ name          │ nu                                 │
│ repository    │ https://github.com/nushell/nushell │
│ rust-version  │ 1.60                               │
│ version       │ 0.72.0                             │
╰───────────────┴────────────────────────────────────╯

And if needed we can drill down further:

> open Cargo.toml | get package.version
0.72.0

Plugins

Nu supports plugins that offer additional functionality to the shell and follow the same structured data model that built-in commands use. There are a few examples in the crates/nu_plugins_* directories.

Plugins are binaries that are available in your path and follow a nu_plugin_* naming convention. These binaries interact with nu via a simple JSON-RPC protocol where the command identifies itself and passes along its configuration, making it available for use. If the plugin is a filter, data streams to it one element at a time, and it can stream data back in return via stdin/stdout. If the plugin is a sink, it is given the full vector of final data and is given free reign over stdin/stdout to use as it pleases.

The awesome-nu repo lists a variety of nu-plugins while the showcase repo shows off informative blog posts that have been written about Nushell along with videos that highlight technical topics that have been presented.

Goals

Nu adheres closely to a set of goals that make up its design philosophy. As features are added, they are checked against these goals.

  • First and foremost, Nu is cross-platform. Commands and techniques should work across platforms and Nu has first-class support for Windows, macOS, and Linux.

  • Nu ensures compatibility with existing platform-specific executables.

  • Nu's workflow and tools should have the usability expected of modern software in 2022 (and beyond).

  • Nu views data as either structured or unstructured. It is a structured shell like PowerShell.

  • Finally, Nu views data functionally. Rather than using mutation, pipelines act as a means to load, change, and save data without mutable state.

Officially Supported By

Please submit an issue or PR to be added to this list.

Contributing

See Contributing for details. Thanks to all the people who already contributed!

License

The project is made available under the MIT license. See the LICENSE file for more information.

nu_scripts's People

Contributors

acanalis avatar amtoine avatar aucacoyan avatar bobhy avatar e2dk4r avatar efx avatar ehdevries avatar fdncred avatar fj0r avatar fnuttens avatar hofer-julian avatar hyiltiz avatar jacobious52 avatar kubouch avatar maxim-uvarov avatar naefl avatar neur1n avatar rgbcube avatar rickcogley avatar schrieveslaach avatar sholderbach avatar siph avatar skelly37 avatar sophiajt avatar stormasm 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

nu_scripts's Issues

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

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
    ╰────

Duplicated git aliases

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

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)

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.

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?

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 │         # }
    ╰────

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
    ╰────

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.

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

[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)

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.

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

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.

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 :)

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

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 😉

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)         │
╰───┴───────┴───────┴───────────┴───────┴──────┴────────────────╯

`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 │ 
    ╰────

[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)

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 👋 😋

Categories

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

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!

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?

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.

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" [

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?

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/)

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.

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.

`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

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.

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 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.

[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?

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 🎉 👋

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?

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.