Skip to content

Commit

Permalink
Merge pull request #2 from LukeChannings/nushell-upgrade
Browse files Browse the repository at this point in the history
Upgrade Nushell to 0.99.0
  • Loading branch information
LukeChannings authored Oct 18, 2024
2 parents e50653f + e588aba commit b81dbd5
Show file tree
Hide file tree
Showing 9 changed files with 210 additions and 201 deletions.
3 changes: 2 additions & 1 deletion .devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
"github.codespaces",
"1password.op-vscode",
"ibecker.treefmt-vscode",
"jnoortheen.nix-ide"
"jnoortheen.nix-ide",
"thenuprojectcontributors.vscode-nushell-lang"
]
}
},
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/binary-cache.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ name: "Binary Cache"
on:
push:
paths:
- config/*
- *.nix
- "config/*"
- "*.nix"

jobs:
binary-cache:
Expand Down
2 changes: 1 addition & 1 deletion config/eza/home.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
programs.eza = {
enable = true;
icons = true;
icons = "auto";
};
}
53 changes: 29 additions & 24 deletions config/nushell/config.nu
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Nushell Config File
#
# version = "0.92.1"
# version = "0.99.0"

# For more information on defining custom themes, see
# https://www.nushell.sh/book/coloring_and_theming.html
Expand Down Expand Up @@ -47,7 +47,8 @@ let dark_theme = {
shape_flag: blue_bold
shape_float: purple_bold
# shapes are used to change the cli syntax highlighting
shape_garbage: { fg: white bg: red attr: b}
shape_garbage: { fg: white bg: red attr: b }
shape_glob_interpolation: cyan_bold
shape_globpattern: cyan_bold
shape_int: purple_bold
shape_internalcall: cyan_bold
Expand All @@ -69,6 +70,7 @@ let dark_theme = {
shape_table: blue_bold
shape_variable: purple
shape_vardecl: purple
shape_raw_string: light_purple
}

let light_theme = {
Expand Down Expand Up @@ -112,7 +114,8 @@ let light_theme = {
shape_flag: blue_bold
shape_float: purple_bold
# shapes are used to change the cli syntax highlighting
shape_garbage: { fg: white bg: red attr: b}
shape_garbage: { fg: white bg: red attr: b }
shape_glob_interpolation: cyan_bold
shape_globpattern: cyan_bold
shape_int: purple_bold
shape_internalcall: cyan_bold
Expand All @@ -134,6 +137,7 @@ let light_theme = {
shape_table: blue_bold
shape_variable: purple
shape_vardecl: purple
shape_raw_string: light_purple
}

# External completer example
Expand Down Expand Up @@ -170,6 +174,14 @@ $env.config = {

error_style: "fancy" # "fancy" or "plain" for screen reader-friendly error messages

# Whether an error message should be printed if an error of a certain kind is triggered.
display_errors: {
exit_code: false # assume the external command prints an error message
# Core dump errors are always printed, and SIGPIPE never triggers an error.
# The setting below controls message printing for termination by all other signals.
termination_signal: true
}

# datetime_format determines what a datetime rendered in the shell would look like.
# Behavior without this configuration point will be to "humanize" the datetime display,
# showing something like "a day ago."
Expand All @@ -187,12 +199,7 @@ $env.config = {
warn: {}
info: {}
},
table: {
split_line: { fg: "#404040" },
selected_cell: { bg: light_blue },
selected_row: {},
selected_column: {},
},
selected_cell: { bg: light_blue },
}

history: {
Expand All @@ -207,6 +214,7 @@ $env.config = {
quick: true # set this to false to prevent auto-selecting completions when only one remains
partial: true # set this to false to prevent partial filling of the prompt
algorithm: "prefix" # prefix or fuzzy
sort: "smart" # "smart" (alphabetical for prefix matching, fuzzy score for fuzzy matching) or "alphabetical"
external: {
enable: true # set to false to prevent nushell looking into $env.PATH to find more suggestions, `false` recommended for WSL users as this look up may be very slow
max_results: 100 # setting it lower can improve completion performance at the cost of omitting some options
Expand All @@ -227,10 +235,9 @@ $env.config = {
}

color_config: $dark_theme # if you want a more interesting theme, you can replace the empty record with `$dark_theme`, `$light_theme` or another custom record
use_grid_icons: true
footer_mode: "25" # always, never, number_of_rows, auto
footer_mode: 25 # always, never, number_of_rows, auto
float_precision: 2 # the precision for displaying floats in tables
buffer_editor: "" # command that will be used to edit the current line buffer with ctrl+o, if unset fallback to $env.EDITOR and $env.VISUAL
buffer_editor: null # command that will be used to edit the current line buffer with ctrl+o, if unset fallback to $env.EDITOR and $env.VISUAL
use_ansi_coloring: true
bracketed_paste: true # enable bracketed paste, currently useless on windows
edit_mode: emacs # emacs, vi
Expand All @@ -255,7 +262,7 @@ $env.config = {
# 633;B - Mark prompt end
# 633;C - Mark pre-execution
# 633;D;exit - Mark execution finished with exit code
# 633;E - NOT IMPLEMENTED - Explicitly set the command line with an optional nonce
# 633;E - Explicitly set the command line with an optional nonce
# 633;P;Cwd=<path> - Mark the current working directory and communicate it to the terminal
# and also helps with the run recent menu in vscode
osc633: true
Expand Down Expand Up @@ -396,6 +403,13 @@ $env.config = {
]
}
}
{
name: completion_previous_menu
modifier: shift
keycode: backtab
mode: [emacs, vi_normal, vi_insert]
event: { send: menuprevious }
}
{
name: ide_completion_menu
modifier: control
Expand Down Expand Up @@ -423,13 +437,6 @@ $env.config = {
mode: [emacs, vi_insert, vi_normal]
event: { send: menu name: help_menu }
}
{
name: completion_previous_menu
modifier: shift
keycode: backtab
mode: [emacs, vi_normal, vi_insert]
event: { send: menuprevious }
}
{
name: next_page_menu
modifier: control
Expand Down Expand Up @@ -749,7 +756,7 @@ $env.config = {
modifier: control
keycode: char_k
mode: emacs
event: { edit: cuttoend }
event: { edit: cuttolineend }
}
{
name: cut_line_from_start
Expand Down Expand Up @@ -854,8 +861,6 @@ $env.config = {
}
# The following bindings with `*system` events require that Nushell has
# been compiled with the `system-clipboard` feature.
# This should be the case for Windows, macOS, and most Linux distributions
# Not available for example on Android (termux)
# If you want to use the system clipboard for visual selection or to
# paste directly, uncomment the respective lines and replace the version
# using the internal clipboard.
Expand Down Expand Up @@ -890,4 +895,4 @@ $env.config = {
event: { edit: selectall }
}
]
}
}
44 changes: 9 additions & 35 deletions config/nushell/env.nu
Original file line number Diff line number Diff line change
Expand Up @@ -3,48 +3,21 @@
# version = "0.92.1"

def create_left_prompt [] {
let dir = match (do --ignore-shell-errors { $env.PWD | path relative-to $nu.home-path }) {
null => $env.PWD
'' => '~'
$relative_pwd => ([~ $relative_pwd] | path join)
}

let path_color = (if (is-admin) { ansi red_bold } else { ansi green_bold })
let separator_color = (if (is-admin) { ansi light_red_bold } else { ansi light_green_bold })
let path_segment = $"($path_color)($dir)"

$path_segment | str replace --all (char path_sep) $"($separator_color)(char path_sep)($path_color)"
starship prompt --cmd-duration $env.CMD_DURATION_MS $'--status=($env.LAST_EXIT_CODE)'
}

def create_right_prompt [] {
# create a right prompt in magenta with green separators and am/pm underlined
let time_segment = ([
(ansi reset)
(ansi magenta)
(date now | format date '%x %X') # try to respect user's locale
] | str join | str replace --regex --all "([/:])" $"(ansi green)${1}(ansi magenta)" |
str replace --regex --all "([AP]M)" $"(ansi magenta_underline)${1}")

let last_exit_code = if ($env.LAST_EXIT_CODE != 0) {([
(ansi rb)
($env.LAST_EXIT_CODE)
] | str join)
} else { "" }

([$last_exit_code, (char space), $time_segment] | str join)
}
$env.STARSHIP_SHELL = "nu"

# Use nushell functions to define your right and left prompt
$env.PROMPT_COMMAND = {|| create_left_prompt }
# FIXME: This default is not implemented in rust code as of 2023-09-08.
$env.PROMPT_COMMAND_RIGHT = {|| create_right_prompt }
$env.PROMPT_COMMAND = { || create_left_prompt }
$env.PROMPT_COMMAND_RIGHT = ""

# The prompt indicators are environmental variables that represent
# the state of the prompt
$env.PROMPT_INDICATOR = {|| "> " }
$env.PROMPT_INDICATOR_VI_INSERT = {|| ": " }
$env.PROMPT_INDICATOR_VI_NORMAL = {|| "> " }
$env.PROMPT_MULTILINE_INDICATOR = {|| "::: " }
$env.PROMPT_INDICATOR = ""
$env.PROMPT_INDICATOR_VI_INSERT = ": "
$env.PROMPT_INDICATOR_VI_NORMAL = ""
$env.PROMPT_MULTILINE_INDICATOR = "::: "

# If you want previously entered commands to have a different prompt from the usual one,
# you can uncomment one or more of the following lines.
Expand Down Expand Up @@ -77,6 +50,7 @@ $env.ENV_CONVERSIONS = {
# The default for this is $nu.default-config-dir/scripts
$env.NU_LIB_DIRS = [
($nu.default-config-dir | path join 'scripts') # add <nushell-config-dir>/scripts
($nu.data-dir | path join 'completions') # default home for nushell completions
]

# Directories to search for plugin binaries when calling register
Expand Down
30 changes: 29 additions & 1 deletion config/nushell/home.nix
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
{
pkgs,
lib,
...
}:
let
inherit (pkgs) stdenv darwin;
in
{
config = {
programs.nushell = {
Expand All @@ -12,6 +16,30 @@
loginFile.text = (builtins.readFile ./login.nu);
};

home.packages = [ pkgs.nushellPlugins.formats ];
home.packages =
let
fixupForDarwin =
drv:
drv.overrideAttrs (oldAttrs: {
buildInputs =
oldAttrs.buildInputs
++ lib.optionals stdenv.isDarwin [
darwin.apple_sdk.frameworks.IOKit
darwin.apple_sdk.frameworks.Security
darwin.apple_sdk.frameworks.CoreServices
];
});
in
(map fixupForDarwin (
with pkgs.nushellPlugins;
[
formats
polars
query
highlight
# net
# units
]
));
};
}
Loading

0 comments on commit b81dbd5

Please sign in to comment.