Repository navigation
Description
Is your feature request related to a problem? Please describe.
Consider the following table:
> echo [[filestem extension basename]; [spam txt spam.txt]]
# filestem extension basename
---------------------------------
0 spam txt spam.txt
The basename column can be written as a combination of filename and extension:
> echo [[filestem extension]; [spam txt]] | insert basename {
echo [ $it.filestem $it.extension ] | str collect '.'
}
# filestem extension basename
---------------------------------
0 spam txt spam.txt
Now when we change the filestem:
> echo [[filestem extension]; [spam txt]] | insert basename {
echo [ $it.filestem $it.extension ] | str collect '.'
} | update filestem eggs
# filestem extension basename
---------------------------------
0 eggs txt spam.txt
, naturally, it updates only the filestem column. To propagate the change into the basename column, we would need to run the insert basename { ... } again to update the derived column. In this case, you could just update the filestem before insert but it could be problematic in more complex pipelines or if you have the table e.g. cached in a variable.
Describe the solution you'd like
My suggestions is to have "dependent columns" -- columns defined as operation on other columns. Modifying the table fields would update the dependent columns without manual intervention. The above example could be written like this:
> let fn = { echo [$it.filestem $it.extension] | str collect '.' }
> echo [ [ filestem extension basename = $fn ]; [spam txt]]
# filestem extension basename
---------------------------------
0 spam txt spam.txt
> echo [ [ filestem extension basename = $fn ]; [spam txt]] | update filestem eggs
# filestem extension basename
---------------------------------
0 eggs txt eggs.txt
So it's basically like a command-line Excel. Notice, I'm supplying values only for the first two columns. The dependent column would be fully automatic and writing to it would throw an error.
Describe alternatives you've considered
None :-D
Additional context
I came across this problem when thinking about the path commands revamp (#3219). It would allow to have duplicate fields in the path table, without worrying about updating basename after updating filename or extension. Apart from the basename example, for example, the column dirname could be constructed from a parts column, where parts column would contain the path pieces split by the a path separator.
Activity
github-actions commentedon Jun 24, 2021
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.
kubouch commentedon Jun 24, 2021
Is it is still a good idea? I think it would be cool.
sophiajt commentedon Jul 7, 2021
Yeah, it'd be cool. Would need some design, will go ahead and mark it.
github-actions commentedon Oct 6, 2021
This issue is being marked stale because it has been open for 90 days without activity. If you feel that this is in error, please comment below and we will keep it marked as active.
github-actions commentedon Oct 16, 2021
This issue has been marked stale for more than 10 days without activity. Closing this issue, but if you find that the issue is still valid, please reopen.