Skip to content

Commit

Permalink
updates to the cookbook
Browse files Browse the repository at this point in the history
  • Loading branch information
fdncred committed Mar 1, 2022
1 parent eeab593 commit 99da58c
Show file tree
Hide file tree
Showing 9 changed files with 354 additions and 272 deletions.
49 changes: 30 additions & 19 deletions cookbook/files.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,37 +6,39 @@ title: Files

### Editing a file and then saving the changes

Here we are making edits to `Cargo.toml`.
We increase the patch version of the crate using `inc` and then save it back to the file.
Here we are making edits to `Cargo.toml`. We increase the patch version of the crate using `inc` and then save it back to the file.
Use `help inc` to get more information.


Read the file's initial contents

`open Cargo.toml | get package.version`
```shell
> open Cargo.toml | get package.version
```

Output

`0.5.1`
`0.59.0`

Make the edit to the version number and save it.

Nu keeps track of the file you have opened.
You may omit the filename argument from `save` if you want to save the changes to the opened file.
_Note: running this command should work but it will reorder the toml file alphabetically by section._

`open Cargo.toml | inc package.version --patch | save`
```shell
> open Cargo.toml | update package.version { |p| $p | get package.version | inc --patch } | save Cargo.toml
```
Output
*none*
_none_
View the changes we made to the file.
`open Cargo.toml | get package.version`
```shell
> open Cargo.toml | get package.version
```
Output
`0.5.2`

`0.59.1`
---
Expand All @@ -55,9 +57,11 @@ Fugazi:In On The Kill Taker:1993
You can parse it into a table.
`open bands.txt | lines | split column ":" Band Album Year | skip 1 | sort-by Year`
```shell
> open bands.txt | lines | split column ":" Band Album Year | skip 1 | sort-by Year
```
Output
Output
```
━━━┯━━━━━━━━┯━━━━━━━━━━━━━━━━━━━━━━━━┯━━━━━━
Expand All @@ -73,17 +77,24 @@ Output
You can alternatively do this using `parse`.
`open bands.txt | lines | parse "{Band}:{Album}:{Year}" | skip 1 | sort-by Year`
```shell
open bands.txt | lines | parse "{Band}:{Album}:{Year}" | skip 1 | sort-by Year
```
Or, you can utilize the `headers` command to use the first row as a header row like. The only difference would be the headers would match the case of the text file. So, in this case, the headers would be lowercase.
```shell
> open bands.txt | lines | split column ":" | headers | sort-by year
```
---
### Word occurrence count with Ripgrep
Suppose you would like to check the number of lines the string "Tagged" appears per file in the nushell project,
then sort those files by largest line count.
Suppose you would like to check the number of lines the string "Value" appears per file in the nushell project, then sort those files by largest line count.
```
rg -c Tagged | lines | split column ":" file line_count | str to-int line_count | sort-by line_count | reverse
```shell
> rg -c Value | lines | split column ":" file line_count | into int line_count | sort-by line_count | reverse
```
Output
Expand Down
55 changes: 33 additions & 22 deletions cookbook/git.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,46 +7,57 @@ title: Git
Nu can help with common `Git` tasks like removing all local branches which have been merged into master.

### Delete git merged branches
Warning: This command will hard delete the merged branches from your machine.
You may want to check the branches selected for deletion by omitting the last git command.

`git branch --merged | lines | where ($it != "* master" && $it != "* main") | each { git branch -D ($it | str trim) }`
**Warning**: This command will hard delete the merged branches from your machine. You may want to check the branches selected for deletion by omitting the last git command.

Output
```shell
> git branch --merged | lines | where ($it != "* master" && $it != "* main") | each {|br| git branch -D ($br | str trim) }
```

Output - the empty row is output because `git` may be outputting something unexpected that we'd like to track down.

```
Deleted branch post-argument-positions (was 9d34ec9).
╭───┬──╮
│ 0 │ │
╰───┴──╯
```

Parse formatted commit messages (more details in the parsing git log section)

`git log --pretty=%h»¦«%aN»¦«%s»¦«%aD | lines | split column "»¦«" sha1 committer desc merged_at | first 10`

