add symlink_to_file function
authorJoerg Jaspert <joerg@debian.org>
Sun, 3 Mar 2013 14:39:49 +0000 (15:39 +0100)
committerJoerg Jaspert <joerg@debian.org>
Sun, 3 Mar 2013 14:39:49 +0000 (15:39 +0100)
A .zsh/functions/symlink_to_file

.zsh/functions/symlink_to_file [new file with mode: 0644]

diff --git a/.zsh/functions/symlink_to_file b/.zsh/functions/symlink_to_file
new file mode 100644 (file)
index 0000000..1743e58
--- /dev/null
@@ -0,0 +1,21 @@
+# -*- mode:sh -*-
+
+local filename=${1:-""}
+
+if [ "${#filename}" -lt 1 ]; then
+    echo "Call: $0 SYMLINK"
+    return 1
+fi
+
+if [ ! -L "${filename}" ]; then
+    echo "$0: ${filename} is not a symbolic link"
+    return 2
+fi
+
+sourcefile=$(readlink -f -n ${filename})
+if [ ! -r "${sourcefile}" ]; then
+    echo "$0: Can't read sourcefile: $sourcefile"
+    return 3
+fi
+
+cp --remove-destination ${sourcefile} ${filename}