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

cd ~/.dotfiles || exit
START=$(pwd)
find -- . -type d | sed '/^\.\$/d' | sed '/^\.\/\.git\//d' | sed '/^\.\/.git/d' | while read -r line; do
    cd "${line}" || continue

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

    if ! test -f ./index.org; then
        echo "#+title: =~/${line}=" > index.org
        echo "* Directories" >> index.org
        for dir in */; do
            echo "- [[https://jjanzen.ca/dotfiles/${line}/${dir}][${dir}]]" >> index.org
        done
        echo "* Files" >> index.org
        for file in *; do
            if test -f "${file}"; then
                if echo "${file}" | grep -q "\.org\$"; then
                    new_file=$(basename "$(grep '#+begin_src' "${file}" | head -1 | cut -d ' ' -f 4)")
                fi
                if [ "$new_file" = "" ]; then
                    new_file=$file
                fi
                echo "- [[/dotfiles/${line}/${file}][${new_file}]]" >> index.org
            fi
        done
    fi
    cd "${START}" || exit
done