Rye's os context has a bunch of builtins related to your operationg system / computer. It's not complete but it's starting to offer a lot of utilities that you typically use inside your bash sessions. All with full Rye capabilities and also strictness / exactness around value types and state.
I had filenames like builtins_base_numbers.go in evaldo folder and wanted to rename them to builtins_numbers.go (like others are). The code above first looks at target names and then renames them.
mkdir then cd
One small but constant pattern in bash is, I create a directory and then I enter it - what else would I want to do 90% of time? :) Maybe there is some way I don't know about, but in bash I resort to shell history (up arrow), jump to the beginning of the line (ctrl-a), delete mkdir (alt-d) and type in cd. It works, but it's very indirects and annoying to my senses :)
In Rye, mkdir functions returns something, like every Rye function. It returns the directory it created (as file uri). And you can of course use a pipe word to invoke function cd on that directory to change into it.
mkdir %new_folder |cd
Or in repl session, if you use seprate lines to see it clearly.
find
find is another classic *ux tool we need constantly ... this is example session inside Rye console after cc-ing to os context. Since these are generic methods they fully work with tab-complete, so you can find / tab-to-them fully inline and don't have to remember all the methods.
×> finder %.
[Native of kind finder]
×> |Name "builtins*go"
[Native of kind finder]
×> |Mtime-since 2 .days
[Native of kind finder]
×> |Max-depth 3
[Native of kind finder]
×> |Eval
Which is equivalent to in your terminal:
$ find . -name "builitns*go" -mtime -2 -maxdepth 3
Which is shorter, but returns a text and Rye returns Rye values, in this case a block of filepaths that can then be passed to any other Rye function.
finder %. |Name "builtins*go" |Mtime-since 2 .days |Max-depth 3 |Eval :files
|zip file now .date? ++ ".zip"
; creates a zip file with name <current-date>.zip containing found files
Or another example using various Rye features, like map and tables
finder %. |Name "*.png" |Eval
|map { .file-info? } |to-table |display
; | is-dir | name | size | mode | mod-time |
; +-------------------------------------------------+
; | false | foo.png | 1077 | -rw-rw-r-- | 07 Sep...|
|columns? { 'name 'size 'mod-time }
|Save\xlsx* %gofiles.xlsx
; creates Excel file with files, sizes and modification times
---
cmd dialect I mentioned in one of previous posts also lives inside os context.
Enter os context with cc os (change context) and use lc (list context) to see all the functions there. Os context naming and function offering will get fine-tuned as time goes.
Visit discord to discuss this: https://discord.gg/J8FBrCSqve
And our github for updates: https://github.com/refaktor/rye
Rye function reference is getting incrementally improved also: https://ryelang.org/info/base.html