From 669320ef99ccf5fb7e6f719712b08147c7002799 Mon Sep 17 00:00:00 2001 From: Igor Date: Sun, 12 May 2024 23:28:38 +0400 Subject: [PATCH 1/7] remove `bin-utils.nu` `into bits` `into int` already in the core --- before_v0.60/bin-utils.nu | 77 --------------------------------------- 1 file changed, 77 deletions(-) delete mode 100644 before_v0.60/bin-utils.nu diff --git a/before_v0.60/bin-utils.nu b/before_v0.60/bin-utils.nu deleted file mode 100644 index ae866fae1..000000000 --- a/before_v0.60/bin-utils.nu +++ /dev/null @@ -1,77 +0,0 @@ -# bin-utils.nu -def "get bits" [x: int, bits] { - if $x == 0 { - $bits - } else { - let new-x = ($x / 2 | into int) - let bit = if $new-x == ($x / 2 | math ceil | into int) { - 0 - } else { - 1 - } - - get bits $new-x ($bits | append $bit) - } -} - -def "get bits2" [x: int] { - let inp = $in - - if $x != 0 { - let new-x = ($x / 2 | into int) - let bit = if $new-x == ($x / 2 | math ceil | into int) { - 0 - } else { - 1 - } - - $inp | append $bit | get bits2 $new-x - } else { - $inp - } -} - -export def "into bits" [] { - let inp = $in - let span = (metadata $inp).span - let type = ($inp | describe) - - if "list" in $type { - $inp | each { - $it | into bits - } - } else if "int" in $type { - [] | get bits2 $inp - } else { - error make { - msg: "Cannot convert to bits", - label: { - text: "This value cannot be converted to bits" - start: $span.start - end: $span.end - } - } - } -} - -export def "bits into int" [] { - reverse | reduce -f 0 { 2 * $it.acc + $it.item } -} - -export def "test bits" [] { - 0..4 | each { - let bits = ($it | into bits) - let res = ($bits | bits into int) - let span = (metadata $res).span - if $it == 1 { - error make { - msg: "Test mismatch", - label: { - text: $"Expected: ($it), bits: ($bits | str collect ''), result: ($res)" - start: $span.start - end: $span.end - } - } - } - } | compact -} \ No newline at end of file From 30a576ea5ef7414f99d9af7622d1bd547d95eeae Mon Sep 17 00:00:00 2001 From: Igor Date: Sun, 12 May 2024 23:30:35 +0400 Subject: [PATCH 2/7] remove `fehbg.nu` This script is already ported to `sourced/fehbg.nu` --- before_v0.60/fehbg.nu | 64 ------------------------------------------- 1 file changed, 64 deletions(-) delete mode 100644 before_v0.60/fehbg.nu diff --git a/before_v0.60/fehbg.nu b/before_v0.60/fehbg.nu deleted file mode 100644 index 5d7ee2a7b..000000000 --- a/before_v0.60/fehbg.nu +++ /dev/null @@ -1,64 +0,0 @@ -#!/usr/bin/env nu -# -# ~/.fehbg.nu -# -# This script selects a random image from a directory and sets it as a -# wallpaper. An additional feature is that it draws the path of the image in -# the lower left corner which makes it easier to find the image later. -# -# The procedure is as follows:: -# * Select a random image from a directory (recursively entering all -# subdirectories) -# * Print the path of the image as an overlay on top of the selected image -# * Save the result in a temporary file -# * Set the temporary image as a wallpaper. -# -# !! Requires `WALLPAPER_DIR` and `TMP_DIR` environment variables to be set !! -# (or just hardcode your own paths below) -# -# You can set this script to run on desktop startup, e.g., by adding it to -# xinitrc. -# -# Dependencies; -# * nu version >=0.32.0 (tested on 0.36.0) -# * feh -# * imagemagick - -# Path definitions -let img_dir = $nu.env.WALLPAPER_DIR -let tmp_image = (echo [ $nu.env.TMP_DIR "wallpaper.jpg" ] | path join) - -# Monitor resolution -let resolution_y = 1440 - -# Position of the caption -let pos_x = 5 -let pos_y = 0.995 * $resolution_y - -# Helper commands -def select_random [] { shuffle | first } - -# List all images in a directory and all its subdirectories -def list_images [dir] { - ls (build-string $dir /**/*) | where type == File | where name =~ jpg or name =~ jpeg or name =~ tif or name =~ tiff -} - -# Set the caption text (just filename for now) -def caption [img_f] { - echo $img_f -} - -# Build the argument for the '-draw' command of the 'convert' utility -def draw_str [img_f] { - build-string 'text ' $pos_x ',' $pos_y ' "' (caption $img_f) '" ' -} - -# Select random image -let img_name = (list_images $img_dir | select_random | get name) - -# Resize the image to the monitor height, draw the caption and save it -let res_str = (build-string 'x' $resolution_y) -convert -resize $res_str -pointsize 15 -fill 'rgb(255,200,150)' -draw (draw_str $img_name) $img_name $tmp_image - -# Set the created image as a background -feh --no-fehbg --bg-max $tmp_image From a1322a4076db6632a6dbf26da007996a2d966eb9 Mon Sep 17 00:00:00 2001 From: Igor Date: Sun, 12 May 2024 23:35:10 +0400 Subject: [PATCH 3/7] move root `before_v0.60` scripts --- {before_v0.60 => modules}/lint_directories.nu | 0 {before_v0.60 => modules}/maintainer_time.nu | 0 {before_v0.60 => modules}/make_readme_table.nu | 0 3 files changed, 0 insertions(+), 0 deletions(-) rename {before_v0.60 => modules}/lint_directories.nu (100%) rename {before_v0.60 => modules}/maintainer_time.nu (100%) rename {before_v0.60 => modules}/make_readme_table.nu (100%) diff --git a/before_v0.60/lint_directories.nu b/modules/lint_directories.nu similarity index 100% rename from before_v0.60/lint_directories.nu rename to modules/lint_directories.nu diff --git a/before_v0.60/maintainer_time.nu b/modules/maintainer_time.nu similarity index 100% rename from before_v0.60/maintainer_time.nu rename to modules/maintainer_time.nu diff --git a/before_v0.60/make_readme_table.nu b/modules/make_readme_table.nu similarity index 100% rename from before_v0.60/make_readme_table.nu rename to modules/make_readme_table.nu From c57acfa91c4aae065c17c694428634e9b90627a0 Mon Sep 17 00:00:00 2001 From: Igor Date: Sun, 12 May 2024 23:42:14 +0400 Subject: [PATCH 4/7] port `lint_directories.nu` --- modules/lint_directories.nu | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/modules/lint_directories.nu b/modules/lint_directories.nu index 112e6cb6b..86cd0a8e0 100644 --- a/modules/lint_directories.nu +++ b/modules/lint_directories.nu @@ -3,14 +3,14 @@ # - 1.0.1 is a valid directory name. # - yeah_whatever_linter is not a valid directory name. def ls-incorrect-dirs [] { - ls | where type == 'Dir' and name != 'scripts'| match -v name '(\d+\.){2,}\d$' + ls | where type == dir and name != 'scripts' | find --invert --regex '(\d+\.){2,}\d$' --columns [name] } let incorrect_count = (ls-incorrect-dirs | length); if $incorrect_count > 0 { -# echo `The following directories are named incorrectly: {{(char newline)}}` - $"The following directories are named incorrectly: (char newline)" - ls-incorrect-dirs - exit 1 -} { - exit 0 + print $"The following directories are named incorrectly: (char newline)" + print (ls-incorrect-dirs) + exit 1 + +} else { + exit 0 } From a37c0fe41a4060c1d268ee8ebe086d0c4f4f7521 Mon Sep 17 00:00:00 2001 From: Igor Date: Sun, 12 May 2024 23:46:49 +0400 Subject: [PATCH 5/7] port `maintainer_time.nu` just `update {|row| ...}` --- modules/maintainer_time.nu | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/modules/maintainer_time.nu b/modules/maintainer_time.nu index e7daa6f1f..5a8dcaab3 100644 --- a/modules/maintainer_time.nu +++ b/modules/maintainer_time.nu @@ -12,9 +12,7 @@ let m_table = ( ] ) let now = (date now) -$m_table | update time { - each { |name| - $now | date to-timezone ($name | get tz) | date format '%c' - } +$m_table | update time {|row| + $now | date to-timezone ($row | get tz) | format date '%c' } From 46b468f27cd2cf14592c4c2aff2930420744db39 Mon Sep 17 00:00:00 2001 From: Igor Date: Sun, 12 May 2024 23:49:27 +0400 Subject: [PATCH 6/7] port `make_readme_table.nu` - `if {} {}` -> `if {} else {}` - `str find-replace` -> `str replace` --- modules/make_readme_table.nu | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/make_readme_table.nu b/modules/make_readme_table.nu index 8f713bc32..130a00b30 100644 --- a/modules/make_readme_table.nu +++ b/modules/make_readme_table.nu @@ -17,14 +17,14 @@ let nu_table = ($nu_files | let cat = ($it.File | path dirname) if $cat == "" { "not assigned yet" - } { + } else { $cat } } | where Category !~ ".git" | select Category File | sort-by Category) # Let's fix the file now let nu_table = ($nu_table | update File { |it| - let file_path = ($it.File | into string | str find-replace '\\' '/') + let file_path = ($it.File | into string | str replace '\\' '/') let file_name = ($file_path | path basename) $"[($file_name)](char lparen)./($file_path)(char rparen)" }) From 9dd0319a731ed007e548d0b17b88a7a6af5eb745 Mon Sep 17 00:00:00 2001 From: Igor Date: Mon, 13 May 2024 17:11:48 +0400 Subject: [PATCH 7/7] fix: `make_readme_table.nu` - add `--all` to replace all occcurencies - `\\` -> '\'. No need to escape backslash in single qoutes --- modules/make_readme_table.nu | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/make_readme_table.nu b/modules/make_readme_table.nu index 130a00b30..ac0fbee0c 100644 --- a/modules/make_readme_table.nu +++ b/modules/make_readme_table.nu @@ -24,7 +24,7 @@ let nu_table = ($nu_files | # Let's fix the file now let nu_table = ($nu_table | update File { |it| - let file_path = ($it.File | into string | str replace '\\' '/') + let file_path = ($it.File | into string | str replace '\' '/' --all) let file_name = ($file_path | path basename) $"[($file_name)](char lparen)./($file_path)(char rparen)" })