aboutsummaryrefslogtreecommitdiff
path: root/fix-dotfile-paths.sh
blob: fcabd6f85a8fc6bc4bb9429daf23ff8312dfd347 (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
#!/bin/sh

create_ls_entry () {
    echo "#+title: =~/$1=" > index.org
    echo "* Directories" >> index.org
    if [ "$1" != "" ]; then
        echo "- [[https://jjanzen.ca/dotfiles/$1..][=../=]]" >> index.org
    fi
    find -L -- . -maxdepth 1 -type d | sed '/^\.$/d' | sed 's/^\.\///' | while read -r dir; do
        if [ "$dir" != "*" ] && [ "$dir" != ".git" ]; then
            echo "- [[https://jjanzen.ca/dotfiles/$1$dir][=$dir/=]]" >> index.org
        fi
    done
    echo "* Files" >> index.org
    find -L -- . -maxdepth 1 -type f | sed 's/^\.\///' | 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 "- [[https://jjanzen.ca/dotfiles/$1$html][=$new_file=]]" >> index.org
        fi
    done
}

create_dir_tree () {
    ROOT="$HOME/.dotfiles/$1"
    create_ls_entry ""

    # 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/"

        cd "$ROOT" || exit
    done
}

cd ~/.dotfiles || exit
git checkout main
echo '#+title: Dotfiles' >> index.org
echo 'This is my system configuration. 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