WIP on cli renassance.

This commit is contained in:
Gabe Venberg 2024-03-14 13:03:31 -05:00
parent 7912b0fd37
commit 11424579e4
2 changed files with 173 additions and 70 deletions

View file

@ -3,24 +3,24 @@ title = "Nushell first impressions"
date = 2024-03-01T11:34:04-06:00
+++
Ive been trying out a bunch of new shell utilities lately,
switching up my shell, terminal multiplexer, and even experimenting with my editor.
Today, Id like to focus on my experiments with my shell.
Ive been experimenting with the tools I use on a regular basis lately -- switching
up my shell, terminal multiplexer, and even trying out other editors. Today,
Id like to focus on my experiments with my shell.
## My old setup
Before this, I had been using a minimal zsh setup for a long time,
with only built in features and a handmade prompt.
Zsh is a good shell, probably one of the best posix shells out there,
and I still use it when a posix shell is needed.
Zsh is a good shell, probably one of the best POSIX shells out there,
and I still use it when a POSIX shell is needed.
However, I got tired of the endless footguns that posix shell scripting imposes,
However, I got tired of the endless footguns that POSIX shell scripting imposes,
easy to make errors around quoting, word splitting, and escaping,
the sort of thing that makes [shellcheck](https://www.shellcheck.net/) necessary.
I played around with fish for a few days,
but it had many of the same fundamental design choices, mainly, being 'stringly typed',
that made posix shells such a displeasure to work with.
that made POSIX shells such a displeasure to work with.
## A Nu shell
@ -95,7 +95,7 @@ explanatory comments.
## Parsing non-nu tools
But what if our tool/text file isnt in a format nushell understands?
Thankfully, for most formats, parsing is relatively straightforward.
Thankfully, for most formats parsing is relatively straightforward.
Lets take this NGINX server log, for example (not a log of real traffic, just a
sample log I found)
@ -108,8 +108,7 @@ sample log I found)
{{</highlight>}}
We can parse it into a nu table like so (each line has a comment explaining what
it does, for those unfamiliar with the nushell language):
We can parse it into a nu table like so:
{{<highlight sh>}}
open access.log |
@ -122,9 +121,10 @@ update time {into datetime -f '%d/%b/%Y:%T %z'} |
# parse into proper integer
update bytes_sent {into int}
{{</highlight>}}
(each line has a comment explaining what it does, for those unfamiliar with the nushell language)
Now that we have it in nushell tables, we can bring all of nushells tools to
bear on the data. We could, for example, plot a histogram of the most common
bear on the data. For example, we could plot a histogram of the most common
ips, just by piping the whole thing into `histogram ip`. We could easily
calculate the average bytes sent per request. We could group the records by the
day or hour they happened, and analyze each of those groups independently. And
@ -135,7 +135,7 @@ While it would be a pretty long one liner if we decided to put it in a single
line, its still quite easy and straightforward to write.
Most log formats and command outputs are similarly straightforward.
## Defining custom commands, with built in arg parsing
## Defining custom commands, with built-in arg parsing
Nushell has a feature called Custom Commands, which fill the same purpose as
functions in other shells/programming languages, but are a bit more featurefull
@ -278,7 +278,7 @@ echo "$i / 1000" | bc
done
{{</highlight>}}
This gets the sizes of all the files in kib. But what if we typo something?
This gets the sizes of all the files in KiB. But what if we typo something?
{{<highlight sh "linenos=false">}}
$ for i in $(ls -l | tr -s " " | cut --fields=6 --delimiter=" "); do
@ -367,8 +367,9 @@ to make 'scripts' that are integrated with the rest of nushell.
## So, overall, is it worth it?
Nushell is certainly an interesting project, and I will almost certainly be
Nushell is certainly an promising project, and I will almost certainly be
continuing to use it as my daily shell. It cant do everything, but dropping into
zsh for a task or two every once in a while isnt that big a deal for me, and
having access to such a powerful shell by default has made other tasks much
easier for me.
easier for me. If you regularly use pipelines in your default shell, consider
giving Nushell a try.