```shell
> git log --pretty=%h»¦«%aN»¦«%s»¦«%aD | lines | split column "»¦«" sha1 committer desc merged_at | first 10
```

Output

```
━━━┯━━━━━━━━━┯━━━━━━━━━━━━━━━━━┯━━━━━━━━━━━━━┯━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
# │ hash │ author │ time │ message
───┼─────────┼─────────────────┼─────────────┼──────────────────────────────────────────────────────────────────
0 │ 9d34ec9 │ Jonathan Turner │ 13 days ago │ Merge pull request #891 from nushell/jonathandturner-patch-1
1 │ fd92271 │ Jonathan Turner │ 13 days ago │ Move rustyline dep back to crates
2 │ 2d44b7d │ Jonathan Turner │ 2 weeks ago │ Update README.md
3 │ faccb06 │ Jonathan Turner │ 2 weeks ago │ Merge pull request #890 from jonathandturner/append_prepend
4 │ a9cd6b4 │ Jonathan Turner │ 2 weeks ago │ Format files
5 │ 81691e0 │ Jonathan Turner │ 2 weeks ago │ Add prepend and append commands
6 │ 26f40dc │ Jonathan Turner │ 2 weeks ago │ Merge pull request #889 from jonathandturner/read_plugin
7 │ 3820fef │ Jonathan Turner │ 2 weeks ago │ Add a simple read/parse plugin to better handle text data
8 │ b6824d8 │ Jonathan Turner │ 2 weeks ago │ Merge pull request #886 from notryanb/fetch-from-variable
9 │ e09160e │ Ryan Blecher │ 2 weeks ago │ add ability to create PathBuf from string to avoid type mismatch
━━━┷━━━━━━━━━┷━━━━━━━━━━━━━━━━━┷━━━━━━━━━━━━━┷━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
───┬──────────┬───────────────────┬───────────────────────────────────────────────────────┬─────────────────────────────────
# │ sha1 │ committer │ desc │ merged_at
───┼──────────┼───────────────────┼───────────────────────────────────────────────────────┼─────────────────────────────────
0 │ 42f1874a │ Justin Ma │ Update some examples and docs (#4682) │ Tue, 1 Mar 2022 21:05:29 +0800
1 │ 2a89936b │ JT │ Move to latest stable crossterm, with fix (#4684) │ Tue, 1 Mar 2022 07:05:46 -0500
2 │ ece5e7db │ Fernando Herrera │ dataframe list command (#4681) │ Tue, 1 Mar 2022 11:41:13 +0000
3 │ a6a96b29 │ JT │ Add binary literals (#4680) │ Mon, 28 Feb 2022 18:31:53 -0500
4 │ e3100e6a │ Luca Trevisani │ Fix alias in `docs/sample_config/config.toml` (#4669) │ Mon, 28 Feb 2022 22:47:14 +0100
5 │ cb5c61d2 │ JT │ Fix open ended ranges (#4677) │ Mon, 28 Feb 2022 11:15:31 -0500
6 │ b09acdb7 │ Justin Ma │ Fix unsupported type message for some math related │ Mon, 28 Feb 2022 23:14:33 +0800
│ │ │ commands (#4672) │
7 │ 0924975b │ JT │ Use default_config.nu by default (#4675) │ Mon, 28 Feb 2022 10:12:08 -0500
8 │ d6a6c4b0 │ JT │ Add back in default keybindings (#4673) │ Mon, 28 Feb 2022 08:54:40 -0500
9 │ eec17304 │ Stefan Holderbach │ Add profiling build profile and symbol strip (#4630) │ Mon, 28 Feb 2022 13:13:24 +0100
───┴──────────┴───────────────────┴───────────────────────────────────────────────────────┴─────────────────────────────────
```

---

### View git comitter activity as a `histogram`

`git log --pretty=%h»¦«%aN»¦«%s»¦«%aD | lines | split column "»¦«" sha1 committer desc merged_at | histogram committer merger | sort-by merger | reverse`
_Note: the `histogram` command is not yet ported to the latest version_

```shell
> git log --pretty=%h»¦«%aN»¦«%s»¦«%aD | lines | split column "»¦«" sha1 committer desc merged_at | histogram committer merger | sort-by merger | reverse
```

