From 203727b2917b1c15cfaf5c032b1ec8baa71458b6 Mon Sep 17 00:00:00 2001 From: Stefan Holderbach Date: Mon, 5 Sep 2022 16:43:01 +0200 Subject: [PATCH] Update old question mark commands `any?`/`all?`/`empty?` to `any`/`all`/`is-empty` (#287) * Replace `all?` with `all` for nushell/nushell#6464 * Replace `any?` with `any` for nushell/nushell#6464 * Replace `emtpy?` with `is-empty` Account for nushell/nushell#6464 * Ignore for `before_v0.60` scripts --- .../auto-generate/parse-help.nu | 4 +-- custom-completions/scoop/scoop-completions.nu | 8 ++--- data_extraction/ultimate_extractor.nu | 2 +- gitlab/gitlab.nu | 2 +- helpers/update_hosts.nu | 2 +- make_release/this_week_in_nu_weekly.nu | 6 ++-- maths/math_functions.nu | 6 ++-- miscelaneous/nu_defs.nu | 36 +++++++++---------- prompt/panache-git.nu | 14 ++++---- rbenv/rbenv.nu | 2 +- virtual_environments/conda.nu | 2 +- 11 files changed, 42 insertions(+), 42 deletions(-) diff --git a/custom-completions/auto-generate/parse-help.nu b/custom-completions/auto-generate/parse-help.nu index cd8e6d8..053459f 100644 --- a/custom-completions/auto-generate/parse-help.nu +++ b/custom-completions/auto-generate/parse-help.nu @@ -9,9 +9,9 @@ def parse-help [] { # takes a table of parsed help commands in format [short? long format? description] def make-completion [command_name: string] { build-string "extern \"" $command_name "\" [\n" ($in | each { |it| - build-string "\t--" $it.long (if ($it.short | empty?) == false { + build-string "\t--" $it.long (if ($it.short | is-empty) == false { build-string "(-" $it.short ")" - }) (if ($it.description | empty?) == false { + }) (if ($it.description | is-empty) == false { build-string "\t\t# " $it.description }) } | str collect "\n") "\n\t...args\n]" diff --git a/custom-completions/scoop/scoop-completions.nu b/custom-completions/scoop/scoop-completions.nu index 8696b1e..095d829 100644 --- a/custom-completions/scoop/scoop-completions.nu +++ b/custom-completions/scoop/scoop-completions.nu @@ -14,10 +14,10 @@ def scoopInstalledApps [] { # unoptimized tooks a long time # ^scoop list | lines | skip 2 | drop 1 | each { |line| $line | str trim | str replace ' .*' '' } - let localAppDir = if (env | any? $it.name == 'SCOOP') { $"($env.SCOOP)\\apps" } else { $"($env.USERPROFILE)\\scoop\\apps" } + let localAppDir = if (env | any $it.name == 'SCOOP') { $"($env.SCOOP)\\apps" } else { $"($env.USERPROFILE)\\scoop\\apps" } let localApps = (ls $localAppDir | get name | path basename) - let globalAppDir = if (env | any? $it.name == 'SCOOP_GLOBAL') { "$env.SCOOP_GLOBAL\\apps" } else { $"($env.ProgramData)\\scoop\\apps" } + let globalAppDir = if (env | any $it.name == 'SCOOP_GLOBAL') { "$env.SCOOP_GLOBAL\\apps" } else { $"($env.ProgramData)\\scoop\\apps" } let globalApps = if ($globalAppDir | path exists) { ls $globalAppDir | get name | path basename } $localApps | append $globalApps @@ -30,7 +30,7 @@ def scoopInstalledAppsWithStar [] { # list of all manifests from all buckets def scoopAllApps [] { - let bucketsDir = if (env | any? $it.name == 'SCOOP') { $"($env.SCOOP)\\buckets" } else { $"($env.USERPROFILE)\\scoop\\buckets" } + let bucketsDir = if (env | any $it.name == 'SCOOP') { $"($env.SCOOP)\\buckets" } else { $"($env.USERPROFILE)\\scoop\\buckets" } for bucket in (ls -s $bucketsDir | get name) { ls ([$bucketsDir, $bucket, 'bucket', '*.json'] | str collect '\') | get name | path basename | str substring ',-5' } | flatten | uniq } @@ -517,7 +517,7 @@ def scoopKnownBuckets [] { } def scoopInstalledBuckets [] { - let bucketsDir = if (env | any? $it.name == 'SCOOP') { $"($env.SCOOP)\\buckets" } else { $"($env.USERPROFILE)\\scoop\\buckets" } + let bucketsDir = if (env | any $it.name == 'SCOOP') { $"($env.SCOOP)\\buckets" } else { $"($env.USERPROFILE)\\scoop\\buckets" } let buckets = (ls $bucketsDir | get name | path basename) $buckets } diff --git a/data_extraction/ultimate_extractor.nu b/data_extraction/ultimate_extractor.nu index e5ee722..4a36edb 100644 --- a/data_extraction/ultimate_extractor.nu +++ b/data_extraction/ultimate_extractor.nu @@ -19,7 +19,7 @@ def extract [name:string #name of the archive to extract ] let command = ($exten|where $name =~ $it.ex|first) - if ($command|empty?) { + if ($command|is-empty) { echo 'Error! Unsupported file extension' } else { nu -c (build-string $command.com ' ' $name) diff --git a/gitlab/gitlab.nu b/gitlab/gitlab.nu index 13967f4..61a3d2b 100755 --- a/gitlab/gitlab.nu +++ b/gitlab/gitlab.nu @@ -24,7 +24,7 @@ def main [ |flatten |par-each {|repo| let payload = (call-gitlab $repo.id '/repository/files/' $file --query $"ref=($branch)") - if ($payload|columns|find message|empty?) { + if ($payload|columns|find message|is-empty) { $payload |get content |hash base64 --decode diff --git a/helpers/update_hosts.nu b/helpers/update_hosts.nu index e0dd01a..a3818b8 100644 --- a/helpers/update_hosts.nu +++ b/helpers/update_hosts.nu @@ -37,7 +37,7 @@ module hosts { echo "Do you want to update the /etc/hosts file? [Y/n]" let choice = (input) if $choice in ["" "Y" "y"] { - let TMP_FILE = if ($WHITELIST|empty?) { + let TMP_FILE = if ($WHITELIST|is-empty) { ($TMP_FILE) } else { ($TMP_FILE | where {|line| $line !~ $pattern}) diff --git a/make_release/this_week_in_nu_weekly.nu b/make_release/this_week_in_nu_weekly.nu index 6f2f161..f579a15 100644 --- a/make_release/this_week_in_nu_weekly.nu +++ b/make_release/this_week_in_nu_weekly.nu @@ -33,7 +33,7 @@ def do-work [] { let site_json = (fetch -u $env.GITHUB_USERNAME -p $env.GITHUB_PASSWORD $query_string | get items | select html_url user.login title) $"## ($row.site)(char nl)(char nl)" - if ($site_json | all? ($it | empty?)) { + if ($site_json | all ($it | is-empty)) { $"none found this week(char nl)(char nl)" } else { $site_json | group-by user_login | transpose user prs | each { |row| @@ -55,7 +55,7 @@ def do-work [] { } }) - if ($entries | all? ($it | empty?)) { + if ($entries | all ($it | is-empty)) { # do nothing } else { $entries | str collect @@ -66,7 +66,7 @@ def do-work [] { let week_num = ((seq date -b '2019-08-23' -n 7 | length) - 1) $"# This week in Nushell #($week_num)(char nl)(char nl)" -if ($env | select GITHUB_USERNAME | empty?) || ($env | select GITHUB_PASSWORD | empty?) { +if ($env | select GITHUB_USERNAME | is-empty) || ($env | select GITHUB_PASSWORD | is-empty) { echo 'Please set GITHUB_USERNAME and GITHUB_PASSWORD in $env to use this script' } else { do-work | str collect diff --git a/maths/math_functions.nu b/maths/math_functions.nu index d777e7a..44eca3d 100644 --- a/maths/math_functions.nu +++ b/maths/math_functions.nu @@ -74,7 +74,7 @@ def isprime [n: int] { let flag = ([[isPrime];[true]] | update isPrime {if ($n mod 2) == 0 { false } else { seq 3 1 $max | each { |it| if ($n mod $it) == 0 { false }}}}) - if ($flag.isPrime.0 | empty?) { echo 'prime' } else { echo 'not prime' } + if ($flag.isPrime.0 | is-empty) { echo 'prime' } else { echo 'not prime' } } #Prime list <= n @@ -143,7 +143,7 @@ def dec2base [ # Scale list to [a,b] interval def scale-minmax [a, b,input?] { - let x = if ($input | empty?) {$in} else {$input} + let x = if ($input | is-empty) {$in} else {$input} let min = ($x | math min) let max = ($x | math max) @@ -153,7 +153,7 @@ def scale-minmax [a, b,input?] { # Scale every column of a table (separately) to [a,b] interval def scale-minmax-table [a, b,input?] { - let x = if ($input | empty?) {$in} else {$input} + let x = if ($input | is-empty) {$in} else {$input} let n_cols = ($x | transpose | length) let name_cols = ($x | transpose | column2 0) diff --git a/miscelaneous/nu_defs.nu b/miscelaneous/nu_defs.nu index ae1daad..ab1bd79 100644 --- a/miscelaneous/nu_defs.nu +++ b/miscelaneous/nu_defs.nu @@ -18,7 +18,7 @@ def mcx [file] { #open file def openf [file?] { - let file = if ($file | empty?) {$in} else {$file} + let file = if ($file | is-empty) {$in} else {$file} bash -c $'xdg-open "($file)" 2>/dev/null &' } @@ -213,7 +213,7 @@ def 7zmax [ # 7zmax * "-sdel" ] { - if ($rest | empty?) { + if ($rest | is-empty) { echo "no files to compress specified" } else { 7z a -t7z -m0=lzma2 -mx=9 -ms=on -mmt=on $"($filename).7z" $rest @@ -252,7 +252,7 @@ def agenda [ let calendars = "your_selected_calendars" let calendars_full = "most_calendars" - if ($full | empty?) || ($full == 0) { + if ($full | is-empty) || ($full == 0) { gcalcli --calendar $"($calendars)" agenda --military $rest } else { gcalcli --calendar $"($calendars_full)" agenda --military $rest @@ -273,7 +273,7 @@ def semana [ let calendars = "your_selected_calendars" let calendars_full = "most_calendars" - if ($full | empty?) || ($full == 0) { + if ($full | is-empty) || ($full == 0) { gcalcli --calendar $"($calendars)" calw $rest --military --monday } else { gcalcli --calendar $"($calendars_full)" calw $rest --military --monday @@ -294,7 +294,7 @@ def mes [ let calendars = "your_selected_calendars" let calendars_full = "most_calendars" - if ($full | empty?) || ($full == 0) { + if ($full | is-empty) || ($full == 0) { gcalcli --calendar $"($calendars)" calm $rest --military --monday } else { gcalcli --calendar $"($calendars_full)" calm $rest --military --monday @@ -303,7 +303,7 @@ def mes [ #get bitly short link (requires xclip) def mbitly [longurl] { - if ($longurl | empty?) { + if ($longurl | is-empty) { echo "no url provided" } else { let Accesstoken = "Token" @@ -332,14 +332,14 @@ def trans [ #More in: https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes ] { - if ($search | empty?) { + if ($search | is-empty) { echo "no search query provided" } else { let key = "api_kei" let user = "user_email" - let from = if ($from | empty?) {"en-US"} else {$from} - let to = if ($to | empty?) {"es-ES"} else {$to} + let from = if ($from | is-empty) {"en-US"} else {$from} + let to = if ($to | is-empty) {"es-ES"} else {$to} let to_translate = ($search | str collect "%20") @@ -387,14 +387,14 @@ def gnu-plot [ #($x | column 0) | gnu-plot --title "My Title" #gnu-plot $x --title "My Title" ] { - let x = if ($data | empty?) {$in} else {$data} + let x = if ($data | is-empty) {$in} else {$data} let n_cols = ($x | transpose | length) let name_cols = ($x | transpose | column2 0) let ylabel = if $n_cols == 1 {$name_cols | get 0} else {$name_cols | get 1} let xlabel = if $n_cols == 1 {""} else {$name_cols | get 0} - let title = if ($title | empty?) {if $n_cols == 1 {$ylabel | str upcase} else {$"($ylabel) vs ($xlabel)"}} else {$title} + let title = if ($title | is-empty) {if $n_cols == 1 {$ylabel | str upcase} else {$"($ylabel) vs ($xlabel)"}} else {$title} $x | to tsv | save data0.txt sed 1d data0.txt | save data.txt @@ -438,10 +438,10 @@ def skim [ } else if ($type == 'string') { $lst }) - if ($s | empty?) { + if ($s | is-empty) { null } else { - if ($preview | empty? ) { + if ($preview | is-empty ) { ($s | sk --layout reverse @@ -476,8 +476,8 @@ def group-list [ def make-group [v, buf, ret, key] { let new_group = ($'($v)' =~ $regex) if $new_group { - let is_key = (not ($key | empty?)) - let is_buf = (not ($buf | empty?)) + let is_key = (not ($key | is-empty)) + let is_buf = (not ($buf | is-empty)) if ($is_buf && $is_key) { let ret = ($ret | append {key: $key, values: $buf}) {buf: [], ret: $ret, key: $v} @@ -490,7 +490,7 @@ def group-list [ } } def loop [lst, buf=[], ret=[], key=''] { - if ($lst | empty?) { + if ($lst | is-empty) { {ret: $ret, buf: $buf, key: $key} } else { let v = ($lst | first) @@ -503,8 +503,8 @@ def group-list [ let ret = $obj.ret let buf = $obj.buf let key = $obj.key - let is_key = (not ($key | empty?)) - let is_buf = (not ($buf | empty?)) + let is_key = (not ($key | is-empty)) + let is_buf = (not ($buf | is-empty)) if ($is_buf && $is_key) { $ret | append {key: $key, values: $buf} } else { diff --git a/prompt/panache-git.nu b/prompt/panache-git.nu index b1533eb..fcb86c5 100644 --- a/prompt/panache-git.nu +++ b/prompt/panache-git.nu @@ -27,7 +27,7 @@ module panache-plumbing { do --ignore-errors { $current_dir | path relative-to $nu.home-path } | str collect ) - let in_sub_dir_of_home = ($current_dir_relative_to_home | empty? | nope) + let in_sub_dir_of_home = ($current_dir_relative_to_home | is-empty | nope) let current_dir_abbreviated = (if $in_sub_dir_of_home { $'~(char separator)($current_dir_relative_to_home)' @@ -40,7 +40,7 @@ module panache-plumbing { # Get repository status as structured data export def "panache-git structured" [] { - let in_git_repo = (do --ignore-errors { git rev-parse --abbrev-ref HEAD } | empty? | nope) + let in_git_repo = (do --ignore-errors { git rev-parse --abbrev-ref HEAD } | is-empty | nope) let status = (if $in_git_repo { git --no-optional-locks status --porcelain=2 --branch | lines @@ -83,7 +83,7 @@ module panache-plumbing { $status | where ($it | str starts-with '# branch.upstream') | str collect - | empty? + | is-empty | nope } else { false @@ -93,7 +93,7 @@ module panache-plumbing { $status | where ($it | str starts-with '# branch.ab') | str collect - | empty? + | is-empty | nope } else { false @@ -130,7 +130,7 @@ module panache-plumbing { $status | where ($it | str starts-with '1') || ($it | str starts-with '2') | str collect - | empty? + | is-empty | nope } else { false @@ -140,7 +140,7 @@ module panache-plumbing { $status | where ($it | str starts-with '?') | str collect - | empty? + | is-empty | nope } else { false @@ -150,7 +150,7 @@ module panache-plumbing { $status | where ($it | str starts-with 'u') | str collect - | empty? + | is-empty | nope } else { false diff --git a/rbenv/rbenv.nu b/rbenv/rbenv.nu index a6026e4..bba0699 100644 --- a/rbenv/rbenv.nu +++ b/rbenv/rbenv.nu @@ -16,7 +16,7 @@ export def-env rbenv [ error make { msg: $"`($command)` command is not supported yet" } } } else { - if ($command | empty?) { + if ($command | is-empty) { ^rbenv } else { ^rbenv $command $args diff --git a/virtual_environments/conda.nu b/virtual_environments/conda.nu index 8b71018..56f28bb 100644 --- a/virtual_environments/conda.nu +++ b/virtual_environments/conda.nu @@ -87,7 +87,7 @@ def 'nu-complete conda envs' [] { conda info --envs | lines | where not ($it | str starts-with '#') - | where not ($it | empty?) + | where not ($it | is-empty) | each {|entry| $entry | split row ' ' | get 0 } }