summary refs log tree commit diff
path: root/home.zsh
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2018-03-14 00:10:56 -0400
committerJune McEnroe <june@causal.agency>2018-03-14 00:10:56 -0400
commitd7842c2b96da32bcfb181a88c34a4b67cf6bc815 (patch)
tree25ca849742e2617fd35b583da611212f868b5491 /home.zsh
parentPHONY is a waste of time (diff)
downloadsrc-d7842c2b96da32bcfb181a88c34a4b67cf6bc815.tar.gz
src-d7842c2b96da32bcfb181a88c34a4b67cf6bc815.zip
Combine home-related scripts
Diffstat (limited to 'home.zsh')
-rwxr-xr-xhome.zsh42
1 files changed, 42 insertions, 0 deletions
diff --git a/home.zsh b/home.zsh
new file mode 100755
index 00000000..8490a3b5
--- /dev/null
+++ b/home.zsh
@@ -0,0 +1,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
+}
+
+$@