aboutsummaryrefslogtreecommitdiff
path: root/fix-dotfile-paths.sh
blob: 004f6466939d9bb91a94cd8ae54a9dec15cc1cf5 (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
#!/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 -- . -maxdepth 1 -type d | sed '/^\.$/d' | sed 's/^\.\///' | while read -r dir; do
        if [ "${dir}" != "*" ]; then
            echo "- [[https://jjanzen.ca/dotfiles/$1${dir}][=${dir}/=]]" >> index.org
        fi
    done
    echo "* Files" >> index.org
    find -- . -maxdepth 1 -type f | sed 's/^\.\///' | while read -r file; do
        if echo "${file}" | grep -q "\(\.tar\.gz$\|\*|^index\.org$\|^README\.md$\|^\.build\.yml$\|^install$\)"; then
            continue
        elif [ "${file}" = ".wallpaper" ]; then
            echo "- [[https://wallhaven.cc/w/vgryy5][.wallpaper]]" >> index.org
            continue
        fi

        if echo "${file}" | grep -q "\.org$"; then
            new_file=$(basename "$(grep -q '#+begin_src' "${file}" | head -1 | cut -d ' ' -f 4)")
        else
            new_file=$file
        fi
        html=$(echo "${file}" | sed 's/\.org$/\.html/')
        echo "- [[https://jjanzen.ca/dotfiles/$1${html}][=${new_file}=]]" >> index.org
    done
}

cd ~/.dotfiles || exit
START=$(pwd)

create_ls_entry ""

# iterate over all files except the .git/ directory and .
find -- . -type d | sed '/^\.$/d' | sed '/^\.\/\.git\//d' | sed '/^\.\/.git/d' | while read -r dir; do
    cd "${dir}" || continue

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

    create_ls_entry "${dir}/"

    cd "${START}" || exit
done