Symbol Link in MSYS on WIN7

[size=medium]As we know the symbol link command 'ln' in MinGW is fake that it creates copy instead of real link in *nix file system.[/size]

[size=medium]A good news is on Win7 its new NTFS support symbol link feature! With "mklink" command in Windows Command Prompt, we could easily do so like below:[/size]

mklink [/d] link target


[size=medium]So it won't be hard to implement a "mklink" for MinGW like below:[/size]

#!/bin/bash

#####################################################
#
# (c) Copyright 2012 Clark. All Rights Reserved.
# 2012-08-29
#
#####################################################

Usage() {
cat<<EOF
mklink [-d][ -z "$2" ][ "$3" != "" && "$1" != "-d" ][ "$3" != "" ][ "${TARGET:0:1}" == "/" ]; then
ROUTE=$(echo "$TARGET" | sed 's,^/\([c-z][ "$ROUTE" == "$TARGET" ]; then
ROUTE=$(echo "$3" | sed 's,^/,'$MSYS',')
fi
else
ROUTE="$TARGET"
fi

ROUTE=$(echo "$ROUTE" | sed 's,/,\\,g')

CMD=$(echo mklink $ISDIR $LINK \"$ROUTE\")
#echo $CMD
cmd /c "$CMD"


[size=medium][color=red]Please be noted that according to [url=http://superuser.com/questions/167076/windows-7-delete-symbolic-link]this article[/url] if you want to remove a directory symbol link in Win7 you should only use 'rmdir' (both available in CMD and MSYS). The 'del' command in CMD will delete all your files in the source directory!!![/color][/size]

[b][size=medium]A typical use case[/size][/b]

[size=medium]You have created your awesome .vimrc and .vim in MSYS and you want to re-use them in gvim:[/size]
cd "$USERPROFILE"
# below 2 links makes your Windows gvim load resource directly from
# you MSYS configurations.
mklink /c/MinGW/msys/1.0/home/user/.vimrc _vimrc
mklink /c/MinGW/msys/1.0/home/user/.vim vimfiles.
# and if you want to invoke gvim from MSYS
cd ~
mklink .vim vimfiles
# a link for _vimrc is not necessary
alias gvim="/c/Program\ Files\ \(x86\)/Vim/vim73/gvim.exe"
# to start gvim in background
gvim <FILENAME> &
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值