Use mklink in msys
I understand that Windows later-than-or-equal-to* Vista provides the mklink
shell command. I'd like to make use of this from the Msys terminal. Any idea how?
When I enter mklink
on the msys terminal, it outputs sh: mklink: command not found
. Msys only provides a fake ln
utility which appears to be effectively the same as cp
.
I tried writing a shell script to open a Windows shell and run mklink
within it, but when my shell script tries to execute cmd /C <instructions>
, msys brings the Windows shell to the foreground of the current terminal and leaves it there, without running the instructions.
**I don't say 'greater-than-or-equal-to' because XP was greater than Vista but had no mklink
utility.*
windows mklink msys
add a comment |
I understand that Windows later-than-or-equal-to* Vista provides the mklink
shell command. I'd like to make use of this from the Msys terminal. Any idea how?
When I enter mklink
on the msys terminal, it outputs sh: mklink: command not found
. Msys only provides a fake ln
utility which appears to be effectively the same as cp
.
I tried writing a shell script to open a Windows shell and run mklink
within it, but when my shell script tries to execute cmd /C <instructions>
, msys brings the Windows shell to the foreground of the current terminal and leaves it there, without running the instructions.
**I don't say 'greater-than-or-equal-to' because XP was greater than Vista but had no mklink
utility.*
windows mklink msys
add a comment |
I understand that Windows later-than-or-equal-to* Vista provides the mklink
shell command. I'd like to make use of this from the Msys terminal. Any idea how?
When I enter mklink
on the msys terminal, it outputs sh: mklink: command not found
. Msys only provides a fake ln
utility which appears to be effectively the same as cp
.
I tried writing a shell script to open a Windows shell and run mklink
within it, but when my shell script tries to execute cmd /C <instructions>
, msys brings the Windows shell to the foreground of the current terminal and leaves it there, without running the instructions.
**I don't say 'greater-than-or-equal-to' because XP was greater than Vista but had no mklink
utility.*
windows mklink msys
I understand that Windows later-than-or-equal-to* Vista provides the mklink
shell command. I'd like to make use of this from the Msys terminal. Any idea how?
When I enter mklink
on the msys terminal, it outputs sh: mklink: command not found
. Msys only provides a fake ln
utility which appears to be effectively the same as cp
.
I tried writing a shell script to open a Windows shell and run mklink
within it, but when my shell script tries to execute cmd /C <instructions>
, msys brings the Windows shell to the foreground of the current terminal and leaves it there, without running the instructions.
**I don't say 'greater-than-or-equal-to' because XP was greater than Vista but had no mklink
utility.*
windows mklink msys
windows mklink msys
asked Feb 13 '13 at 19:49
JellicleCatJellicleCat
80631124
80631124
add a comment |
add a comment |
4 Answers
4
active
oldest
votes
You can use Windows native symlinks. To enable it uncomment line with:
MSYS=winsymlinks:nativestrict
in MSYS2 start bat file. And run MSYS2 with admin privileges.
1
In the current version you can set this by uncommenting the respective line in the respective.ini
-files (msys2,ini
, etc.) in the Msys2 installation folder (C:msys64 by default).
– TNT
Mar 11 '18 at 9:52
add a comment |
Using cmd //c mklink
directly on the MSYS bash command line should work.
$ cmd //c mklink
Creates a symbolic link.
MKLINK [[/D] | [/H] | [/J]] Link Target
/D Creates a directory symbolic link. Default is a file
symbolic link.
/H Creates a hard link instead of a symbolic link.
/J Creates a Directory Junction.
Link specifies the new symbolic link name.
Target specifies the path (relative or absolute) that the new link
refers to.
Note: The mklink command and arguments need to be provided as a single argument to cmd. Quote the entire command like so
cmd //c 'mklink link target'
Note that the command would normally be
cmd /c 'mklink link target'
which would work in Cygwin and other shell environments,
and even in an existing CMD session.
However, msys seems to mangle command-line arguments (to Windows commands),
and it interprets /c
as a pathname to the root of the C
disk,
and converts it to c:
.
Typing //c
has been found to cause msys to pass the /c
option to cmd
.
See How to run internal cmd command from the msys shell?
I get the same result as you when I enter the command you entered, but when I supply the necessary arguments to actually make a linkcmd /c mklink <link> <target>
, then it opens the Windows shell in my current msys window.
– JellicleCat
Feb 14 '13 at 18:11
Ah, the mklink command and arguments need to be quoted. Answer amended accordingly.
– ak2
Feb 15 '13 at 9:19
2
...AND you need to escape the/c
parameter, using//c
instead. See superuser.com/a/526777/50251.
– rsenna
May 24 '14 at 3:36
Not much consolation, but I am trying to getmklink
working without msys in a makefile and it is causing no end of pain. The cmd /c thing almost worked, but then incapacitated mingw32-make (no further output). Wonderful. Think I'm going to find a way to avoid symlinks if this is the case!
– Engineer
Jul 5 '15 at 15:59
add a comment |
MSYS=winsymlinks:nativestrict
requires you to run MSYS2 in elevated mode,
I'm really not comfortable with that.
This script only prompts for UAC elevation when invoked,
of course it won't be useful for scripting then,
but at least it suits my needs:
~/scripts/sh/msys2-ln.sh:
#!/bin/sh
if [ "$#" -eq 2 -a "$1" == "-s" ]; then
TARGET="$2"
LINK=$(basename "$TARGET")
elif [ "$#" -eq 3 -a "$1" == "-s" ]; then
TARGET="$2"
LINK="$3"
else
echo "this weak implementation only supports `ln -s`"
exit
fi
if [ -d "$TARGET" ]; then
MKLINK_OPTS="//d"
fi
TARGET=$(cygpath -w -a "$TARGET")
LINK=$(cygpath -w -a "$LINK")
echo "$TARGET"
echo "$LINK"
cscript //nologo ~/scripts/wsh/run-elevated.js
cmd //c mklink $MKLINK_OPTS "$LINK" "$TARGET"
~/scripts/wsh/run-elevated.js
var args = WScript.Arguments;
if(args.length == 0){
WScript.Echo("nothing to run");
WScript.Quit(0);
}
var quoted_args = ;
for(var i = 1; i < args.length; ++i){
var arg = args(i); // it's a callable, not array like
if(arg.indexOf(" ") != -1){
arg = """ + arg + """;
}
quoted_args.push(arg);
}
var SHAPP = WScript.CreateObject("shell.application");
SHAPP.ShellExecute(args(0), quoted_args.join(" "), "", "runas", 1);
~/.bashrc
# workaround for MSYS2's awkward ln
if [ $- == *i* -a ! -z $MSYSTEM ]; then
alias ln='~/scripts/sh/msys2-ln.sh'
alias ecmd='powershell "start-process cmd.exe "/k cd /d $(pwd -W)" -verb runas"'
fi
The additional ecmd alias launches an elevated cmd in current directory,
might be useful sometimes,
and it also serves as an example of acquiring UAC elevation through powershell,
if somebody knows how to escape this thing properly,
we can ditch that WSH helper.
add a comment |
Windows 10 now supports symbolic links without needing to run as administrator, so long as you turn on developer mode in the Windows settings.
Once that is done, you can get ln
working correctly with a single line in a .bashrc
file in your home directory!
export MSYS=winsymlinks:nativestrict
(I was not able to figure out where the equivalent .ini file is in my Git Bash installation. But setting the environment variable there would probably work, too.)
More details in this very helpful article by Josh Kelley:
https://www.joshkel.com/2018/01/18/symlinks-in-windows/
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "3"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f550732%2fuse-mklink-in-msys%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
4 Answers
4
active
oldest
votes
4 Answers
4
active
oldest
votes
active
oldest
votes
active
oldest
votes
You can use Windows native symlinks. To enable it uncomment line with:
MSYS=winsymlinks:nativestrict
in MSYS2 start bat file. And run MSYS2 with admin privileges.
1
In the current version you can set this by uncommenting the respective line in the respective.ini
-files (msys2,ini
, etc.) in the Msys2 installation folder (C:msys64 by default).
– TNT
Mar 11 '18 at 9:52
add a comment |
You can use Windows native symlinks. To enable it uncomment line with:
MSYS=winsymlinks:nativestrict
in MSYS2 start bat file. And run MSYS2 with admin privileges.
1
In the current version you can set this by uncommenting the respective line in the respective.ini
-files (msys2,ini
, etc.) in the Msys2 installation folder (C:msys64 by default).
– TNT
Mar 11 '18 at 9:52
add a comment |
You can use Windows native symlinks. To enable it uncomment line with:
MSYS=winsymlinks:nativestrict
in MSYS2 start bat file. And run MSYS2 with admin privileges.
You can use Windows native symlinks. To enable it uncomment line with:
MSYS=winsymlinks:nativestrict
in MSYS2 start bat file. And run MSYS2 with admin privileges.
answered Feb 23 '16 at 7:41
driftcrowdriftcrow
7112
7112
1
In the current version you can set this by uncommenting the respective line in the respective.ini
-files (msys2,ini
, etc.) in the Msys2 installation folder (C:msys64 by default).
– TNT
Mar 11 '18 at 9:52
add a comment |
1
In the current version you can set this by uncommenting the respective line in the respective.ini
-files (msys2,ini
, etc.) in the Msys2 installation folder (C:msys64 by default).
– TNT
Mar 11 '18 at 9:52
1
1
In the current version you can set this by uncommenting the respective line in the respective
.ini
-files (msys2,ini
, etc.) in the Msys2 installation folder (C:msys64 by default).– TNT
Mar 11 '18 at 9:52
In the current version you can set this by uncommenting the respective line in the respective
.ini
-files (msys2,ini
, etc.) in the Msys2 installation folder (C:msys64 by default).– TNT
Mar 11 '18 at 9:52
add a comment |
Using cmd //c mklink
directly on the MSYS bash command line should work.
$ cmd //c mklink
Creates a symbolic link.
MKLINK [[/D] | [/H] | [/J]] Link Target
/D Creates a directory symbolic link. Default is a file
symbolic link.
/H Creates a hard link instead of a symbolic link.
/J Creates a Directory Junction.
Link specifies the new symbolic link name.
Target specifies the path (relative or absolute) that the new link
refers to.
Note: The mklink command and arguments need to be provided as a single argument to cmd. Quote the entire command like so
cmd //c 'mklink link target'
Note that the command would normally be
cmd /c 'mklink link target'
which would work in Cygwin and other shell environments,
and even in an existing CMD session.
However, msys seems to mangle command-line arguments (to Windows commands),
and it interprets /c
as a pathname to the root of the C
disk,
and converts it to c:
.
Typing //c
has been found to cause msys to pass the /c
option to cmd
.
See How to run internal cmd command from the msys shell?
I get the same result as you when I enter the command you entered, but when I supply the necessary arguments to actually make a linkcmd /c mklink <link> <target>
, then it opens the Windows shell in my current msys window.
– JellicleCat
Feb 14 '13 at 18:11
Ah, the mklink command and arguments need to be quoted. Answer amended accordingly.
– ak2
Feb 15 '13 at 9:19
2
...AND you need to escape the/c
parameter, using//c
instead. See superuser.com/a/526777/50251.
– rsenna
May 24 '14 at 3:36
Not much consolation, but I am trying to getmklink
working without msys in a makefile and it is causing no end of pain. The cmd /c thing almost worked, but then incapacitated mingw32-make (no further output). Wonderful. Think I'm going to find a way to avoid symlinks if this is the case!
– Engineer
Jul 5 '15 at 15:59
add a comment |
Using cmd //c mklink
directly on the MSYS bash command line should work.
$ cmd //c mklink
Creates a symbolic link.
MKLINK [[/D] | [/H] | [/J]] Link Target
/D Creates a directory symbolic link. Default is a file
symbolic link.
/H Creates a hard link instead of a symbolic link.
/J Creates a Directory Junction.
Link specifies the new symbolic link name.
Target specifies the path (relative or absolute) that the new link
refers to.
Note: The mklink command and arguments need to be provided as a single argument to cmd. Quote the entire command like so
cmd //c 'mklink link target'
Note that the command would normally be
cmd /c 'mklink link target'
which would work in Cygwin and other shell environments,
and even in an existing CMD session.
However, msys seems to mangle command-line arguments (to Windows commands),
and it interprets /c
as a pathname to the root of the C
disk,
and converts it to c:
.
Typing //c
has been found to cause msys to pass the /c
option to cmd
.
See How to run internal cmd command from the msys shell?
I get the same result as you when I enter the command you entered, but when I supply the necessary arguments to actually make a linkcmd /c mklink <link> <target>
, then it opens the Windows shell in my current msys window.
– JellicleCat
Feb 14 '13 at 18:11
Ah, the mklink command and arguments need to be quoted. Answer amended accordingly.
– ak2
Feb 15 '13 at 9:19
2
...AND you need to escape the/c
parameter, using//c
instead. See superuser.com/a/526777/50251.
– rsenna
May 24 '14 at 3:36
Not much consolation, but I am trying to getmklink
working without msys in a makefile and it is causing no end of pain. The cmd /c thing almost worked, but then incapacitated mingw32-make (no further output). Wonderful. Think I'm going to find a way to avoid symlinks if this is the case!
– Engineer
Jul 5 '15 at 15:59
add a comment |
Using cmd //c mklink
directly on the MSYS bash command line should work.
$ cmd //c mklink
Creates a symbolic link.
MKLINK [[/D] | [/H] | [/J]] Link Target
/D Creates a directory symbolic link. Default is a file
symbolic link.
/H Creates a hard link instead of a symbolic link.
/J Creates a Directory Junction.
Link specifies the new symbolic link name.
Target specifies the path (relative or absolute) that the new link
refers to.
Note: The mklink command and arguments need to be provided as a single argument to cmd. Quote the entire command like so
cmd //c 'mklink link target'
Note that the command would normally be
cmd /c 'mklink link target'
which would work in Cygwin and other shell environments,
and even in an existing CMD session.
However, msys seems to mangle command-line arguments (to Windows commands),
and it interprets /c
as a pathname to the root of the C
disk,
and converts it to c:
.
Typing //c
has been found to cause msys to pass the /c
option to cmd
.
See How to run internal cmd command from the msys shell?
Using cmd //c mklink
directly on the MSYS bash command line should work.
$ cmd //c mklink
Creates a symbolic link.
MKLINK [[/D] | [/H] | [/J]] Link Target
/D Creates a directory symbolic link. Default is a file
symbolic link.
/H Creates a hard link instead of a symbolic link.
/J Creates a Directory Junction.
Link specifies the new symbolic link name.
Target specifies the path (relative or absolute) that the new link
refers to.
Note: The mklink command and arguments need to be provided as a single argument to cmd. Quote the entire command like so
cmd //c 'mklink link target'
Note that the command would normally be
cmd /c 'mklink link target'
which would work in Cygwin and other shell environments,
and even in an existing CMD session.
However, msys seems to mangle command-line arguments (to Windows commands),
and it interprets /c
as a pathname to the root of the C
disk,
and converts it to c:
.
Typing //c
has been found to cause msys to pass the /c
option to cmd
.
See How to run internal cmd command from the msys shell?
edited Mar 20 '17 at 10:04
Community♦
1
1
answered Feb 14 '13 at 11:52
ak2ak2
3,2471315
3,2471315
I get the same result as you when I enter the command you entered, but when I supply the necessary arguments to actually make a linkcmd /c mklink <link> <target>
, then it opens the Windows shell in my current msys window.
– JellicleCat
Feb 14 '13 at 18:11
Ah, the mklink command and arguments need to be quoted. Answer amended accordingly.
– ak2
Feb 15 '13 at 9:19
2
...AND you need to escape the/c
parameter, using//c
instead. See superuser.com/a/526777/50251.
– rsenna
May 24 '14 at 3:36
Not much consolation, but I am trying to getmklink
working without msys in a makefile and it is causing no end of pain. The cmd /c thing almost worked, but then incapacitated mingw32-make (no further output). Wonderful. Think I'm going to find a way to avoid symlinks if this is the case!
– Engineer
Jul 5 '15 at 15:59
add a comment |
I get the same result as you when I enter the command you entered, but when I supply the necessary arguments to actually make a linkcmd /c mklink <link> <target>
, then it opens the Windows shell in my current msys window.
– JellicleCat
Feb 14 '13 at 18:11
Ah, the mklink command and arguments need to be quoted. Answer amended accordingly.
– ak2
Feb 15 '13 at 9:19
2
...AND you need to escape the/c
parameter, using//c
instead. See superuser.com/a/526777/50251.
– rsenna
May 24 '14 at 3:36
Not much consolation, but I am trying to getmklink
working without msys in a makefile and it is causing no end of pain. The cmd /c thing almost worked, but then incapacitated mingw32-make (no further output). Wonderful. Think I'm going to find a way to avoid symlinks if this is the case!
– Engineer
Jul 5 '15 at 15:59
I get the same result as you when I enter the command you entered, but when I supply the necessary arguments to actually make a link
cmd /c mklink <link> <target>
, then it opens the Windows shell in my current msys window.– JellicleCat
Feb 14 '13 at 18:11
I get the same result as you when I enter the command you entered, but when I supply the necessary arguments to actually make a link
cmd /c mklink <link> <target>
, then it opens the Windows shell in my current msys window.– JellicleCat
Feb 14 '13 at 18:11
Ah, the mklink command and arguments need to be quoted. Answer amended accordingly.
– ak2
Feb 15 '13 at 9:19
Ah, the mklink command and arguments need to be quoted. Answer amended accordingly.
– ak2
Feb 15 '13 at 9:19
2
2
...AND you need to escape the
/c
parameter, using //c
instead. See superuser.com/a/526777/50251.– rsenna
May 24 '14 at 3:36
...AND you need to escape the
/c
parameter, using //c
instead. See superuser.com/a/526777/50251.– rsenna
May 24 '14 at 3:36
Not much consolation, but I am trying to get
mklink
working without msys in a makefile and it is causing no end of pain. The cmd /c thing almost worked, but then incapacitated mingw32-make (no further output). Wonderful. Think I'm going to find a way to avoid symlinks if this is the case!– Engineer
Jul 5 '15 at 15:59
Not much consolation, but I am trying to get
mklink
working without msys in a makefile and it is causing no end of pain. The cmd /c thing almost worked, but then incapacitated mingw32-make (no further output). Wonderful. Think I'm going to find a way to avoid symlinks if this is the case!– Engineer
Jul 5 '15 at 15:59
add a comment |
MSYS=winsymlinks:nativestrict
requires you to run MSYS2 in elevated mode,
I'm really not comfortable with that.
This script only prompts for UAC elevation when invoked,
of course it won't be useful for scripting then,
but at least it suits my needs:
~/scripts/sh/msys2-ln.sh:
#!/bin/sh
if [ "$#" -eq 2 -a "$1" == "-s" ]; then
TARGET="$2"
LINK=$(basename "$TARGET")
elif [ "$#" -eq 3 -a "$1" == "-s" ]; then
TARGET="$2"
LINK="$3"
else
echo "this weak implementation only supports `ln -s`"
exit
fi
if [ -d "$TARGET" ]; then
MKLINK_OPTS="//d"
fi
TARGET=$(cygpath -w -a "$TARGET")
LINK=$(cygpath -w -a "$LINK")
echo "$TARGET"
echo "$LINK"
cscript //nologo ~/scripts/wsh/run-elevated.js
cmd //c mklink $MKLINK_OPTS "$LINK" "$TARGET"
~/scripts/wsh/run-elevated.js
var args = WScript.Arguments;
if(args.length == 0){
WScript.Echo("nothing to run");
WScript.Quit(0);
}
var quoted_args = ;
for(var i = 1; i < args.length; ++i){
var arg = args(i); // it's a callable, not array like
if(arg.indexOf(" ") != -1){
arg = """ + arg + """;
}
quoted_args.push(arg);
}
var SHAPP = WScript.CreateObject("shell.application");
SHAPP.ShellExecute(args(0), quoted_args.join(" "), "", "runas", 1);
~/.bashrc
# workaround for MSYS2's awkward ln
if [ $- == *i* -a ! -z $MSYSTEM ]; then
alias ln='~/scripts/sh/msys2-ln.sh'
alias ecmd='powershell "start-process cmd.exe "/k cd /d $(pwd -W)" -verb runas"'
fi
The additional ecmd alias launches an elevated cmd in current directory,
might be useful sometimes,
and it also serves as an example of acquiring UAC elevation through powershell,
if somebody knows how to escape this thing properly,
we can ditch that WSH helper.
add a comment |
MSYS=winsymlinks:nativestrict
requires you to run MSYS2 in elevated mode,
I'm really not comfortable with that.
This script only prompts for UAC elevation when invoked,
of course it won't be useful for scripting then,
but at least it suits my needs:
~/scripts/sh/msys2-ln.sh:
#!/bin/sh
if [ "$#" -eq 2 -a "$1" == "-s" ]; then
TARGET="$2"
LINK=$(basename "$TARGET")
elif [ "$#" -eq 3 -a "$1" == "-s" ]; then
TARGET="$2"
LINK="$3"
else
echo "this weak implementation only supports `ln -s`"
exit
fi
if [ -d "$TARGET" ]; then
MKLINK_OPTS="//d"
fi
TARGET=$(cygpath -w -a "$TARGET")
LINK=$(cygpath -w -a "$LINK")
echo "$TARGET"
echo "$LINK"
cscript //nologo ~/scripts/wsh/run-elevated.js
cmd //c mklink $MKLINK_OPTS "$LINK" "$TARGET"
~/scripts/wsh/run-elevated.js
var args = WScript.Arguments;
if(args.length == 0){
WScript.Echo("nothing to run");
WScript.Quit(0);
}
var quoted_args = ;
for(var i = 1; i < args.length; ++i){
var arg = args(i); // it's a callable, not array like
if(arg.indexOf(" ") != -1){
arg = """ + arg + """;
}
quoted_args.push(arg);
}
var SHAPP = WScript.CreateObject("shell.application");
SHAPP.ShellExecute(args(0), quoted_args.join(" "), "", "runas", 1);
~/.bashrc
# workaround for MSYS2's awkward ln
if [ $- == *i* -a ! -z $MSYSTEM ]; then
alias ln='~/scripts/sh/msys2-ln.sh'
alias ecmd='powershell "start-process cmd.exe "/k cd /d $(pwd -W)" -verb runas"'
fi
The additional ecmd alias launches an elevated cmd in current directory,
might be useful sometimes,
and it also serves as an example of acquiring UAC elevation through powershell,
if somebody knows how to escape this thing properly,
we can ditch that WSH helper.
add a comment |
MSYS=winsymlinks:nativestrict
requires you to run MSYS2 in elevated mode,
I'm really not comfortable with that.
This script only prompts for UAC elevation when invoked,
of course it won't be useful for scripting then,
but at least it suits my needs:
~/scripts/sh/msys2-ln.sh:
#!/bin/sh
if [ "$#" -eq 2 -a "$1" == "-s" ]; then
TARGET="$2"
LINK=$(basename "$TARGET")
elif [ "$#" -eq 3 -a "$1" == "-s" ]; then
TARGET="$2"
LINK="$3"
else
echo "this weak implementation only supports `ln -s`"
exit
fi
if [ -d "$TARGET" ]; then
MKLINK_OPTS="//d"
fi
TARGET=$(cygpath -w -a "$TARGET")
LINK=$(cygpath -w -a "$LINK")
echo "$TARGET"
echo "$LINK"
cscript //nologo ~/scripts/wsh/run-elevated.js
cmd //c mklink $MKLINK_OPTS "$LINK" "$TARGET"
~/scripts/wsh/run-elevated.js
var args = WScript.Arguments;
if(args.length == 0){
WScript.Echo("nothing to run");
WScript.Quit(0);
}
var quoted_args = ;
for(var i = 1; i < args.length; ++i){
var arg = args(i); // it's a callable, not array like
if(arg.indexOf(" ") != -1){
arg = """ + arg + """;
}
quoted_args.push(arg);
}
var SHAPP = WScript.CreateObject("shell.application");
SHAPP.ShellExecute(args(0), quoted_args.join(" "), "", "runas", 1);
~/.bashrc
# workaround for MSYS2's awkward ln
if [ $- == *i* -a ! -z $MSYSTEM ]; then
alias ln='~/scripts/sh/msys2-ln.sh'
alias ecmd='powershell "start-process cmd.exe "/k cd /d $(pwd -W)" -verb runas"'
fi
The additional ecmd alias launches an elevated cmd in current directory,
might be useful sometimes,
and it also serves as an example of acquiring UAC elevation through powershell,
if somebody knows how to escape this thing properly,
we can ditch that WSH helper.
MSYS=winsymlinks:nativestrict
requires you to run MSYS2 in elevated mode,
I'm really not comfortable with that.
This script only prompts for UAC elevation when invoked,
of course it won't be useful for scripting then,
but at least it suits my needs:
~/scripts/sh/msys2-ln.sh:
#!/bin/sh
if [ "$#" -eq 2 -a "$1" == "-s" ]; then
TARGET="$2"
LINK=$(basename "$TARGET")
elif [ "$#" -eq 3 -a "$1" == "-s" ]; then
TARGET="$2"
LINK="$3"
else
echo "this weak implementation only supports `ln -s`"
exit
fi
if [ -d "$TARGET" ]; then
MKLINK_OPTS="//d"
fi
TARGET=$(cygpath -w -a "$TARGET")
LINK=$(cygpath -w -a "$LINK")
echo "$TARGET"
echo "$LINK"
cscript //nologo ~/scripts/wsh/run-elevated.js
cmd //c mklink $MKLINK_OPTS "$LINK" "$TARGET"
~/scripts/wsh/run-elevated.js
var args = WScript.Arguments;
if(args.length == 0){
WScript.Echo("nothing to run");
WScript.Quit(0);
}
var quoted_args = ;
for(var i = 1; i < args.length; ++i){
var arg = args(i); // it's a callable, not array like
if(arg.indexOf(" ") != -1){
arg = """ + arg + """;
}
quoted_args.push(arg);
}
var SHAPP = WScript.CreateObject("shell.application");
SHAPP.ShellExecute(args(0), quoted_args.join(" "), "", "runas", 1);
~/.bashrc
# workaround for MSYS2's awkward ln
if [ $- == *i* -a ! -z $MSYSTEM ]; then
alias ln='~/scripts/sh/msys2-ln.sh'
alias ecmd='powershell "start-process cmd.exe "/k cd /d $(pwd -W)" -verb runas"'
fi
The additional ecmd alias launches an elevated cmd in current directory,
might be useful sometimes,
and it also serves as an example of acquiring UAC elevation through powershell,
if somebody knows how to escape this thing properly,
we can ditch that WSH helper.
edited Aug 25 '17 at 10:23
answered Aug 25 '17 at 10:10
JimmyZJimmyZ
312
312
add a comment |
add a comment |
Windows 10 now supports symbolic links without needing to run as administrator, so long as you turn on developer mode in the Windows settings.
Once that is done, you can get ln
working correctly with a single line in a .bashrc
file in your home directory!
export MSYS=winsymlinks:nativestrict
(I was not able to figure out where the equivalent .ini file is in my Git Bash installation. But setting the environment variable there would probably work, too.)
More details in this very helpful article by Josh Kelley:
https://www.joshkel.com/2018/01/18/symlinks-in-windows/
add a comment |
Windows 10 now supports symbolic links without needing to run as administrator, so long as you turn on developer mode in the Windows settings.
Once that is done, you can get ln
working correctly with a single line in a .bashrc
file in your home directory!
export MSYS=winsymlinks:nativestrict
(I was not able to figure out where the equivalent .ini file is in my Git Bash installation. But setting the environment variable there would probably work, too.)
More details in this very helpful article by Josh Kelley:
https://www.joshkel.com/2018/01/18/symlinks-in-windows/
add a comment |
Windows 10 now supports symbolic links without needing to run as administrator, so long as you turn on developer mode in the Windows settings.
Once that is done, you can get ln
working correctly with a single line in a .bashrc
file in your home directory!
export MSYS=winsymlinks:nativestrict
(I was not able to figure out where the equivalent .ini file is in my Git Bash installation. But setting the environment variable there would probably work, too.)
More details in this very helpful article by Josh Kelley:
https://www.joshkel.com/2018/01/18/symlinks-in-windows/
Windows 10 now supports symbolic links without needing to run as administrator, so long as you turn on developer mode in the Windows settings.
Once that is done, you can get ln
working correctly with a single line in a .bashrc
file in your home directory!
export MSYS=winsymlinks:nativestrict
(I was not able to figure out where the equivalent .ini file is in my Git Bash installation. But setting the environment variable there would probably work, too.)
More details in this very helpful article by Josh Kelley:
https://www.joshkel.com/2018/01/18/symlinks-in-windows/
answered Jan 31 at 0:55
AmeliaBRAmeliaBR
1112
1112
add a comment |
add a comment |
Thanks for contributing an answer to Super User!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f550732%2fuse-mklink-in-msys%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown