From b40ead9ae2e77e3460e2b07f308401759a20a557 Mon Sep 17 00:00:00 2001 From: Igor Date: Mon, 13 May 2024 16:53:40 +0400 Subject: [PATCH] Port `before_v0.60/cool_oneliners` folder (#831) This PR is part of porting all old scripts #221 and ports `cool_oneliners` folder ## Summary ### dict.nu This script has already been ported to `sourced/cool_oneliners/dict.nu` in 28c7e097dbc79c51fce577f61312b495487b7670 ```yaml from: before_v0.60/cool_oneliners/dict.nu to: sourced/cool-oneliners/dict.nu functions: dict: sourced/cool-oneliners/dict.nu:2:dict ``` ### file_cat.nu has already been ported to `sourced/cool_oneliners/file_cat.nu` in c47ccd42b808f71dfc6ed2b4b5ebc20f5fa2d26e ```yaml from: before_v0.60/cool_oneliners/file_cat.nu to: sourced/cool-oneliners/file_cat.nu ``` ### filesize.nu ```yaml from: before_v0.60/cool_oneliners/filesize.nu to: sourced/cool-oneliners/filesize.nu ``` ### js_map_to_markdown.nu ```yaml from: before_v0.60/cool_oneliners/js_map_to_markdown.nu to: sourced/cool-oneliners/js_map_to_markdown.nu ``` I created `sourced/cool-oneliners/assets/js_map.json` with the data for this script as it was before ### cdpath-implementation.nu ```yaml from: before_v0.60/cool_oneliners/cdpath-implementation.nu to: sourced/cool-oneliners/cdpath-implementation.nu functions: c: sourced/cool-oneliners/cdpath-implementation.nu:18:c ``` ### parse_aws_s3_ls.nu I don't have aws so I just ported the syntax ```yaml from: before_v0.60/cool_oneliners/parse_aws_s3_ls.nu to: null ``` Edit: I considered not porting this script yet because I can't test it for now ### npm_update_versions.nu ```yaml from: before_v0.60/cool_oneliners/npm_update_versions.nu to: sourced/cool-oneliners/npm_update_versions.nu ``` ### xml_search_schema.nu ```yaml from: before_v0.60/cool_oneliners/xml_search_schema.nu to: sourced/cool-oneliners/xml_search_schema.nu ``` --- before_v0.60/cool_oneliners/README.md | 19 -------- .../cool_oneliners/cdpath-implementation.nu | 23 --------- before_v0.60/cool_oneliners/dict.nu | 14 ------ before_v0.60/cool_oneliners/file_cat.nu | 3 -- before_v0.60/cool_oneliners/filesize.nu | 2 - .../cool_oneliners/js_map_to_markdown.nu | 2 - .../cool_oneliners/npm_update_versions.nu | 2 - sourced/cool-oneliners/assets/js_map.json | 6 +++ .../cool-oneliners/cdpath-implementation.nu | 48 +++++++++++++++++++ sourced/cool-oneliners/filesize.nu | 2 + sourced/cool-oneliners/js_map_to_markdown.nu | 2 + sourced/cool-oneliners/npm_update_versions.nu | 2 + .../cool-oneliners}/xml_search_schema.nu | 2 +- 13 files changed, 61 insertions(+), 66 deletions(-) delete mode 100644 before_v0.60/cool_oneliners/README.md delete mode 100644 before_v0.60/cool_oneliners/cdpath-implementation.nu delete mode 100644 before_v0.60/cool_oneliners/dict.nu delete mode 100644 before_v0.60/cool_oneliners/file_cat.nu delete mode 100644 before_v0.60/cool_oneliners/filesize.nu delete mode 100644 before_v0.60/cool_oneliners/js_map_to_markdown.nu delete mode 100644 before_v0.60/cool_oneliners/npm_update_versions.nu create mode 100644 sourced/cool-oneliners/assets/js_map.json create mode 100644 sourced/cool-oneliners/cdpath-implementation.nu create mode 100644 sourced/cool-oneliners/filesize.nu create mode 100644 sourced/cool-oneliners/js_map_to_markdown.nu create mode 100644 sourced/cool-oneliners/npm_update_versions.nu rename {before_v0.60/cool_oneliners => sourced/cool-oneliners}/xml_search_schema.nu (70%) diff --git a/before_v0.60/cool_oneliners/README.md b/before_v0.60/cool_oneliners/README.md deleted file mode 100644 index 5bb77e6..0000000 --- a/before_v0.60/cool_oneliners/README.md +++ /dev/null @@ -1,19 +0,0 @@ -# cool oneliners - -Capturing oneliners to and from the nushell Discourse channel `#cool-oneliners`. - -Consider these a living library. -Or an ongoing story of how people actually use `nu`. - -## Naming and script requirements - -- the filename should be an abbreviation of the general topic of the script - For example: - - ```sh - git_batch_extract.nu - ``` - -- the script should have two lines - - the first line should be a comment describing the script's purpose - - the second line should be the cool oneliner diff --git a/before_v0.60/cool_oneliners/cdpath-implementation.nu b/before_v0.60/cool_oneliners/cdpath-implementation.nu deleted file mode 100644 index c1b88db..0000000 --- a/before_v0.60/cool_oneliners/cdpath-implementation.nu +++ /dev/null @@ -1,23 +0,0 @@ -#!/usr/bin/nu - -# I actually use it as a part of my startup, so I am not really sure how to pack it, yet I wouldd like to contribute -#------------------------------------------------------------------------------------------------------------------------------- -# -# How to use? -#------------------------------------------------- -#1) Add desired paths to the cdpath variable -#2) Use in your shell: $c [directory] -#2.5) You *have to* use an argument. If you wish to simply $cd, use $cd command. -#3) If the path exists, you will cd into the first match found (the command is iterating over the list in the correct order, -# i.e. first element is being iterated overin the first place) -#3.5) But if path does not exist, you will receive a proper echo. -#----------------------------------------------------------------------------------------------------------------------------------- -# -#Written by skelly37 -#------------------------ - - -startup = [ - "let cdpath = [. /place/your ~/cdpath/here ]", - "def c [dir] { let wd = (pwd); for element in $cdpath {if (pwd) == $wd {cd $element; for directory in (ls -a | select name type | each { if $it.type == Dir {echo $it.name} {} } ) {if $dir == $directory {cd $dir} {}}; if (pwd) == $element {cd $wd} {}} {}}; if (pwd) == $wd {cd $wd; echo \"No such path!\"} {}}", -] diff --git a/before_v0.60/cool_oneliners/dict.nu b/before_v0.60/cool_oneliners/dict.nu deleted file mode 100644 index 3678ffd..0000000 --- a/before_v0.60/cool_oneliners/dict.nu +++ /dev/null @@ -1,14 +0,0 @@ -# Function querying free online English dictionary API for definition of given word(s) -def dict [...word #word(s) to query the dictionary API but they have to make sense together like "martial law", not "cats dogs" -] { - let query = ($word | str collect %20) - let link = (build-string 'https://api.dictionaryapi.dev/api/v2/entries/en/' ($query|str find-replace ' ' '%20')) - let output = (fetch $link | - rename word) - let w = ($output.word | first) - - if $w == "No Definitions Found" {echo $output.word} {echo $output | - get meanings.definitions | - select definition example - } -} diff --git a/before_v0.60/cool_oneliners/file_cat.nu b/before_v0.60/cool_oneliners/file_cat.nu deleted file mode 100644 index d120e24..0000000 --- a/before_v0.60/cool_oneliners/file_cat.nu +++ /dev/null @@ -1,3 +0,0 @@ -# Combine two files into one -# You can generate `a.json` with something like `range 1..5 | save a.json` -echo (open a.json) (open b.json) | save c.json diff --git a/before_v0.60/cool_oneliners/filesize.nu b/before_v0.60/cool_oneliners/filesize.nu deleted file mode 100644 index 4655215..0000000 --- a/before_v0.60/cool_oneliners/filesize.nu +++ /dev/null @@ -1,2 +0,0 @@ -## show directory sizes in current directory starting from the largest -ls -d|where type == Dir|sort-by size|reverse|format filesize apparent GB diff --git a/before_v0.60/cool_oneliners/js_map_to_markdown.nu b/before_v0.60/cool_oneliners/js_map_to_markdown.nu deleted file mode 100644 index 5020f10..0000000 --- a/before_v0.60/cool_oneliners/js_map_to_markdown.nu +++ /dev/null @@ -1,2 +0,0 @@ -# Ingest JavaScript Map JSON into nu then to markdown -open ../assets/js_map.json | each { echo [[Español English]; [ $it.0 $it.1]] } | to md diff --git a/before_v0.60/cool_oneliners/npm_update_versions.nu b/before_v0.60/cool_oneliners/npm_update_versions.nu deleted file mode 100644 index 9b48655..0000000 --- a/before_v0.60/cool_oneliners/npm_update_versions.nu +++ /dev/null @@ -1,2 +0,0 @@ -# Increment the minor version for any package.json in the current directory (eigenrick — 08/16/2020) -ls */package.json | each { open $it.name | inc version --minor | to json --pretty 2 | save --raw } diff --git a/sourced/cool-oneliners/assets/js_map.json b/sourced/cool-oneliners/assets/js_map.json new file mode 100644 index 0000000..49cd833 --- /dev/null +++ b/sourced/cool-oneliners/assets/js_map.json @@ -0,0 +1,6 @@ +[ + ["cero", "zero"], + ["uno", "one"], + ["dos", "two"], + ["tres", "three"] +] diff --git a/sourced/cool-oneliners/cdpath-implementation.nu b/sourced/cool-oneliners/cdpath-implementation.nu new file mode 100644 index 0000000..9cb2949 --- /dev/null +++ b/sourced/cool-oneliners/cdpath-implementation.nu @@ -0,0 +1,48 @@ +#!/usr/bin/nu + +# I actually use it as a part of my startup, so I am not really sure how to pack it, yet I wouldd like to contribute +#------------------------------------------------------------------------------------------------------------------------------- +# +# How to use? +#------------------------------------------------- +#1) Add desired paths to the cdpath variable +#2) Use in your shell: $c [directory] +#2.5) You *have to* use an argument. If you wish to simply $cd, use $cd command. +#3) If the path exists, you will cd into the first match found (the command is iterating over the list in the correct order, +# i.e. first element is being iterated overin the first place) +#3.5) But if path does not exist, you will receive a proper echo. +#----------------------------------------------------------------------------------------------------------------------------------- +# +#Written by skelly37 +#------------------------ + +# startup = [ +# "let cdpath = [. /place/your ~/cdpath/here ]", +# "def c [dir] { let wd = (pwd); for element in $cdpath {if (pwd) == $wd {cd $element; for directory in (ls -a | select name type | each { if $it.type == Dir {echo $it.name} {} } ) {if $dir == $directory {cd $dir} {}}; if (pwd) == $element {cd $wd} {}} {}}; if (pwd) == $wd {cd $wd; echo \"No such path!\"} {}}", +# ] +# + +export def --env c [dir] { + let CD_PATH = [. ($env.NU_PLUGIN_DIRS | get 0) $nu.default-config-dir ] + let wd = (pwd); + for element in $CD_PATH { + let element = ($element | path expand) + if (pwd) == $wd { + cd $element; + for directory in (ls -a | where type == dir | get name) { + if $dir == $directory { + cd $dir + break + } + }; + if (pwd) == $element { + cd $wd + } + } + }; + if (pwd) == $wd { + cd $wd + print "No such path!" + } +} + diff --git a/sourced/cool-oneliners/filesize.nu b/sourced/cool-oneliners/filesize.nu new file mode 100644 index 0000000..261cc6a --- /dev/null +++ b/sourced/cool-oneliners/filesize.nu @@ -0,0 +1,2 @@ +## show directory sizes in current directory starting from the largest +ls -d|where type == dir|sort-by size|reverse|format filesize GB size diff --git a/sourced/cool-oneliners/js_map_to_markdown.nu b/sourced/cool-oneliners/js_map_to_markdown.nu new file mode 100644 index 0000000..0190a1e --- /dev/null +++ b/sourced/cool-oneliners/js_map_to_markdown.nu @@ -0,0 +1,2 @@ +# Ingest JavaScript Map JSON into nu then to markdown +open assets/js_map.json | each { echo [[Español English]; [ $in.0 $in.1]] } | flatten | to md diff --git a/sourced/cool-oneliners/npm_update_versions.nu b/sourced/cool-oneliners/npm_update_versions.nu new file mode 100644 index 0000000..a549697 --- /dev/null +++ b/sourced/cool-oneliners/npm_update_versions.nu @@ -0,0 +1,2 @@ +# Increment the minor version for any package.json in the current directory with `nu_plugin_inc` (eigenrick — 08/16/2020) +ls -f */package.json | each {|it| open $it.name | inc version --minor | to json --indent 2 | save --raw --force $it.name } diff --git a/before_v0.60/cool_oneliners/xml_search_schema.nu b/sourced/cool-oneliners/xml_search_schema.nu similarity index 70% rename from before_v0.60/cool_oneliners/xml_search_schema.nu rename to sourced/cool-oneliners/xml_search_schema.nu index 65e607e..142e973 100644 --- a/before_v0.60/cool_oneliners/xml_search_schema.nu +++ b/sourced/cool-oneliners/xml_search_schema.nu @@ -3,4 +3,4 @@ # To get that file, first download the following zip: # https://www.ecma-international.org/wp-content/uploads/ECMA-376-Fifth-Edition-Part-1-Fundamentals-And-Markup-Language-Reference.zip # Then, unzip the contents of OfficeOpenXML-XMLSchema-Strict.zip. -open wml.xsd | from xml | get schema.children.simpleType | flatten | where name =~ 'BrType' | get children.restriction.children.enumeration.attributes +open wml.xsd | from xml | get content | where tag == simpleType | flatten | where name =~ BrType | get content.content.0.attributes