1#!
2#[[BEGIN PROPERTIES]]
3# Type = Command
4# Order = 10.0
5# Interpreter = perl
6# Caption = Sym Link
7# Descr =Create symbolic links to files and/or directories. The symbolic
8# Descr =links get the same names as the originals.
9# Descr =
10# Descr =Selection details:
11# Descr =
12# Descr =  Source: The files and directories to which the symbolic links
13# Descr =          shall point.
14# Descr =
15# Descr =  Target: The directory in which the symbolic links shall be
16# Descr =          created.
17# Icon = sym_link.tga
18# Hotkey = Ctrl+L
19#[[END PROPERTIES]]
20
21use strict;
22use warnings;
23BEGIN { require "$ENV{'EM_DIR'}/res/emFileMan/scripts/cmd-util.pl"; }
24
25if (IsFirstPass()) {
26
27	ErrorIfNoSources();
28	ErrorIfNotSingleTarget();
29	ErrorIfTargetsNotDirs();
30
31	ConfirmIfSourcesAcrossDirs();
32
33	my $message=
34		"Are you sure to create symbolic link(s):\n".
35		"\n".
36		"To:\n".
37		GetSrcListing().
38		"\n".
39		"In:\n".
40		GetTgtListing()
41	;
42	Confirm("Sym Link",$message);
43
44	SecondPassInTerminal("Sym Link");
45}
46
47my @src=GetSrc();
48my @tgt=GetTgt();
49
50my $e=TermRunAndSync(
51	"ln",
52	($Config{'osname'} eq 'linux' or $Config{'osname'} eq 'cygwin') ? (
53		"-vs"
54	)
55	: (
56		"-s"
57	),
58	"--",
59	@src,
60	$tgt[0]
61);
62
63my @newTgt=();
64for (my $i=0; $i<@src; $i++) {
65	my $f=fileparse($src[$i]);
66	my $p=catfile($tgt[0],$f);
67	if (-e $p) {
68		push(@newTgt,$p);
69	}
70}
71if (@newTgt > 0) {
72	SendSelectKS(@newTgt);
73}
74else {
75	SendUpdate();
76}
77
78TermEnd($e);
79