-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmate
More file actions
executable file
·83 lines (69 loc) · 1.76 KB
/
mate
File metadata and controls
executable file
·83 lines (69 loc) · 1.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/usr/bin/env perl
#
# Updated 2010-04-21 Jay Levitt
# Originally borrowed from
# http://snippets.dzone.com/posts/show/510
# and
# http://groups.google.com/group/comp.unix.shell/msg/77af5d0e339d0006
# and
# http://forum.slicehost.com/comments.php?DiscussionID=1090
#
# Add to your Mac's ~/.ssh/config:
# RemoteForward 10022 localhost:22
#
# TODO: Check for MATE_PORT variable to override port 10022, so
# multiple clients can do this simultaneously
#
# TODO: Store mount, app, user in Mac environment and pass them via
# .ssh/environment (or some other way that works on machines with
# PermitUserEnvironment=No).
use warnings;
use strict;
use English '-no_match_vars';
use Cwd 'abs_path';
use Getopt::Long;
# Customize these:
my $mac_mount = '/Volumes/remote-mounted';
my $mac_app = "/Applications/TextMate.app";
my $mac_user = 'jay';
my $debug = '';
my $tunnel = 'y';
my $wait = '';
GetOptions (
'debug' => \$debug,
'tunnel!' => \$tunnel,
'wait|w' => \$wait
);
my $mac_ip;
my $mac_port;
if ($tunnel) {
$mac_ip = "localhost";
$mac_port = 10022;
} else {
my @ssh_from = split(/ /,$ENV{'SSH_CLIENT'});
$mac_ip = $ssh_from[0];
$mac_port = 22;
}
my $file = abs_path(${ARGV[0]});
print "Opening '$file'...\n";
unless (-e $file) {
print "create $file? [Yn] ";
chomp (my $do_create = <STDIN>);
unless (($do_create eq "Y") || ($do_create eq "y") || ($do_create eq "")) {
exit;
}
`touch $file`;
}
unless (-e $file) {
print "Couldn't create $file!\n";
exit;
}
my $command = "ssh ${mac_user}\@${mac_ip} -p ${mac_port} \"open -a ${mac_app} ${mac_mount}${file}; exit\"";
if ($debug) {
print $command . "\n";
}
`$command`;
if ($wait || $PROGRAM_NAME =~ /mate_wait/ ) {
print "Press ENTER when done: ";
my $waiting = <STDIN>;
}