about summary refs log tree commit diff stats
path: root/pkgs/by-name/ne/neorg/functions/inputs.sh
blob: 613d75741379583c2337619b52d105de1fad182c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/usr/bin/env dash

inputs0add() {
    url_file="$1"

    mkdir --parents "$(dirname "%NEORG_INPUTS_STORAGE_FILE")"

    clean "$url_file" >>"%NEORG_INPUTS_STORAGE_FILE" &&
        msg2 "Successfully added file '$url_file' with $(wc -l <"$url_file") entries to the url list"
}

inputs0review() {
    base_profile="$1"

    [ -f "%NEORG_INPUTS_STORAGE_FILE" ] || die "'%NEORG_INPUTS_STORAGE_FILE' is not a file. Have you added something with 'inputs_add' yet?"

    done_urls="$(mktmp)"

    # We assume that the project is not yet open.
    firefox -P "$base_profile" &

    while read -r url; do
        msg "Adding url '$url'"
        notify-send "Neorg" "Reviewing '$url'"
        firefox -P "$base_profile" "$url"

        echo "$url" >>"$done_urls"
    done <"%NEORG_INPUTS_STORAGE_FILE"

    # Wait for the Firefox process from above to finish.
    wait

    tmp="$(mktmp)"
    # source: https://stackoverflow.com/a/24324455
    awk 'NR==FNR {a[$0]=1; next} !a[$0]' "$done_urls" "%NEORG_INPUTS_STORAGE_FILE" >"$tmp"

    mv "$tmp" "%NEORG_INPUTS_STORAGE_FILE"
}