Created
November 28, 2013 12:57
-
-
Save geoff-nixon/7691477 to your computer and use it in GitHub Desktop.
dirlink — ln with support for directory hard links and "hard linking" symbolic links For Darwin. Needs some reformatting, but it works! Install in your path **as** ln for best results.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
d64(){ env awk 'function d(){while(getline<"/dev/stdin"){for(i=1;i<=length ($0); | |
i++){c=index("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/", | |
substr($0,i,1));if(c--){for(b=0;b<6;b++){o=o*2+int(c/32);c=(c*2)%64;if(++obc==8) | |
{printf "%c",o;obc=0;o=0;}}}}}}d()';}; here=$(pwd); for where; do true; done | |
s(){ awk '{split($0,c,"");for(i=1;i<=length(c);i++){printf("%s\n",c[i])}}' ;} | |
temp=$(echo '/tmp/.'$(od -XN4 -An /dev/urandom|sed "s/ //g")); filex(){ echo ' | |
H4sIAAAAAAACA+2ZX2gcVRTGz2wm3dFOzDwEDBp1H7bSgmRjSaSoBVN2aYptjTbVoA3Xye7N7pj5E+ | |
7ONNnSYmGtMK7BUnzxSYL6Iig+1jdLhRYECb7qg6CFaCIE6oP0wfWczU13muwWwSfh/thvz3d35nx3 | |
bu4u7GS/v/PH32kA6EGlUHtRrg5wCUDT0B9CMTY5frTweuGVl6CNBV2hvvc16psqTE8le6Skp3l7pQ | |
jGQr4UgmR3/+pjACc0rH0AOiTQ4WK7p1rzZgOXVcNotkPG408ADFLtp+tsY8iMPSjWamYV7i5w0SHj | |
EGYMU8WMVNfrKFZD4fjlLmuZw4w8VcxIksxjLPIXHb/EHH8u6JDxOWZMUO2//15MaNSbH58ahzYZlN | |
XW9ntAvzt3qeaWQNK535D7mILOMOa729uxEIpdGQZmmFR3ZOy55zpc+34ZA5hhUd2RkZaSexF4XuB3 | |
W0sWM/Id/v5awrc/C8ePnXyxkD+2vQ8jAJ/SwcxWTSf7ZN6gXOtDWH/CelN+ziYT2aReuXYDuvNVhn | |
p3Q9lDKBOVi6oi5zqzObmFvXIuTW73vwU/bx0xUaNyXSnK1b7Q8bk9L+pUrRpyb/jIcKmGI4Anae7E | |
++aAHBsZ+A8oFAqFQqFQKN6C+Fb91836htWY0eOh7PIJIz6e1evXtWu/pLTv4jNZY00DgD9Px7dOvf | |
ZqfWOoUTA+oW/AjQtmfHg/mciKx54ik/6ablMufRM+sp6Kby5PaOva+HsvN9/5IUxfvJOLbq//Hl+L | |
+0bw1Ph2/TlYfkOP/lqxqJOaUs3VFSMxWPsSAJYLG3E+q9/Qs2WMXpsBgObpjeXCpnz1Q3r1KGBXYR | |
PbjFjPrp3H4YqJSTeAwDWYcZg14vNZHS+ezqBvl1SnsV6+XAELU/dBBgfNfTqVu+Cy6xtG/YLREz3c | |
KJiNCb3xgkFzx2Z2DeeG9d6rGpb6t8bMdeweyFDUYOt5qPWcyQBSoQO/XWk2m+gHyb+75YfIn9vyGf | |
I+enk7xTx7nrMSd+0ax0FQilzOHN8JHdt1znHBirbrVuXJdJyFXHhsLvKLVdDkN3zYUVMouiMeBZS8 | |
swXpe1AmdlqoLlg/f2CgyCbvb/OoSdQZlEKhUCgUCoVCoVAoFIr/N6uPHvhRMy24iv551JGC3atj7X | |
/Aav0uakq/H/2A9CPo8QE9mgWAj1H5Ov3P6DB6jR7Imwm/mPBvJ/yVhP8o4T9O+M8Sfvv30b0oE5VG | |
PYjq63CMYCenx0W5KOtZYIwtiKDs2x5H71UYX+LFKOSswu0SF8C4f9YRgU8nzvOaVxastGiLuYNM8L | |
JTDblgVV4MncCv4inFsCKwr/U/HCaCKHR8jLVDvuSEwIpuUJxntmsLD7sX3BqmC+EHWFrHXcefB+bZ | |
xcq9AcIuiWdzubFnnh4dGz0I8A+mYostpCEAAA=='|d64|gzcat > $temp; chmod +x $temp ;} | |
slnk(){ for a in $(with "$@"); do if [ $a = s ];then echo s; break;fi; done ;} | |
what(){ for that in "$@"; do if [ "$that" != "$where" ]; then echo $that; fi done ;}; dlnk(){ filex; $temp "$@"; rm -rf $temp ;} | |
with(){ for that in $(what "$@"); do if [ "$(echo $that | cut -c1)" = "-" ] | |
then echo $that | sed -e 's/\-//g' | s; fi; done ;} | |
if [ "$(slnk $@)" = s ]; then exec ln "$@"; exit 0; else | |
for file in "$(what "$@")"; do if [ "$(echo $that | cut -c1)" != "-" ]; then | |
if [ "$(echo $that | cut -c1)" != "/" ]; then file="./$file"; fi | |
if [ "$(echo $where | cut -c1)" != "/" ]; then where="./$where"; fi | |
if [ $(file -hbi "$file" | grep directory 1>/dev/null) ]; then | |
if not $(file -hbi "$file" | grep symbolic 1>/dev/null); then | |
exec ln "$@"; exit 0; fi else cp -R $file $where; exit 0; fi; else | |
if [ ! -e "$file" ]; then echo 'Cannot find specified original.'; exit 1; fi | |
wherefrom="$(dirname "$file")"; cd "$wherefrom"; wherefrom="$(pwd)" | |
fromwhere="$wherefrom/$(basename "$file")"; cd "$here"; fi | |
if [ -e "$where" ]; then | |
if not $(file -b $(dirname "$where") | grep directory 1>/dev/null); then | |
echo 'Cannot overwrite an existing file.'; exit 1; fi | |
whereto=$where; cd "$whereto"; whereto="$(pwd)"; cd "$here" | |
towhere="$whereto/$(basename "$file")"; else | |
if $(file -b $(dirname "$where") | grep directory 1>/dev/null); then | |
echo 'Cannt find destination specified.'; exit 1; fi | |
whereto="$(dirname "$where")"; cd "$whereto"; whereto="$(pwd)"; cd "$here" | |
towhere="$whereto/$(basename "$where")"; fi | |
if [ "$wherefrom" = "$whereto" ]; then | |
echo 'Cannot hard link directories in the same parent directory.'; exit 1 | |
elif [ "$fromwhere" = "$whereto" ]; then | |
echo 'Cannot recursively hard link directories.'; exit 1 | |
else dlnk "$fromwhere" "$towhere" | |
fi; done | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment