mirror of
https://github.com/nushell/nushell
synced 2024-11-10 15:14:14 +00:00
remove some old documentation, relocate others (#4726)
* remove some old documentation, relocate others * small tweak to default config
This commit is contained in:
parent
e64ca97fe2
commit
b714e034aa
12 changed files with 5 additions and 1315 deletions
|
@ -1,43 +0,0 @@
|
|||
# How to configure 3rd party prompts
|
||||
|
||||
## nerdfonts
|
||||
|
||||
nerdfonts are not required but they make the presentation much better.
|
||||
|
||||
[site](https://www.nerdfonts.com)
|
||||
|
||||
[repo](https://github.com/ryanoasis/nerd-fonts)
|
||||
|
||||
## oh-my-posh
|
||||
|
||||
[site](ttps://ohmyposh.dev/)
|
||||
|
||||
[repo](https://github.com/JanDeDobbeleer/oh-my-posh)
|
||||
|
||||
If you like [oh-my-posh](https://ohmyposh.dev/), you can use oh-my-posh with nushell with few steps. It's works great with nushell. There is how to setup oh-my-posh with nushell:
|
||||
|
||||
1. Install Oh My Posh and download oh-my-posh's themes following [guide](https://ohmyposh.dev/docs/linux#installation).
|
||||
2. Download and Install a [nerd font](https://github.com/ryanoasis/nerd-fonts).
|
||||
3. Set the PROMPT_COMMAND in ~/.config/nushell/config.nu, change `M365Princess.omp.json` to whatever you like [Themes demo](https://ohmyposh.dev/docs/themes).
|
||||
|
||||
```
|
||||
let-env PROMPT_COMMAND = { oh-my-posh --config ~/.poshthemes/M365Princess.omp.json }
|
||||
```
|
||||
|
||||
## Starship
|
||||
|
||||
[site](https://starship.rs/)
|
||||
|
||||
[repo](https://github.com/starship/starship)
|
||||
|
||||
1. Follow the links above and install starship.
|
||||
2. Install nerdfonts depending on your preferences.
|
||||
3. Set the starship shell environment variable to `nu` by running this commend `let-env STARSHIP_SHELL = "nu"`
|
||||
4. If you want the default ticking clock with date & time on the right prompt execut this command `hide PROMPT_COMMAND_RIGHT`
|
||||
5. If you don't want the default indicator, you can run this command `let-env PROMPT_INDICATOR = " "`
|
||||
6. Set starship as your left prompt with this command `let-env PROMPT_COMMAND = { starship prompt --cmd-duration $env.CMD_DURATION_MS --status $env.LAST_EXIT_CODE | str trim }`. Note that you may not have to use `str trim` in the nushell prompt if you disable starship's default newline setting with this entry in the starship.toml file `add_newline = false`. There have been reports that this might not play nice with nushell prompts. We're still testing.
|
||||
7. Since nushell supports a right prompt you can also play around with starship's ability to set a right prompt. Setting the right prompt in nushell is identical to setting the left prompt however you use `PROMPT_COMMAND_RIGHT`.
|
||||
|
||||
## Purs
|
||||
|
||||
[repo](https://github.com/xcambar/purs)
|
|
@ -1,478 +0,0 @@
|
|||
# Coloring and Theming in Nushell
|
||||
|
||||
There are a few main parts that nushell allows you to change the color. All of these can be set in the `config.nu` configuration file. If you see the hash/hashtag/pound mark `#` in the config file it means the text after it is commented out.
|
||||
|
||||
1. table borders
|
||||
2. primitive values
|
||||
3. shapes (this is the command line syntax)
|
||||
4. prompt
|
||||
5. LS_COLORS
|
||||
|
||||
## `Table borders`
|
||||
|
||||
---
|
||||
|
||||
Table borders are controlled by the `table_mode` setting in the `config.nu`. Here is an example:
|
||||
|
||||
```
|
||||
let $config = {
|
||||
table_mode: rounded
|
||||
}
|
||||
```
|
||||
|
||||
Here are the current options for `table_mode`:
|
||||
|
||||
1. `rounded` # of course, this is the best one :)
|
||||
2. `basic`
|
||||
3. `compact`
|
||||
4. `compact_double`
|
||||
5. `light`
|
||||
6. `thin`
|
||||
7. `with_love`
|
||||
8. `rounded`
|
||||
9. `reinforced`
|
||||
10. `heavy`
|
||||
11. `none`
|
||||
12. `other`
|
||||
|
||||
### `Color symbologies`
|
||||
|
||||
---
|
||||
|
||||
- `r` - normal color red's abbreviation
|
||||
- `rb` - normal color red's abbreviation with bold attribute
|
||||
- `red` - normal color red
|
||||
- `red_bold` - normal color red with bold attribute
|
||||
- `"#ff0000"` - "#hex" format foreground color red (quotes are required)
|
||||
- `{ fg: "#ff0000" bg: "#0000ff" attr: b }` - "full #hex" format foreground red in "#hex" format with a background of blue in "#hex" format with an attribute of bold abbreviated.
|
||||
|
||||
### `attributes`
|
||||
|
||||
---
|
||||
|
||||
| code | meaning |
|
||||
| ---- | ------------------- |
|
||||
| l | blink |
|
||||
| b | bold |
|
||||
| d | dimmed |
|
||||
| h | hidden |
|
||||
| i | italic |
|
||||
| r | reverse |
|
||||
| s | strikethrough |
|
||||
| u | underline |
|
||||
| n | nothing |
|
||||
| | defaults to nothing |
|
||||
|
||||
### `normal colors` and `abbreviations`
|
||||
|
||||
| code | name |
|
||||
| ------ | ---------------------- |
|
||||
| g | green |
|
||||
| gb | green_bold |
|
||||
| gu | green_underline |
|
||||
| gi | green_italic |
|
||||
| gd | green_dimmed |
|
||||
| gr | green_reverse |
|
||||
| gbl | green_blink |
|
||||
| gst | green_strike |
|
||||
| lg | light_green |
|
||||
| lgb | light_green_bold |
|
||||
| lgu | light_green_underline |
|
||||
| lgi | light_green_italic |
|
||||
| lgd | light_green_dimmed |
|
||||
| lgr | light_green_reverse |
|
||||
| lgbl | light_green_blink |
|
||||
| lgst | light_green_strike |
|
||||
| r | red |
|
||||
| rb | red_bold |
|
||||
| ru | red_underline |
|
||||
| ri | red_italic |
|
||||
| rd | red_dimmed |
|
||||
| rr | red_reverse |
|
||||
| rbl | red_blink |
|
||||
| rst | red_strike |
|
||||
| lr | light_red |
|
||||
| lrb | light_red_bold |
|
||||
| lru | light_red_underline |
|
||||
| lri | light_red_italic |
|
||||
| lrd | light_red_dimmed |
|
||||
| lrr | light_red_reverse |
|
||||
| lrbl | light_red_blink |
|
||||
| lrst | light_red_strike |
|
||||
| u | blue |
|
||||
| ub | blue_bold |
|
||||
| uu | blue_underline |
|
||||
| ui | blue_italic |
|
||||
| ud | blue_dimmed |
|
||||
| ur | blue_reverse |
|
||||
| ubl | blue_blink |
|
||||
| ust | blue_strike |
|
||||
| lu | light_blue |
|
||||
| lub | light_blue_bold |
|
||||
| luu | light_blue_underline |
|
||||
| lui | light_blue_italic |
|
||||
| lud | light_blue_dimmed |
|
||||
| lur | light_blue_reverse |
|
||||
| lubl | light_blue_blink |
|
||||
| lust | light_blue_strike |
|
||||
| b | black |
|
||||
| bb | black_bold |
|
||||
| bu | black_underline |
|
||||
| bi | black_italic |
|
||||
| bd | black_dimmed |
|
||||
| br | black_reverse |
|
||||
| bbl | black_blink |
|
||||
| bst | black_strike |
|
||||
| ligr | light_gray |
|
||||
| ligrb | light_gray_bold |
|
||||
| ligru | light_gray_underline |
|
||||
| ligri | light_gray_italic |
|
||||
| ligrd | light_gray_dimmed |
|
||||
| ligrr | light_gray_reverse |
|
||||
| ligrbl | light_gray_blink |
|
||||
| ligrst | light_gray_strike |
|
||||
| y | yellow |
|
||||
| yb | yellow_bold |
|
||||
| yu | yellow_underline |
|
||||
| yi | yellow_italic |
|
||||
| yd | yellow_dimmed |
|
||||
| yr | yellow_reverse |
|
||||
| ybl | yellow_blink |
|
||||
| yst | yellow_strike |
|
||||
| ly | light_yellow |
|
||||
| lyb | light_yellow_bold |
|
||||
| lyu | light_yellow_underline |
|
||||
| lyi | light_yellow_italic |
|
||||
| lyd | light_yellow_dimmed |
|
||||
| lyr | light_yellow_reverse |
|
||||
| lybl | light_yellow_blink |
|
||||
| lyst | light_yellow_strike |
|
||||
| p | purple |
|
||||
| pb | purple_bold |
|
||||
| pu | purple_underline |
|
||||
| pi | purple_italic |
|
||||
| pd | purple_dimmed |
|
||||
| pr | purple_reverse |
|
||||
| pbl | purple_blink |
|
||||
| pst | purple_strike |
|
||||
| lp | light_purple |
|
||||
| lpb | light_purple_bold |
|
||||
| lpu | light_purple_underline |
|
||||
| lpi | light_purple_italic |
|
||||
| lpd | light_purple_dimmed |
|
||||
| lpr | light_purple_reverse |
|
||||
| lpbl | light_purple_blink |
|
||||
| lpst | light_purple_strike |
|
||||
| c | cyan |
|
||||
| cb | cyan_bold |
|
||||
| cu | cyan_underline |
|
||||
| ci | cyan_italic |
|
||||
| cd | cyan_dimmed |
|
||||
| cr | cyan_reverse |
|
||||
| cbl | cyan_blink |
|
||||
| cst | cyan_strike |
|
||||
| lc | light_cyan |
|
||||
| lcb | light_cyan_bold |
|
||||
| lcu | light_cyan_underline |
|
||||
| lci | light_cyan_italic |
|
||||
| lcd | light_cyan_dimmed |
|
||||
| lcr | light_cyan_reverse |
|
||||
| lcbl | light_cyan_blink |
|
||||
| lcst | light_cyan_strike |
|
||||
| w | white |
|
||||
| wb | white_bold |
|
||||
| wu | white_underline |
|
||||
| wi | white_italic |
|
||||
| wd | white_dimmed |
|
||||
| wr | white_reverse |
|
||||
| wbl | white_blink |
|
||||
| wst | white_strike |
|
||||
| dgr | dark_gray |
|
||||
| dgrb | dark_gray_bold |
|
||||
| dgru | dark_gray_underline |
|
||||
| dgri | dark_gray_italic |
|
||||
| dgrd | dark_gray_dimmed |
|
||||
| dgrr | dark_gray_reverse |
|
||||
| dgrbl | dark_gray_blink |
|
||||
| dgrst | dark_gray_strike |
|
||||
|
||||
### `"#hex"` format
|
||||
|
||||
---
|
||||
|
||||
The "#hex" format is one way you typically see colors represented. It's simply the `#` character followed by 6 characters. The first two are for `red`, the second two are for `green`, and the third two are for `blue`. It's important that this string be surrounded in quotes, otherwise nushell thinks it's a commented out string.
|
||||
|
||||
Example: The primary `red` color is `"#ff0000"` or `"#FF0000"`. Upper and lower case in letters shouldn't make a difference.
|
||||
|
||||
This `"#hex"` format allows us to specify 24-bit truecolor tones to different parts of nushell.
|
||||
|
||||
## `full "#hex"` format
|
||||
|
||||
---
|
||||
|
||||
The `full "#hex"` format is a take on the `"#hex"` format but allows one to specify the foreground, background, and attributes in one line.
|
||||
|
||||
Example: `{ fg: "#ff0000" bg: "#0000ff" attr: b }`
|
||||
|
||||
- foreground of red in "#hex" format
|
||||
- background of blue in "#hex" format
|
||||
- attribute of bold abbreviated
|
||||
|
||||
## `Primitive values`
|
||||
|
||||
---
|
||||
|
||||
Primitive values are things like `int` and `string`. Primitive values and shapes can be set with a variety of color symbologies seen above.
|
||||
|
||||
This is the current list of primitives. Not all of these are configurable. The configurable ones are marked with \*.
|
||||
|
||||
| primitive | default color | configurable |
|
||||
| ------------ | --------------------- | ------------ |
|
||||
| `any` | | |
|
||||
| `binary` | Color::White.normal() | \* |
|
||||
| `block` | Color::White.normal() | \* |
|
||||
| `bool` | Color::White.normal() | \* |
|
||||
| `cellpath` | Color::White.normal() | \* |
|
||||
| `condition` | | |
|
||||
| `custom` | | |
|
||||
| `date` | Color::White.normal() | \* |
|
||||
| `duration` | Color::White.normal() | \* |
|
||||
| `expression` | | |
|
||||
| `filesize` | Color::White.normal() | \* |
|
||||
| `float` | Color::White.normal() | \* |
|
||||
| `glob` | | |
|
||||
| `import` | | |
|
||||
| `int` | Color::White.normal() | \* |
|
||||
| `list` | Color::White.normal() | \* |
|
||||
| `nothing` | Color::White.normal() | \* |
|
||||
| `number` | | |
|
||||
| `operator` | | |
|
||||
| `path` | | |
|
||||
| `range` | Color::White.normal() | \* |
|
||||
| `record` | Color::White.normal() | \* |
|
||||
| `signature` | | |
|
||||
| `string` | Color::White.normal() | \* |
|
||||
| `table` | | |
|
||||
| `var` | | |
|
||||
| `vardecl` | | |
|
||||
| `variable` | | |
|
||||
|
||||
#### special "primitives" (not really primitives but they exist solely for coloring)
|
||||
|
||||
| primitive | default color | configurable |
|
||||
| --------------------------- | -------------------------- | ------------ |
|
||||
| `leading_trailing_space_bg` | Color::Rgb(128, 128, 128)) | \* |
|
||||
| `header` | Color::Green.bold() | \* |
|
||||
| `empty` | Color::Blue.normal() | \* |
|
||||
| `row_index` | Color::Green.bold() | \* |
|
||||
| `hints` | Color::DarkGray.normal() | \* |
|
||||
|
||||
Here's a small example of changing some of these values.
|
||||
|
||||
```
|
||||
let config = {
|
||||
color_config: {
|
||||
separator: purple
|
||||
leading_trailing_space_bg: "#ffffff"
|
||||
header: gb
|
||||
date: wd
|
||||
filesize: c
|
||||
row_index: cb
|
||||
bool: red
|
||||
int: green
|
||||
duration: blue_bold
|
||||
range: purple
|
||||
float: red
|
||||
string: white
|
||||
nothing: red
|
||||
binary: red
|
||||
cellpath: cyan
|
||||
hints: dark_gray
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Here's another small example using multiple color syntaxes with some comments.
|
||||
|
||||
```
|
||||
let config = {
|
||||
color_config: {
|
||||
separator: "#88b719" # this sets only the foreground color like PR #486
|
||||
leading_trailing_space_bg: white # this sets only the foreground color in the original style
|
||||
header: { # this is like PR #489
|
||||
fg: "#B01455", # note, quotes are required on the values with hex colors
|
||||
bg: "#ffb900",# note, commas are not required, it could also be all on one line
|
||||
attr: bli # note, there are no quotes around this value. it works with or without quotes
|
||||
}
|
||||
date: "#75507B"
|
||||
filesize: "#729fcf"
|
||||
row_index: { # note, that this is another way to set only the foreground, no need to specify bg and attr
|
||||
fg: "#e50914"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## `Shape` values
|
||||
|
||||
As mentioned above, `shape` is a term used to indicate the sytax coloring.
|
||||
|
||||
Here's the current list of flat shapes.
|
||||
|
||||
| shape | default style | configurable |
|
||||
| ---------------------------- | -------------------------------------- | ------------ |
|
||||
| `shape_block` | fg(Color::Blue).bold() | \* |
|
||||
| `shape_bool` | fg(Color::LightCyan) | \* |
|
||||
| `shape_custom` | bold() | \* |
|
||||
| `shape_external` | fg(Color::Cyan) | \* |
|
||||
| `shape_externalarg` | fg(Color::Green).bold() | \* |
|
||||
| `shape_filepath` | fg(Color::Cyan) | \* |
|
||||
| `shape_flag` | fg(Color::Blue).bold() | \* |
|
||||
| `shape_float` | fg(Color::Purple).bold() | \* |
|
||||
| `shape_garbage` | fg(Color::White).on(Color::Red).bold() | \* |
|
||||
| `shape_globpattern` | fg(Color::Cyan).bold() | \* |
|
||||
| `shape_int` | fg(Color::Purple).bold() | \* |
|
||||
| `shape_internalcall` | fg(Color::Cyan).bold() | \* |
|
||||
| `shape_list` | fg(Color::Cyan).bold() | \* |
|
||||
| `shape_literal` | fg(Color::Blue) | \* |
|
||||
| `shape_nothing` | fg(Color::LightCyan) | \* |
|
||||
| `shape_operator` | fg(Color::Yellow) | \* |
|
||||
| `shape_range` | fg(Color::Yellow).bold() | \* |
|
||||
| `shape_record` | fg(Color::Cyan).bold() | \* |
|
||||
| `shape_signature` | fg(Color::Green).bold() | \* |
|
||||
| `shape_string` | fg(Color::Green) | \* |
|
||||
| `shape_string_interpolation` | fg(Color::Cyan).bold() | \* |
|
||||
| `shape_table` | fg(Color::Blue).bold() | \* |
|
||||
| `shape_variable` | fg(Color::Purple) | \* |
|
||||
|
||||
Here's a small example of how to apply color to these items. Anything not specified will receive the default color.
|
||||
|
||||
```
|
||||
let $config = {
|
||||
color_config: {
|
||||
shape_garbage: { fg: "#FFFFFF" bg: "#FF0000" attr: b}
|
||||
shape_bool: green
|
||||
shape_int: { fg: "#0000ff" attr: b}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## `Prompt` configuration and coloring
|
||||
|
||||
The nushell prompt is configurable through these environment variables settings.
|
||||
|
||||
- `PROMPT_COMMAND`: Code to execute for setting up the prompt (block)
|
||||
- `PROMPT_COMMAND_RIGHT`: Code to execute for setting up the _RIGHT_ prompt (block) (see oh-my.nu in nu_scripts)
|
||||
- `PROMPT_INDICATOR` = "〉": The indicator printed after the prompt (by default ">"-like Unicode symbol)
|
||||
- `PROMPT_INDICATOR_VI_INSERT` = ": "
|
||||
- `PROMPT_INDICATOR_VI_NORMAL` = "v "
|
||||
- `PROMPT_MULTILINE_INDICATOR` = "::: "
|
||||
|
||||
Example: For a simple prompt one could do this. Note that `PROMPT_COMMAND` requires a `block` whereas the others require a `string`.
|
||||
|
||||
`> let-env PROMPT_COMMAND = { build-string (date now | date format '%m/%d/%Y %I:%M:%S%.3f') ': ' (pwd | path basename) }`
|
||||
|
||||
If you don't like the default `PROMPT_INDICATOR` you could change it like this.
|
||||
|
||||
`> let-env PROMPT_INDICATOR = "> "`
|
||||
|
||||
Coloring of the prompt is controlled by the `block` in `PROMPT_COMMAND` where you can write your own custom prompt. We've written a slightly fancy one that has git statuses located in the [nu_scripts repo](https://github.com/nushell/nu_scripts/blob/main/engine-q/prompt/oh-my.nu).
|
||||
|
||||
## `LS_COLORS` colors for the `ls` command
|
||||
|
||||
Nushell will respect and use the `LS_COLORS` environment variable setting on Mac, Linux, and Windows. This setting allows you to define the color of file types when you do a `ls`. For instance, you can make directories one color, _.md markdown files another color, _.toml files yet another color, etc. There are a variety of ways to color your file types.
|
||||
|
||||
There's an exhaustive list [here](https://github.com/trapd00r/LS_COLORS), which is overkill, but gives you an rudimentary understanding of how to create a ls_colors file that `dircolors` can turn into a `LS_COLORS` environment variable.
|
||||
|
||||
[This](https://www.linuxhowto.net/how-to-set-colors-for-ls-command/) is a pretty good introduction to `LS_COLORS`. I'm sure you can fine many more tutorials on the web.
|
||||
|
||||
I like the `vivid` application and currently have it configured in my `config.nu` like this. You can find `vivid` [here](https://github.com/sharkdp/vivid).
|
||||
|
||||
`let-env LS_COLORS = (vivid generate molokai | str trim)`
|
||||
|
||||
## Theming
|
||||
|
||||
Theming combines all the coloring above. Here's a quick example of one we put together quickly to demonstrate the ability to theme. This is a spin on the `base16` themes that we see so widespread on the web.
|
||||
|
||||
The key to making theming work is to make sure you specify all themes and colors you're going to use in the `config.nu` file _before_ you declare the `let config = ` line.
|
||||
|
||||
```
|
||||
# lets define some colors
|
||||
|
||||
let base00 = "#181818" # Default Background
|
||||
let base01 = "#282828" # Lighter Background (Used for status bars, line number and folding marks)
|
||||
let base02 = "#383838" # Selection Background
|
||||
let base03 = "#585858" # Comments, Invisibles, Line Highlighting
|
||||
let base04 = "#b8b8b8" # Dark Foreground (Used for status bars)
|
||||
let base05 = "#d8d8d8" # Default Foreground, Caret, Delimiters, Operators
|
||||
let base06 = "#e8e8e8" # Light Foreground (Not often used)
|
||||
let base07 = "#f8f8f8" # Light Background (Not often used)
|
||||
let base08 = "#ab4642" # Variables, XML Tags, Markup Link Text, Markup Lists, Diff Deleted
|
||||
let base09 = "#dc9656" # Integers, Boolean, Constants, XML Attributes, Markup Link Url
|
||||
let base0a = "#f7ca88" # Classes, Markup Bold, Search Text Background
|
||||
let base0b = "#a1b56c" # Strings, Inherited Class, Markup Code, Diff Inserted
|
||||
let base0c = "#86c1b9" # Support, Regular Expressions, Escape Characters, Markup Quotes
|
||||
let base0d = "#7cafc2" # Functions, Methods, Attribute IDs, Headings
|
||||
let base0e = "#ba8baf" # Keywords, Storage, Selector, Markup Italic, Diff Changed
|
||||
let base0f = "#a16946" # Deprecated, Opening/Closing Embedded Language Tags, e.g. <?php ?>
|
||||
|
||||
# we're creating a theme here that uses the colors we defined above.
|
||||
|
||||
let base16_theme = {
|
||||
separator: $base03
|
||||
leading_trailing_space_bg: $base04
|
||||
header: $base0b
|
||||
date: $base0e
|
||||
filesize: $base0d
|
||||
row_index: $base0c
|
||||
bool: $base08
|
||||
int: $base0b
|
||||
duration: $base08
|
||||
range: $base08
|
||||
float: $base08
|
||||
string: $base04
|
||||
nothing: $base08
|
||||
binary: $base08
|
||||
cellpath: $base08
|
||||
hints: dark_gray
|
||||
|
||||
# shape_garbage: { fg: $base07 bg: $base08 attr: b} # base16 white on red
|
||||
# but i like the regular white on red for parse errors
|
||||
shape_garbage: { fg: "#FFFFFF" bg: "#FF0000" attr: b}
|
||||
shape_bool: $base0d
|
||||
shape_int: { fg: $base0e attr: b}
|
||||
shape_float: { fg: $base0e attr: b}
|
||||
shape_range: { fg: $base0a attr: b}
|
||||
shape_internalcall: { fg: $base0c attr: b}
|
||||
shape_external: $base0c
|
||||
shape_externalarg: { fg: $base0b attr: b}
|
||||
shape_literal: $base0d
|
||||
shape_operator: $base0a
|
||||
shape_signature: { fg: $base0b attr: b}
|
||||
shape_string: $base0b
|
||||
shape_filepath: $base0d
|
||||
shape_globpattern: { fg: $base0d attr: b}
|
||||
shape_variable: $base0e
|
||||
shape_flag: { fg: $base0d attr: b}
|
||||
shape_custom: {attr: b}
|
||||
}
|
||||
|
||||
# now let's apply our regular config settings but also apply the "color_config:" theme that we specified above.
|
||||
|
||||
let config = {
|
||||
filesize_metric: true
|
||||
table_mode: rounded # basic, compact, compact_double, light, thin, with_love, rounded, reinforced, heavy, none, other
|
||||
use_ls_colors: true
|
||||
color_config: $base16_theme # <-- this is the theme
|
||||
use_grid_icons: true
|
||||
footer_mode: always #always, never, number_of_rows, auto
|
||||
animate_prompt: false
|
||||
float_precision: 2
|
||||
without_color: false
|
||||
filesize_format: "b" # b, kb, kib, mb, mib, gb, gib, tb, tib, pb, pib, eb, eib, zb, zib, auto
|
||||
edit_mode: emacs # vi
|
||||
max_history_size: 10000
|
||||
log_level: error
|
||||
}
|
||||
```
|
||||
|
||||
if you want to go full-tilt on theming, you'll want to theme all the items I mentioned at the very beginning, including LS_COLORS, and the prompt. Good luck!
|
|
@ -1,3 +1,5 @@
|
|||
# Documentation
|
||||
|
||||
Here is a collection of various pages documenting the changes made in engine-q which should probably end up in the book after we merge it to Nushell.
|
||||
|
||||
Please see our [book](https://www.nushell.sh) for more complete documentation
|
||||
|
|
|
@ -1,95 +0,0 @@
|
|||
filesize_format = "B" # can be b, kb, kib, mb, mib, gb, gib, etc
|
||||
filesize_metric = true # true => (KB, MB, GB), false => (KiB, MiB, GiB)
|
||||
skip_welcome_message = false # Note to nushell developer: This is expected to be false, when testing nushell itself
|
||||
disable_table_indexes = false
|
||||
nonzero_exit_errors = true
|
||||
startup = [
|
||||
"alias la = ls --all",
|
||||
"alias ll = ls --long",
|
||||
"def nudown [] {fetch https://api.github.com/repos/nushell/nushell/releases | get assets | select name download_count}",
|
||||
"def nuver [] {version | pivot key value}",
|
||||
]
|
||||
table_mode = "other" # basic, compact, compact_double, light, thin, with_love, rounded, reinforced, heavy, none, other
|
||||
plugin_dirs = ["D:\\Src\\GitHub\\nu-plugin-lib\\samples\\Nu.Plugin.Len\\bin\\Debug\\netcoreapp3.1"]
|
||||
pivot_mode = "auto" # auto, always, never
|
||||
ctrlc_exit = false
|
||||
complete_from_path = true
|
||||
rm_always_trash = true
|
||||
|
||||
[env]
|
||||
# nu now reads PROMPT_COMMAND env var instead of "prompt" config parameter
|
||||
# and if fails to parse it, it silently ignores it and uses default prompt
|
||||
PROMPT_COMMAND = "build-string (ansi gb) (pwd) (ansi reset) '(' (ansi cb) (do -i { git rev-parse --abbrev-ref HEAD } | str trim ) (ansi reset) ')' (char newline) (ansi yb) (date format '%m/%d/%Y %I:%M:%S%.3f %p') (ansi reset) '> ' "
|
||||
|
||||
# for each of the options in the color_config section, you are able to set
|
||||
# the color alone or with one of the following attributes.
|
||||
# color, abbreviation
|
||||
# green g
|
||||
# red r
|
||||
# blue u
|
||||
# black b
|
||||
# yellow y
|
||||
# purple p
|
||||
# cyan c
|
||||
# white w
|
||||
# attribute, abbreviation
|
||||
# bold b
|
||||
# underline u
|
||||
# italic i
|
||||
# dimmed d
|
||||
# reverse r
|
||||
# abbreviated: green bold = gb, red underline = ru, blue dimmed = ud
|
||||
# or verbose: green_bold, red_underline, blue_dimmed
|
||||
|
||||
[color_config]
|
||||
primitive_int = "green"
|
||||
primitive_decimal = "red"
|
||||
primitive_filesize = "ur"
|
||||
primitive_string = "pb"
|
||||
primitive_line = "yellow"
|
||||
primitive_columnpath = "cyan"
|
||||
primitive_pattern = "white"
|
||||
primitive_boolean = "green"
|
||||
primitive_date = "ru"
|
||||
primitive_duration = "blue"
|
||||
primitive_range = "purple"
|
||||
primitive_path = "yellow"
|
||||
primitive_binary = "cyan"
|
||||
separator_color = "purple"
|
||||
header_align = "l" # left|l, right|r, center|c
|
||||
header_color = "c" # green|g, red|r, blue|u, black|b, yellow|y, purple|p, cyan|c, white|w
|
||||
index_color = "rd"
|
||||
leading_trailing_space_bg = "white"
|
||||
|
||||
[line_editor]
|
||||
max_history_size = 100000
|
||||
history_duplicates = "ignoreconsecutive" # alwaysadd,ignoreconsecutive
|
||||
history_ignore_space = false
|
||||
completion_type = "circular" # circular, list, fuzzy
|
||||
completion_prompt_limit = 100
|
||||
keyseq_timeout_ms = 500 # ms
|
||||
edit_mode = "emacs" # vi, emacs
|
||||
auto_add_history = true
|
||||
bell_style = "audible" # audible, none, visible
|
||||
color_mode = "enabled" # enabled, forced, disabled
|
||||
tab_stop = 4
|
||||
|
||||
[textview]
|
||||
term_width = "default" # "default" or a number
|
||||
tab_width = 4
|
||||
colored_output = true
|
||||
true_color = true
|
||||
header = true
|
||||
line_numbers = true
|
||||
grid = false
|
||||
vcs_modification_markers = true
|
||||
snip = true
|
||||
wrapping_mode = "NoWrapping" # Character, NoWrapping
|
||||
use_italics = true
|
||||
paging_mode = "QuitIfOneScreen" # Always, QuitIfOneScreen, Never
|
||||
pager = "less"
|
||||
theme = "TwoDark"
|
||||
|
||||
# To add path and env do this
|
||||
# > config set path $nu.path
|
||||
# > config set env $nu.env
|
|
@ -112,7 +112,7 @@ extern "git push" [
|
|||
let default_theme = {
|
||||
# color for nushell primitives
|
||||
separator: white
|
||||
leading_trailing_space_bg: { attr: b }
|
||||
leading_trailing_space_bg: { attr: n } # no fg, no bg, attr non effectively turns this off
|
||||
header: green_bold
|
||||
empty: blue
|
||||
bool: white
|
||||
|
@ -198,7 +198,7 @@ let $config = {
|
|||
modifier: none
|
||||
keycode: tab
|
||||
mode: emacs # emacs vi_normal vi_insert
|
||||
event: {
|
||||
event: {
|
||||
until: [
|
||||
{ send: menu name: completion_menu }
|
||||
{ send: menunext }
|
||||
|
@ -217,7 +217,7 @@ let $config = {
|
|||
modifier: control
|
||||
keycode: char_x
|
||||
mode: emacs # emacs vi_normal vi_insert
|
||||
event: {
|
||||
event: {
|
||||
until: [
|
||||
{ send: menu name: history_menu }
|
||||
{ send: menupagenext }
|
||||
|
|
|
@ -1,440 +0,0 @@
|
|||
# These are the common keys acrosso modes taken directly from Rustyline. If
|
||||
# you want to change the keybinding you should change the letter after
|
||||
# "key:". If you want to change the modifier you should change or add the
|
||||
# modifier after "key:", such as:
|
||||
# key:
|
||||
# Char: A
|
||||
# modifiers:
|
||||
# CTRL:
|
||||
# binding:
|
||||
# blah:
|
||||
# Available modifiers are CTRL, ALT, SHIFT, NONE, CTRL_SHIFT,
|
||||
# ALT_SHIFT, CTRL_ALT, CTRL_ALT_SHIFT
|
||||
|
||||
##########################################################
|
||||
# Common From https://github.com/kkawakam/rustyline#actions
|
||||
##########################################################
|
||||
|
||||
# Control Backspace, delete 1 word at a time
|
||||
- key:
|
||||
Backspace:
|
||||
modifiers:
|
||||
CTRL:
|
||||
binding:
|
||||
Kill:
|
||||
BackwardWord:
|
||||
repeat: 1
|
||||
word: Big
|
||||
|
||||
# Alt Backspace, delete 1 word at a time
|
||||
- key:
|
||||
Backspace:
|
||||
modifiers:
|
||||
ALT:
|
||||
binding:
|
||||
Kill:
|
||||
BackwardWord:
|
||||
repeat: 1
|
||||
word: Big
|
||||
|
||||
# Move cursor to the beginning of line
|
||||
- key:
|
||||
Home:
|
||||
binding:
|
||||
Move: BeginningOfLine
|
||||
|
||||
# Move cursor to end of line
|
||||
- key:
|
||||
End:
|
||||
binding:
|
||||
Move: EndOfLine
|
||||
|
||||
# Move cursor one character left
|
||||
- key:
|
||||
Left: #Left Arrow Key
|
||||
binding:
|
||||
Move:
|
||||
BackwardChar: 1
|
||||
|
||||
# Move cursor one character right
|
||||
- key:
|
||||
Right: #Right Arrow Key
|
||||
binding:
|
||||
Move:
|
||||
ForwardChar: 1
|
||||
|
||||
# Complete Hint
|
||||
- key:
|
||||
Right:
|
||||
modifiers:
|
||||
SHIFT:
|
||||
binding:
|
||||
CompleteHint:
|
||||
- key:
|
||||
Char: F
|
||||
modifiers:
|
||||
CTRL:
|
||||
binding:
|
||||
CompleteHint:
|
||||
|
||||
# Interrupt/Cancel edition
|
||||
- key:
|
||||
Char: C
|
||||
modifiers:
|
||||
CTRL:
|
||||
binding:
|
||||
Interrupt:
|
||||
|
||||
# (if line is not empty) Delete character under cursor
|
||||
- key:
|
||||
Char: D
|
||||
modifiers:
|
||||
CTRL:
|
||||
binding:
|
||||
EndOfFile:
|
||||
|
||||
# Delete character under cursor
|
||||
- key:
|
||||
Delete:
|
||||
binding:
|
||||
Kill:
|
||||
ForwardChar: 1
|
||||
|
||||
# Finish the line entry
|
||||
- key:
|
||||
Char: J
|
||||
modifiers:
|
||||
CTRL:
|
||||
binding:
|
||||
AcceptLine:
|
||||
- key:
|
||||
Char: M
|
||||
modifiers:
|
||||
CTRL:
|
||||
binding:
|
||||
AcceptLine:
|
||||
|
||||
# This makes multiline editing stop working since Enter accepts a line
|
||||
# - key:
|
||||
# Enter:
|
||||
# binding:
|
||||
# AcceptLine:
|
||||
|
||||
# Next match from history
|
||||
- key:
|
||||
Down: #Down Arrow Key
|
||||
binding:
|
||||
LineDownOrNextHistory: 1
|
||||
|
||||
# Previous match from history
|
||||
- key:
|
||||
Up: #Up Arrow Key
|
||||
binding:
|
||||
LineUpOrPreviousHistory: 1
|
||||
|
||||
# Reverse Search history (Ctrl-S forward, Ctrl-G cancel)
|
||||
- key:
|
||||
Char: R
|
||||
modifiers:
|
||||
CTRL:
|
||||
binding:
|
||||
ReverseSearchHistory:
|
||||
|
||||
# Forward Search history (Ctrl-R backward, Ctrl-G cancel)
|
||||
- key:
|
||||
Char: S
|
||||
modifiers:
|
||||
CTRL:
|
||||
binding:
|
||||
ForwardSearchHistory:
|
||||
|
||||
# Transpose previous character with current character
|
||||
- key:
|
||||
Char: T
|
||||
modifiers:
|
||||
CTRL:
|
||||
binding:
|
||||
TransposeChars:
|
||||
|
||||
# Delete from start of line to cursor
|
||||
- key:
|
||||
Char: U
|
||||
modifiers:
|
||||
CTRL:
|
||||
binding:
|
||||
Kill: BeginningOfLine
|
||||
|
||||
# Insert any special character without performing its associated action (#65)
|
||||
- key:
|
||||
Char: Q
|
||||
modifiers:
|
||||
CTRL:
|
||||
binding:
|
||||
QuotedInsert:
|
||||
- key:
|
||||
Char: V
|
||||
modifiers:
|
||||
CTRL:
|
||||
binding:
|
||||
QuotedInsert:
|
||||
|
||||
# Delete word leading up to cursor (using white space as a word boundary)
|
||||
- key:
|
||||
Char: W
|
||||
modifiers:
|
||||
CTRL:
|
||||
binding:
|
||||
Kill:
|
||||
BackwardWord:
|
||||
repeat: 1
|
||||
word: Big
|
||||
|
||||
# Paste from Yank buffer
|
||||
- key:
|
||||
Char: Y
|
||||
modifiers:
|
||||
CTRL:
|
||||
binding:
|
||||
Yank:
|
||||
repeat: 1
|
||||
anchor: Before
|
||||
|
||||
# Suspend (Unix only)
|
||||
- key:
|
||||
Char: Z
|
||||
modifiers:
|
||||
CTRL:
|
||||
binding:
|
||||
Suspend:
|
||||
|
||||
# Undo
|
||||
- key:
|
||||
Char: "_"
|
||||
modifiers:
|
||||
CTRL:
|
||||
binding:
|
||||
Undo: 1
|
||||
|
||||
# KeyPress::UnknownEscSeq => Cmd::Noop,
|
||||
- key:
|
||||
UnknownEscSeq:
|
||||
binding:
|
||||
Noop:
|
||||
##########################################################
|
||||
# Possible options for key:
|
||||
##########################################################
|
||||
# /// Unsupported escape sequence (on unix platform)
|
||||
# UnknownEscSeq,
|
||||
# /// ⌫ or `KeyEvent::Ctrl('H')`
|
||||
# Backspace,
|
||||
# /// ⇤ (usually Shift-Tab)
|
||||
# BackTab,
|
||||
# /// Paste (on unix platform)
|
||||
# BracketedPasteStart,
|
||||
# /// Paste (on unix platform)
|
||||
# BracketedPasteEnd,
|
||||
# /// Single char
|
||||
# Char(char),
|
||||
# /// ⌦
|
||||
# Delete,
|
||||
# /// ↓ arrow key
|
||||
# Down,
|
||||
# /// ⇲
|
||||
# End,
|
||||
# /// ↵ or `KeyEvent::Ctrl('M')`
|
||||
# Enter,
|
||||
# /// Escape or `KeyEvent::Ctrl('[')`
|
||||
# Esc,
|
||||
# /// Function key
|
||||
# F(u8),
|
||||
# /// ⇱
|
||||
# Home,
|
||||
# /// Insert key
|
||||
# Insert,
|
||||
# /// ← arrow key
|
||||
# Left,
|
||||
# // /// `KeyEvent::Char('\0')`
|
||||
# Null,
|
||||
# /// ⇟
|
||||
# PageDown,
|
||||
# /// ⇞
|
||||
# PageUp,
|
||||
# /// → arrow key
|
||||
# Right,
|
||||
# /// ⇥ or `KeyEvent::Ctrl('I')`
|
||||
# Tab,
|
||||
# /// ↑ arrow key
|
||||
# Up,
|
||||
|
||||
##########################################################
|
||||
# Possible options for command binding
|
||||
##########################################################
|
||||
# /// abort
|
||||
# Abort, // Miscellaneous Command
|
||||
# /// accept-line
|
||||
# AcceptLine,
|
||||
# /// beginning-of-history
|
||||
# BeginningOfHistory,
|
||||
# /// capitalize-word
|
||||
# CapitalizeWord,
|
||||
# /// clear-screen
|
||||
# ClearScreen,
|
||||
# /// complete
|
||||
# Complete,
|
||||
# /// complete-backward
|
||||
# CompleteBackward,
|
||||
# /// complete-hint
|
||||
# CompleteHint,
|
||||
# /// Dedent current line
|
||||
# Dedent(Movement),
|
||||
# /// downcase-word
|
||||
# DowncaseWord,
|
||||
# /// vi-eof-maybe
|
||||
# EndOfFile,
|
||||
# /// end-of-history
|
||||
# EndOfHistory,
|
||||
# /// forward-search-history
|
||||
# ForwardSearchHistory,
|
||||
# /// history-search-backward
|
||||
# HistorySearchBackward,
|
||||
# /// history-search-forward
|
||||
# HistorySearchForward,
|
||||
# /// Indent current line
|
||||
# Indent(Movement),
|
||||
# /// Insert text
|
||||
# Insert { repeat: RepeatCount, string: String },
|
||||
# /// Interrupt signal (Ctrl-C)
|
||||
# Interrupt,
|
||||
# /// backward-delete-char, backward-kill-line, backward-kill-word
|
||||
# /// delete-char, kill-line, kill-word, unix-line-discard, unix-word-rubout,
|
||||
# /// vi-delete, vi-delete-to, vi-rubout
|
||||
# Kill(Movement),
|
||||
# /// backward-char, backward-word, beginning-of-line, end-of-line,
|
||||
# /// forward-char, forward-word, vi-char-search, vi-end-word, vi-next-word,
|
||||
# /// vi-prev-word
|
||||
# Move(Movement),
|
||||
# /// Inserts a newline
|
||||
# Newline,
|
||||
# /// next-history
|
||||
# NextHistory,
|
||||
# /// No action
|
||||
# Noop,
|
||||
# /// vi-replace
|
||||
# Overwrite(char),
|
||||
# /// Paste from the clipboard
|
||||
# #[cfg(windows)]
|
||||
# PasteFromClipboard,
|
||||
# /// previous-history
|
||||
# PreviousHistory,
|
||||
# /// quoted-insert
|
||||
# QuotedInsert,
|
||||
# /// vi-change-char
|
||||
# ReplaceChar { repeat: RepeatCount, ch: char },
|
||||
# /// vi-change-to, vi-substitute
|
||||
# Replace {
|
||||
# movement: Movement,
|
||||
# replacement: Option<String>,
|
||||
# },
|
||||
# /// reverse-search-history
|
||||
# ReverseSearchHistory,
|
||||
# /// self-insert
|
||||
# SelfInsert { repeat: RepeatCount, ch: char },
|
||||
# /// Suspend signal (Ctrl-Z on unix platform)
|
||||
# Suspend,
|
||||
# /// transpose-chars
|
||||
# TransposeChars,
|
||||
# /// transpose-words
|
||||
# TransposeWords(RepeatCount),
|
||||
# /// undo
|
||||
# Undo(RepeatCount),
|
||||
# /// Unsupported / unexpected
|
||||
# Unknown,
|
||||
# /// upcase-word
|
||||
# UpcaseWord,
|
||||
# /// vi-yank-to
|
||||
# ViYankTo(Movement),
|
||||
# /// yank, vi-put
|
||||
# Yank { repeat: RepeatCount, anchor: Anchor },
|
||||
# /// yank-pop
|
||||
# YankPop,
|
||||
# /// moves cursor to the line above or switches to prev history entry if
|
||||
# /// the cursor is already on the first line
|
||||
# LineUpOrPreviousHistory(RepeatCount),
|
||||
# /// moves cursor to the line below or switches to next history entry if
|
||||
# /// the cursor is already on the last line
|
||||
# LineDownOrNextHistory(RepeatCount),
|
||||
# /// accepts the line when cursor is at the end of the text (non including
|
||||
# /// trailing whitespace), inserts newline character otherwise
|
||||
# AcceptOrInsertLine,
|
||||
|
||||
##########################################################
|
||||
# Possible options for Word
|
||||
##########################################################
|
||||
# /// non-blanks characters
|
||||
# Big,
|
||||
# /// alphanumeric characters
|
||||
# Emacs,
|
||||
# /// alphanumeric (and '_') characters
|
||||
# Vi,
|
||||
|
||||
##########################################################
|
||||
# Possible options for At
|
||||
##########################################################
|
||||
# /// Start of word.
|
||||
# Start,
|
||||
# /// Before end of word.
|
||||
# BeforeEnd,
|
||||
# /// After end of word.
|
||||
# AfterEnd,
|
||||
|
||||
##########################################################
|
||||
# Possible options for Anchor
|
||||
##########################################################
|
||||
# /// After cursor
|
||||
# After,
|
||||
# /// Before cursor
|
||||
# Before,
|
||||
|
||||
##########################################################
|
||||
# Possible options for CharSearch
|
||||
##########################################################
|
||||
# /// Forward search
|
||||
# Forward(char),
|
||||
# /// Forward search until
|
||||
# ForwardBefore(char),
|
||||
# /// Backward search
|
||||
# Backward(char),
|
||||
# /// Backward search until
|
||||
# BackwardAfter(char),
|
||||
|
||||
##########################################################
|
||||
# Possible options for Movement
|
||||
##########################################################
|
||||
# /// Whole current line (not really a movement but a range)
|
||||
# WholeLine,
|
||||
# /// beginning-of-line
|
||||
# BeginningOfLine,
|
||||
# /// end-of-line
|
||||
# EndOfLine,
|
||||
# /// backward-word, vi-prev-word
|
||||
# BackwardWord(RepeatCount, Word), // Backward until start of word
|
||||
# /// forward-word, vi-end-word, vi-next-word
|
||||
# ForwardWord(RepeatCount, At, Word), // Forward until start/end of word
|
||||
# /// vi-char-search
|
||||
# ViCharSearch(RepeatCount, CharSearch),
|
||||
# /// vi-first-print
|
||||
# ViFirstPrint,
|
||||
# /// backward-char
|
||||
# BackwardChar(RepeatCount),
|
||||
# /// forward-char
|
||||
# ForwardChar(RepeatCount),
|
||||
# /// move to the same column on the previous line
|
||||
# LineUp(RepeatCount),
|
||||
# /// move to the same column on the next line
|
||||
# LineDown(RepeatCount),
|
||||
# /// Whole user input (not really a movement but a range)
|
||||
# WholeBuffer,
|
||||
# /// beginning-of-buffer
|
||||
# BeginningOfBuffer,
|
||||
# /// end-of-buffer
|
||||
# EndOfBuffer,
|
|
@ -1,33 +0,0 @@
|
|||
{
|
||||
"bare_member": "ff0000",
|
||||
"close_delimiter": "ffffff",
|
||||
"comment": "ff0000",
|
||||
"decimal": "0000ff",
|
||||
"dot": "ffffff",
|
||||
"dot_dot": "0000ff",
|
||||
"dot_dot_left_angle_bracket": "00ff00",
|
||||
"external_command": "ffffff",
|
||||
"external_word": "0000ff",
|
||||
"flag": "0000ff",
|
||||
"garbage": "ff0000",
|
||||
"glob_pattern": "ffffff",
|
||||
"identifier": "ff0000",
|
||||
"int": "ffffff",
|
||||
"internal_command": "ff0000",
|
||||
"it_variable": "ffffff",
|
||||
"keyword": "0000ff",
|
||||
"open_delimiter": "ff0000",
|
||||
"operator": "ff0000",
|
||||
"path": "ff0000",
|
||||
"pipe": "ff0000",
|
||||
"separator": "0000ff",
|
||||
"shorthand_flag": "ff0000",
|
||||
"size_number": "ffffff",
|
||||
"size_unit": "0000ff",
|
||||
"string": "0000ff",
|
||||
"string_member": "ffffff",
|
||||
"type": "0000ff",
|
||||
"variable": "0000ff",
|
||||
"whitespace": "ffffff",
|
||||
"word": "ffffff"
|
||||
}
|
|
@ -1,223 +0,0 @@
|
|||
#!/usr/bin/env pwsh
|
||||
|
||||
# Created to demonstrate how to create a plugin with PowerShell
|
||||
# Below is a list of other links to help with scripting language plugin creation
|
||||
# https://vsoch.github.io/2019/nushell-plugin-golang/
|
||||
# Go https://github.com/vsoch/nushell-plugin-len
|
||||
# Python https://github.com/vsoch/nushell-plugin-python
|
||||
# Python https://github.com/vsoch/nushell-plugin-pokemon
|
||||
# C# https://github.com/myty/nu-plugin-lib
|
||||
# Ruby https://github.com/andrasio/nu_plugin
|
||||
|
||||
# WIP 8/26/20
|
||||
# This is not yet ready for prime time but it could give someone
|
||||
# a headstart with writing powershell core plugins for mac/linux/win
|
||||
# Most of the comments are TODO's or functions from python plugins
|
||||
# meant to be used as a reference.
|
||||
#
|
||||
# While this length demonstration works, it is filled with debug
|
||||
# messages that can be seen during normal operation.
|
||||
#
|
||||
# This is by no means complete. Good luck!
|
||||
|
||||
# def print_good_response(response):
|
||||
# json_response = {"jsonrpc": "2.0", "method": "response", "params": {"Ok": response}}
|
||||
# print(json.dumps(json_response))
|
||||
# sys.stdout.flush()
|
||||
|
||||
function print_good_response {
|
||||
param($response)
|
||||
$json_response = @"
|
||||
{"jsonrpc": "2.0", "method": "response", "params": {"Ok": $($response)}}
|
||||
"@
|
||||
Write-Host $json_response
|
||||
}
|
||||
|
||||
# def get_length(string_value):
|
||||
# string_len = len(string_value["item"]["Primitive"]["String"])
|
||||
# int_item = {"Primitive": {"Int": string_len}}
|
||||
# int_value = string_value
|
||||
# int_value["item"] = int_item
|
||||
# return int_value
|
||||
|
||||
# function get_length {
|
||||
# param($string_val)
|
||||
# $string_len = $string_val[`"item`"][`"Primitive`"][`"String`"].Length
|
||||
# }
|
||||
|
||||
function config {
|
||||
param ($json_rpc)
|
||||
#Write-Host $json_rpc
|
||||
|
||||
$response = '{ "jsonrpc": "2.0", "method": "response", "params": { "Ok": { "name": "mylen", "usage": "Return the length of a string", "positional": [], "rest_positional": null, "named": {}, "is_filter": true } } }'
|
||||
Write-Host $response
|
||||
return
|
||||
}
|
||||
|
||||
function begin_filter {
|
||||
$response = '{"jsonrpc":"2.0","method":"response","params":{"Ok":[]}}'
|
||||
Write-Host $response
|
||||
return
|
||||
}
|
||||
|
||||
function run_filter {
|
||||
param($input_data)
|
||||
Write-TraceMessage "PIPED" $input_data
|
||||
|
||||
$prim = "Primitive"
|
||||
$method = $input_data | Select-Object "method"
|
||||
$params = $input_data.params
|
||||
$primitive = $input_data.params.value.$prim
|
||||
$prim_type = ""
|
||||
$len = 0
|
||||
|
||||
if (![String]::IsNullOrEmpty($input_data)) {
|
||||
Write-TraceMessage "FJSON" $input_data
|
||||
}
|
||||
if (![String]::IsNullOrEmpty($method)) {
|
||||
Write-TraceMessage "FMETHOD" $method
|
||||
}
|
||||
if (![String]::IsNullOrEmpty($params)) {
|
||||
Write-TraceMessage "FPARAMS" $params
|
||||
}
|
||||
if (![String]::IsNullOrEmpty($primitive)) {
|
||||
Write-TraceMessage "FPRIMITIVE" $primitive
|
||||
# $prim_type = $primitive | Get-Member -MemberType NoteProperty | Select-Object Name
|
||||
# switch ($prim_type.Name) {
|
||||
# 'String' { $data.params.value.$prim.String }
|
||||
# 'Int' { $data.params.value.$prim.Int }
|
||||
# Default { "none-found" }
|
||||
# }
|
||||
}
|
||||
|
||||
$prim_type = $primitive | Get-Member -MemberType NoteProperty | Select-Object Name
|
||||
switch ($prim_type.Name) {
|
||||
'String' { $len = $input_data.params.value.$prim.String.Length }
|
||||
'Int' { $input_data.params.value.$prim.Int }
|
||||
Default { $len = 0 }
|
||||
}
|
||||
|
||||
# Create a json hash making sure all the child nodes are sorted
|
||||
$json_obj = [ordered]@{
|
||||
jsonrpc = "2.0"
|
||||
method = "response"
|
||||
params = [ordered]@{
|
||||
Ok = @(
|
||||
[ordered]@{
|
||||
Ok = [ordered]@{
|
||||
Value = [ordered]@{
|
||||
value = [ordered]@{
|
||||
Primitive = [ordered]@{
|
||||
Int = $len
|
||||
}
|
||||
}
|
||||
tag = [ordered]@{
|
||||
anchor = $null
|
||||
span = @{
|
||||
end = 2
|
||||
start = 0
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
$response = $json_obj | ConvertTo-Json -Depth 100 -Compress
|
||||
Write-Host $response
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
function end_filter {
|
||||
$response = '{"jsonrpc":"2.0","method":"response","params":{"Ok":[]}}'
|
||||
Write-Host $response
|
||||
return
|
||||
}
|
||||
|
||||
function Write-TraceMessage {
|
||||
Param
|
||||
(
|
||||
[Parameter(Mandatory = false, Position = 0)]
|
||||
[string] $label,
|
||||
[Parameter(Mandatory = false, Position = 1)]
|
||||
[string] $message
|
||||
)
|
||||
|
||||
[Console]::Error.WriteLine("$($label) $($message)")
|
||||
}
|
||||
|
||||
function run_loop {
|
||||
param($data)
|
||||
$prim = "Primitive"
|
||||
$method = $data | Select-Object "method"
|
||||
$params = $data.params
|
||||
$primitive = $data.params.value.$prim
|
||||
# $prim_type = ""
|
||||
# Write out some debug trace messages
|
||||
if (![String]::IsNullOrEmpty($data)) {
|
||||
Write-TraceMessage "JSON" $data
|
||||
}
|
||||
if (![String]::IsNullOrEmpty($method)) {
|
||||
Write-TraceMessage "METHOD" $method
|
||||
}
|
||||
if (![String]::IsNullOrEmpty($params)) {
|
||||
Write-TraceMessage "PARAMS" $params
|
||||
}
|
||||
if (![String]::IsNullOrEmpty($primitive)) {
|
||||
Write-TraceMessage "PRIMITIVE" $primitive
|
||||
# $prim_type = $primitive | Get-Member -MemberType NoteProperty | Select-Object Name
|
||||
# switch ($prim_type.Name) {
|
||||
# 'String' { $data.params.value.$prim.String }
|
||||
# 'Int' { $data.params.value.$prim.Int }
|
||||
# Default { "none-found" }
|
||||
# }
|
||||
}
|
||||
|
||||
|
||||
if ($method[0].method -eq "config") {
|
||||
# Write-TraceMessage "Received config method with: " $data
|
||||
return config
|
||||
}
|
||||
elseif ($method[0].method -eq "begin_filter") {
|
||||
return begin_filter
|
||||
}
|
||||
elseif ($method[0].method -eq "end_filter") {
|
||||
return end_filter
|
||||
}
|
||||
elseif ($method[0].method -eq "filter") {
|
||||
# return run_filter -piped $params
|
||||
return run_filter -input_data $data
|
||||
}
|
||||
}
|
||||
|
||||
function Get-PipedData {
|
||||
param(
|
||||
[Parameter(
|
||||
Position = 0,
|
||||
Mandatory = true,
|
||||
ValueFromPipeline = true,
|
||||
ValueFromPipelineByPropertyName = true)
|
||||
]
|
||||
[Alias('piped')]
|
||||
[String]$piped_input
|
||||
)
|
||||
|
||||
process {
|
||||
# Write-Error $piped_input
|
||||
Write-TraceMessage "BeforeJSON" $piped_input
|
||||
$json = ConvertFrom-Json $piped_input
|
||||
run_loop -data $json
|
||||
}
|
||||
}
|
||||
|
||||
# $prim = "Primitive"
|
||||
# $j = $json | ConvertFrom-Json
|
||||
# $j.params.value.$prim
|
||||
# String
|
||||
# ------
|
||||
# 123
|
||||
|
||||
# $Input | Get-PipedData
|
||||
$Input | ForEach-Object { $_ | Get-PipedData }
|
Loading…
Reference in a new issue