🐚
nushell お試し
wndows11 wezterm nu-0.83
Windows, Linux, OSX 兼用の Shell としていけるかやってみる。
WezTerm で変な改行が入る件
これで使えるようになった。やってく。
pipeline
powershell 感のある object パイプ。
わりと sql ぽい感じもする(where とか)。
内部コマンドと外部コマンドの区別があり、パイプの前後は
in | in, in | ex, ex | in, ex | ex の4種類があって
挙動が異なることを意識する。
型に注意
型を意識する必要がある。
同じ関数でも複数の型に対応しているものはポリモーフィックに動作している。
table(List<record>)recordList<record以外の型>- その他の型(string, int, datetime... etc)
コレクション型が3種類?あって table が pipeline 的にはいろいろできるのだけど、
List<datetime> と Table<datetime から作った record> が別物だったり
慣れが必要。
fzf を混ぜる
ls | where type == dir | get name | to text | fzf | str trim | cd $in
| command | out | ||
|---|---|---|---|
| 組み込み | ls | table | |
| 組み込み | where type == dir | ||
| 組み込み | get name | list<string> |
|
| 組み込み | to text | string | 外部コマンド(fzf)にわたす前に! |
| 外部 | fzf | string |
ghq で cd するやつ
def-env gg [] {
ghq list --full-path | fzf --preview $"bat --color=always --style=header,grid --line-range :80 {}/README.*" | decode utf-8 | str trim | cd $in
}
scoped-cd のせいで def-env が必要ぽい?
特殊変数
- $in pipeline の値にアクセスできる
- $it 同じ?詳細不明
custom command
関数に相当する。
-
[]が引数 - 最後に評価した値が return する
- 特に何もしなくても
$in変数がパイプ入力として使える様子 -
(func arg)もしくは($in | func)のようにコールする
型別操作メモ
table
List<record>。
record
json object ひとつが相当する。
items で key, value にアクセスできる。
如何に table型に持っていくかが肝っぽい。
例えば気象庁の area リストを以下のようにして table に変形できる。
let area = "https://www.jma.go.jp/bosai/common/const/area.json"
http get $jma.area | get centers | items {|k,v| {center:$k} | merge $v}
Discussion