```
━━━━┯━━━━━━━━━━━━━━━━━━━━━┯━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Expand All @@ -66,4 +77,4 @@ Output
11 │ Odin Dutton │ *
12 │ Jonathan Rothberg │ *
━━━┷━━━━━━━━━━━━━━━━━━━━━┷━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
```
```
93 changes: 61 additions & 32 deletions cookbook/help.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,72 +8,101 @@ A good way to become familiar with all that nu has to offer is by utilizing the

### How to see all supported commands:

`help commands`
```shell
> help commands | where is_custom == $false | first 10 | drop column
```

Output

```
━━━━┯━━━━━━━━━━━━━┯━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
# │ name │ description
────┼─────────────┼──────────────────────────────────────────────────────────────────────────────
0 │ append │ Append the given row to the table
1 │ autoview │ View the contents of the pipeline as a table or list.
2 │ average │ Compute the average of a column of numerical values.
3 │ binaryview │ Autoview of binary data.
4 │ cd │ Change to a new path.
5 │ clip │ Copy the contents of the pipeline to the copy/paste buffer
6 │ config │ Configuration management.
7 │ count │ Show the total number of rows.
8 │ cp │ Copy files.
9 │ date │ Get the current datetime.
10 │ debug │ Debug input fed.
━━━━┷━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
───┬───────────────┬────────────┬───────────┬───────────┬────────────────────────────────────────────────────────────────
# │ name │ category │ is_plugin │ is_custom │ usage
───┼───────────────┼────────────┼───────────┼───────────┼────────────────────────────────────────────────────────────────
0 │ alias │ core │ false │ false │ Alias a command (with optional flags) to a new name
1 │ all? │ filters │ false │ false │ Test if every element of the input matches a predicate.
2 │ ansi │ platform │ false │ false │ Output ANSI codes to change color.
3 │ ansi gradient │ platform │ false │ false │ draw text with a provided start and end code making a gradient
4 │ ansi strip │ platform │ false │ false │ strip ansi escape sequences from string
5 │ any? │ filters │ false │ false │ Tests if any element of the input matches a predicate.
6 │ append │ filters │ false │ false │ Append a row to the table.
7 │ benchmark │ system │ false │ false │ Time the running time of a block
8 │ build-string │ strings │ false │ false │ Create a string from the arguments.
9 │ cal │ generators │ false │ false │ Display a calendar.
───┴───────────────┴────────────┴───────────┴───────────┴────────────────────────────────────────────────────────────────
```

---

### Specific information on a command

To find more specific information on a command, use `help <COMMAND>`.

`help fetch`
```shell
> help fetch
```

Output

```
Load from a URL into a cell, convert to table if possible (avoid by appending '--raw')
Fetch the contents from a URL (HTTP GET operation).
Usage:
> fetch <path> {flags}
> fetch {flags} <URL>
parameters:
<path> the URL to fetch the contents from
Flags:
-h, --help
Display this help message
-u, --user <Any>
the username when authenticating
-p, --password <Any>
the password when authenticating
-t, --timeout <Int>
timeout period in seconds
-H, --headers <Any>
custom headers you want to add
-r, --raw
fetch contents as text rather than a table
flags:
--raw: fetch contents as text rather than a table
```
Parameters:
URL: the URL to fetch the contents from
Examples:
Fetch content from url.com
> fetch url.com
Fetch content from url.com, with username and password
> fetch -u myuser -p mypass url.com
Fetch content from url.com, with custom header
> fetch -H [my-header-key my-header-value] url.com
```

---

### Specific information on a command subcommand

To find more specific information on a command subcommand, use `help <COMMAND> <SUBCOMMAND>`.

`help str reverse`
```shell
> help str reverse
```

Output

```
outputs the reversals of the strings in the pipeline
Usage:
> str reverse ...args {flags}
Parameters:
...args: optionally reverse text by column paths
> str reverse ...(rest)
Flags:
-h, --help: Display this help message
-h, --help
Display this help message
Parameters:
...rest: optionally reverse text by column paths
Examples:
Return the reversals of multiple strings
> echo 'Nushell' | str reverse
```
> 'Nushell' | str reverse
```
Loading

0 comments on commit 99da58c

Please sign in to comment.