36 lines
868 B
Plaintext
Executable File
36 lines
868 B
Plaintext
Executable File
#!/usr/bin/env nu
|
|
|
|
let today = (date now | format date '%Y-%m-%d')
|
|
let pic_dir = (xdg-user-dir PICTURES)
|
|
let bg_dir = $pic_dir | path join "bg"
|
|
let today_img_file = $bg_dir | path join ( [ $today, ".png" ] | str join )
|
|
let is_new = ((date now | format date "%H" | into int) >= 10)
|
|
mkdir $bg_dir
|
|
|
|
def exists [file: path] {
|
|
return ($file | path exists)
|
|
}
|
|
|
|
def is_empty [file: path] {
|
|
return ((exists $file) and ((ls $file | get size | first | into int) == 0))
|
|
}
|
|
|
|
def fetch [] {
|
|
http get ("https://bing.com" + ((http get https://www.bing.com/HPImageArchive.aspx?format=js&n=1).images.0.url)) | save $today_img_file
|
|
}
|
|
|
|
def cleanup [] {
|
|
if (is_empty $today_img_file) {
|
|
rm -rf $today_img_file
|
|
}
|
|
}
|
|
|
|
cleanup
|
|
|
|
if $is_new and (not (exists $today_img_file)) {
|
|
fetch
|
|
/run/current-system/sw/bin/ln -sf $today_img_file ( $pic_dir | path join "bg.png" )
|
|
}
|
|
|
|
cleanup
|