# utility functions # TODO: move this into nushell modules # returs true, if the sequene has exactly one element export def has-one []: list -> bool { let size = $in | length $size == 1 } # Gets value of a column, or falls back to given alternative value. export def get-or-else [ column: string # name of the column to get its value from value: any # alternative value to return, in case `get` gets nothing ]: [ record -> any table -> any ] { select -i $column | update $column { if ( $in | is-empty ) { $value } else { $in } } | get $column } # checks if a file is executable export def is-executable []: path -> bool { match $nu.os-info.family { 'unix' => { $env | upsert __file_for_executbale_check ( $in | path expand ) run-external sh '-c' '[ -x "$__file_for_executbale_check" ] && echo true || echo false' | into bool } 'windows' => { # poor mans check on win32 $in | find --regex '(\.exe)|(\.bat)|(\.ps1)$' | is-not-empty } } } # creates a symbolic link export def slink [ source: path # the original file path target: path # the file of the symbolic link ] { match $nu.os-info.family { 'unix' => { run-external ln '--symbolic' $source $target } 'windows' => { # TODO: test on win32 run-external cmd '/c' mklink $target $source } } }