insert
really is, I believe, what you are looking for, despite the confusing example in the book.
Try:
ls -af **/* | insert path { $in.name | path dirname } | update name { $in.name | path basename }
That inserts a new path
column and updates (rather than drops) the existing name
column to just show the name.
You can clean it up a bit and make it easier to call by putting it in a function:
def split-ls [] {
insert path { $in.name | path dirname } |
update name { $in.name | path basename }
}
Then invoke with:
ls -af **/* | split-ls
If you really want two new columns and to remove the existing name:
ls -af **/* | insert path { $in.name | path dirname } | insert base { $in.name | path basename } | move path --before name | move base --before path | reject name
Or, as above:
def split-ls [ --help (-h) ] {
insert path { $in.name | path dirname } |
insert base { $in.name | path basename } |
move path --before name |
move base --before path |
reject name
}
ls -af **/* | split-ls