-
Notifications
You must be signed in to change notification settings - Fork 11
/
magento-cd
executable file
·163 lines (142 loc) · 4.7 KB
/
magento-cd
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
#!/usr/bin/env php
<?php
//
// Go somewhere in the current Magento installation.
//
// @author Joseph Mastey <joseph.mastey@gmail.com>
// @author $Author$
// @version $Id$
// @copyright Copyright (c) JRM Ventures LLC, 2010-
try {
require_once("lib/base.php");
require_once("$support_dir/cd-paths.php");
require_once("$support_dir/defaults.php");
} catch( Exception $e ) {
require_once("$support_dir/cd-paths.php");
require_once("$support_dir/defaults.php");
$magento = $default_path;
$theme = trim(`cd $default_path; magento-theme`);
}
if(2 != $server->argc) {
print_error("Usage: magento-cd %somepath%\n");
print `pwd`;
exit;
}
$target = $server->argv[1];
// it's a project!
if(is_array($project_paths) && count($project_paths)) {
foreach($project_paths as $path) {
if(file_exists("$path/$target") and is_dir("$path/$target")) {
print_error("Zing! Advancing to project $target.\n");
print "$path/$target";
exit;
}
}
}
// it's a developer specified shortcut!
if(isset($cd_paths[$target])) {
if(!isset($theme)) { $theme = trim(`magento-theme`); }
$edition = get_edition();
if(0 == strcmp($edition, "community")) {
$package = "default";
} else {
$package = $edition;
}
$path = str_replace(array(
"%magento%", "%theme%", "%edition%", "%edition_package%",
), array(
$magento, $theme, $edition, $package,
), $cd_paths[$target]);
print_error("Zap! Teleported to $target.\n");
print "$path";
exit;
}
// it's a module handle!
try {
$target_path = module_path($target);
print_error("Whiz! Going to module $target.\n");
print "$magento/app/code/$target_path";
exit;
} catch( Exception $e ) {
// it wasn't a module name. keep moving.
}
// it's a company handle!
try {
$target_path = company_path($target);
print_error("Bang! You're at company dir $target.\n");
print "$magento/app/code/$target_path";
exit;
} catch( Exception $e ) {
// it wasn't a company handle. keep moving.
}
// it's a model handle!
try {
$target_path = handle_to_path($target, "model");
$filename = handle_to_file($target, "model");
if(!file_exists("$target_path/$filename")) {
throw new Exception("It's a fake! Bail!");
}
print_error("Get thee to model $target.\n");
print "$target_path";
exit;
} catch( Exception $e ) {
// it wasn't a model handle. keep moving.
}
// it's a block handle!
try {
$target_path = handle_to_path($target, "block");
$filename = handle_to_file($target, "block");
if(!file_exists("$target_path/$filename")) {
throw new Exception("It's a fake! Bail!");
}
print_error("Kapow! You're at block $target.\n");
print "$target_path";
exit;
} catch( Exception $e ) {
// it wasn't a model handle. keep moving.
}
// it's a really poorly typed module handle!
try {
$target_path = fuzzy_module_path($target);
print_error("Buh? Headed to FAKE local module '$target'. Put a little more effort in next time.\n");
print "$magento/app/code/$target_path";
exit;
} catch( Exception $e ) {
// it wasn't a poorly typed module name. keep moving.
}
// it's a really, incredibly sloppy file path...
try {
if(!preg_match("#([a-zA-Z]+[_\ \\\\/]+)+#", $target)) {
throw new Exception("doesn't look right.");
}
$modpath = str_replace(array("_", " ", "\\"), "/", $target);
$target_paths = horrible_path($modpath);
print_error("You've got to be kidding... That's not even a real thing.\n");
if(count($target_paths) > 1) {
print_error("For future reference, here are some real things:\n");
foreach($target_paths as $path) {
print_error(" $path\n");
}
}
print array_shift($target_paths);
exit;
} catch( Exception $e ) {
// what in the world?
}
print_error("Couldn't figure out where $target is. Meditate on uncertainty and try again.\n");
print `pwd`;
function putdocs() {
global $support_dir;
require_once("$support_dir/cd-paths.php");
return array(
"Load a path in the current Magento installation. Use tab completion to see available paths.",
"Usage: mcd SHORTCUT", "",
"Shortcuts may be specified in data/cd-paths, or can be one of the following:",
"* A project in the project-dir specified in your profile\n\t(project -> /var/www/project)",
"* A complete module name\n\t(core -> app/code/core/Mage/Core, loaded from [core,community,local])",
"* A partial module name from the local codepool\n\t(foo -> app/code/local/Company/FooBarModule)",
"* A class handle for a block, model or helper\n\t(core/template -> app/code/core/Mage/Core/Block)",
"* An incredibly lazily typed path inside of app/code\n\t(sales/order/pdf -> app/code/core/Mage/Sales/Order/Pdf)",
"", "Known Shortcuts:",
) + array_keys($cd_paths);
}