summary refs log tree commit diff
path: root/link.sh
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2018-08-16 18:00:42 -0400
committerJune McEnroe <june@causal.agency>2018-08-16 18:00:42 -0400
commit0460970a937191ee3ff70658503e7407d4cf6caa (patch)
treeb349321d4d920e9104603da0dd123079346b34eb /link.sh
parentShorten .local ssh names (diff)
downloadsrc-0460970a937191ee3ff70658503e7407d4cf6caa.tar.gz
src-0460970a937191ee3ff70658503e7407d4cf6caa.zip
Port all scripts to sh
Not hard, but having to escape ( ) inside [ ] had me confused for a bit.
Diffstat (limited to 'link.sh')
-rwxr-xr-xlink.sh18
1 files changed, 18 insertions, 0 deletions
diff --git a/link.sh b/link.sh
new file mode 100755
index 00000000..0f1f49aa
--- /dev/null
+++ b/link.sh
@@ -0,0 +1,18 @@
+#!/bin/sh
+set -e -u
+
+if [ $# -eq 1 ]; then
+	linkPath=$1
+	filePath="$PWD/home/${linkPath#$HOME/}"
+	[ ! -f "$filePath" ]
+	mkdir -p "$(dirname "$filePath")"
+	mv "$linkPath" "$filePath"
+fi
+
+find home -type f | while read -r findPath; do
+	filePath="$PWD/$findPath"
+	linkPath="$HOME/${findPath#home/}"
+	mkdir -p "$(dirname "$linkPath")"
+	[ \( -f "$linkPath" -a -L "$linkPath" \) -o ! -f "$linkPath" ]
+	ln -s -f "$filePath" "$linkPath"
+done