Home Explore Blog CI



nushell

2nd chunk of `cookbook/parsing_git_log.md`
aeb020ab51862f3911949e0251ef42097ef710ae73e32ed000000001000015bd
# => ───┼──────────┼──────────────────────┼──────────────────┼────────────────────────┼──────────────────
# =>  0 │ 42f1874a │ Update some examples │ Justin Ma        │ hustcer@outlook.com    │ Tue, 1 Mar 2022
# =>    │          │ and docs (#4682)     │                  │                        │ 21:05:29 +0800
# =>  1 │ 2a89936b │ Move to latest       │ Sophia           │ 547158+sophiajt@users. │ Tue, 1 Mar 2022
# =>    │          │ stable crossterm,    │                  │ noreply.github.com     │ 07:05:46 -0500
# =>    │          │ with fix (#4684)     │                  │                        │
# =>  2 │ ece5e7db │ dataframe list       │ Fernando Herrera │ fernando.j.herrera@g   │ Tue, 1 Mar 2022
# =>    │          │ command (#4681)      │                  │ mail.com               │ 11:41:13 +0000
# =>  3 │ a6a96b29 │ Add binary literals  │ Sophia           │ 547158+sophiajt@users. │ Mon, 28 Feb 2022
# =>    │          │ (#4680)              │                  │ noreply.github.com     │ 18:31:53 -0500
# =>  4 │ e3100e6a │ Fix alias in         │ Luca Trevisani   │ lucatrv@hotmail.com    │ Mon, 28 Feb 2022
# =>    │          │ `docs/sample_config/ │                  │                        │ 22:47:14 +0100
# =>    │          │ config.toml`         │                  │                        │
# =>    │          │ (#4669)              │                  │                        │
# => ───┴──────────┴──────────────────────┴──────────────────┴────────────────────────┴──────────────────
```

Yay, for columns! But wait, it would really be nice if those columns had something other than generically named column names.

Let's try adding the columns names to `split column` like this.

```nu
git log --pretty=%h»¦«%s»¦«%aN»¦«%aE»¦«%aD -n 5 | lines | split column "»¦«" commit subject name email date
# => ───┬──────────┬──────────────────────┬──────────────────┬────────────────────────┬──────────────────
# =>  # │  commit  │       subject        │       name       │        email           │       date
# => ───┼──────────┼──────────────────────┼──────────────────┼────────────────────────┼──────────────────
# =>  0 │ 42f1874a │ Update some examples │ Justin Ma        │ hustcer@outlook.com    │ Tue, 1 Mar 2022
# =>    │          │ and docs (#4682)     │                  │                        │ 21:05:29 +0800
# =>  1 │ 2a89936b │ Move to latest       │ Sophia           │ 547158+sophiajt@users. │ Tue, 1 Mar 2022
# =>    │          │ stable crossterm,    │                  │ noreply.github.com     │ 07:05:46 -0500
# =>    │          │ with fix (#4684)     │                  │                        │
# =>  2 │ ece5e7db │ dataframe list       │ Fernando Herrera │ fernando.j.herrera@g   │ Tue, 1 Mar 2022
# =>    │          │ command (#4681)      │                  │ mail.com               │ 11:41:13 +0000
# =>  3 │ a6a96b29 │ Add binary literals  │ Sophia           │ 547158+sophiajt@users. │ Mon, 28 Feb 2022
# =>    │          │ (#4680)              │                  │ noreply.github.com     │ 18:31:53 -0500
# =>  4 │ e3100e6a │ Fix alias in         │ Luca Trevisani   │ lucatrv@hotmail.com    │ Mon, 28 Feb 2022
# =>    │          │ `docs/sample_config/ │                  │                        │ 22:47:14 +0100
# =>    │          │ config.toml`         │                  │                        │
# =>    │          │ (#4669)              │                  │                        │
# => ───┴──────────┴──────────────────────┴──────────────────┴────────────────────────┴──────────────────
```

Ahhh, that looks much better.

Hmmm, that date string is a string. If it were a date vs a string it could be used for sorting by date. The way we do that is we have to convert the datetime to a real datetime and update the column. Try this.

```nu
git log --pretty=%h»¦«%s»¦«%aN»¦«%aE»¦«%aD -n 5 | lines | split column "»¦«" commit subject name email date | upsert date {|d| $d.date | into datetime}
# => ───┬──────────┬──────────────────────────┬──────────────────┬────────────────────────────┬──────────────

Title: Adding Column Names and Converting Date Format
Summary
This section improves the parsing of `git log` output by adding meaningful column names to the table created by `split column`. It then demonstrates how to convert the date string in the 'date' column into a datetime object using `upsert` and `into datetime`, allowing for date-based sorting and other datetime operations.