aboutsummaryrefslogtreecommitdiff
path: root/fix-dotfile-paths.sh
blob: e4d22e05d67c5c27c9b3f38e318ccb4347ffbb2b (plain)
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/bin/sh

create_ls_entry () {
    echo "creating entry $2$1"
    echo "#+title: =~/$1=" > index.org
    echo "* Directories" >> index.org
    if [ "$1" != "" ]; then
        echo "- [[$2$1..][=../=]]" >> index.org
    fi
    find -L -- . -maxdepth 1 -type d | sed '/^\.$/d' | sed 's/^\.\///' | sort | while read -r dir; do
        if [ "$dir" != "*" ] && [ "$dir" != ".git" ]; then
            echo "- [[$2$1$dir][=$dir/=]]" >> index.org
        fi
    done
    files=$(find -L -- . -maxdepth 1 -type f | sed 's/^\.\///')
    if [ "$files" != '' ]; then
        echo '* Files' >> index.org
        echo "$files" | sort | while read -r file; do
            if [ "$file" = ".wallpaper" ]; then
                echo "- [[https://wallhaven.cc/w/vgryy5][=.wallpaper=]]" >> index.org
            elif echo "$file" | grep -q "\.org$" && [ "$file" != "index.org" ]; then
                new_file=$(basename "$(grep '#+begin_src' "$file" | head -1 | cut -d ' ' -f 4)")
                html=$(echo "$file" | sed 's/\.org$/\.html/')
                echo "- [[$2$1$html][=$new_file=]]" >> index.org
            fi
        done
    fi
}

create_dir_tree () {
    ROOT="$HOME/.dotfiles/$1"
    URLROOT="https://jjanzen.ca/dotfiles/$1/"
    create_ls_entry "" "$URLROOT"

    # iterate over all directories
    find -L -- . -type d | sed '/^\.$/d' | while read -r dir; do
        cd "$dir" || continue

        dir=$(echo "$dir" | sed 's/^\.\///')

        create_ls_entry "$dir/" "$URLROOT"

        cd "$ROOT" || exit
    done
}

cd ~/.dotfiles || exit
git checkout main
echo '#+title: Dotfiles' >> index.org
echo 'This is my system configuration. These pages are automatically generated from the sources hosted [[https://git.sr.ht/~jjanzen/.dotfiles][here]]. Choose which system to browse: ' >> index.org
find -- . -maxdepth 1 -type d | sed '/\(^\.$\|^\.\/\.git$\|\.\/common\)/d' | while read -r root; do
    root=$(echo "$root" | sed 's/\(\.\/\|\/$\)//')
    echo "- [[https://jjanzen.ca/dotfiles/$root][$root]]" >> index.org
    cd "$root" || exit
    create_dir_tree "$root"
    cd ~/.dotfiles || exit
done

cd || exit