summary refs log tree commit diff
path: root/home.zsh
blob: 8490a3b53feecf8b68a6e310f162d823c6142576 (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
39
40
41
42
#!/usr/bin/env zsh
set -o errexit -o nounset -o pipefail

fail() {
    echo "$@"
    exit 1
}

link() {
    local relPath srcPath dstPath
    < home.txt while read relPath; do
        srcPath="$PWD/home/$relPath"
        dstPath="$HOME/$relPath"
        [ -L "$dstPath" ] && continue
        mkdir -p "$(dirname "$dstPath")"
        ln -s "$srcPath" "$dstPath"
        echo "$relPath"
    done
}

import() {
    local relPath srcPath dstPath
    relPath="$1"
    srcPath="$HOME/$relPath"
    dstPath="$PWD/home/$relPath"
    [ -f "$dstPath" ] && fail "$dstPath exists"
    mkdir -p "$(dirname "$dstPath")"
    mv "$srcPath" "$dstPath"
    ln -s "$dstPath" "$srcPath"
    echo "$relPath" >> home.txt
    sort -o home.txt home.txt
}

prune() {
    local linkPath
    find -L ~ -type l -lname "$PWD/*" | while read linkPath; do
        rm "$linkPath"
        echo "$linkPath"
    done
}

$@