You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
35 lines
1.0 KiB
Cheetah
35 lines
1.0 KiB
Cheetah
10 months ago
|
def print-fact [] {
|
||
|
let username = {{#if flags.windows}}$env.USERNAME{{else}}$env.USER{{/if}}
|
||
|
echo $"Hello (ansi purple_bold)($username)(ansi reset),
|
||
11 months ago
|
it's the (ansi purple_bold)(date now | format date '%d.%m.%Y')(ansi reset) at (ansi purple_bold)(date now | format date '%H:%M:%S')(ansi reset)
|
||
10 months ago
|
Did you know: (ansi purple_bold)(fact)(ansi reset)"
|
||
|
}
|
||
|
|
||
|
def fact [] {
|
||
10 months ago
|
let cache_file = '{{dirs.data}}' | path join facts.txt
|
||
10 months ago
|
if not ($cache_file | path exists) {
|
||
|
touch $cache_file
|
||
|
}
|
||
|
mut all_facts = open $cache_file | lines
|
||
|
|
||
|
if ($all_facts | length) < 4 {
|
||
|
try {
|
||
|
$all_facts = (fetch-facts | prepend $all_facts)
|
||
|
} catch {|e|
|
||
|
print -e $"Failed to refresh facts cache ($e)"
|
||
|
}
|
||
|
}
|
||
|
$all_facts | skip 1 | str join "\n" | save -f $cache_file
|
||
|
if ($all_facts | is-empty) {
|
||
|
"I wasn't able to provide a fact."
|
||
|
} else {
|
||
|
$all_facts | first
|
||
|
}
|
||
|
}
|
||
|
|
||
|
def fetch-facts [num_facts: number = 10] {
|
||
|
0..($num_facts) | par-each { http get https://uselessfacts.jsph.pl/api/v2/facts/random | get text }
|
||
|
}
|
||
|
|
||
|
print-fact
|