-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathConfigureiTerm2.php
96 lines (70 loc) · 2.49 KB
/
ConfigureiTerm2.php
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
<?php
namespace App\Commands;
use Illuminate\Support\Facades\File;
use ZipArchive;
class ConfigureiTerm2 extends StepCommand
{
/**
* The signature of the command.
*
* @var string
*/
protected $signature = 'configure:iterm2';
/**
* The description of the command.
*
* @var string
*/
protected $description = 'Install the Python API for iTerm2.';
protected static $packageName = 'iterm2env';
/**
* Execute the console command.
*
* @return void
*/
public function handle()
{
// Get manifest...
$this->comment('Downloading python for iTerm2...');
$manifest = json_decode(file_get_contents('https://iterm2.com/downloads/pyenv/manifest.json'), true);
// Download file locally.
$url = $manifest[0]['url'];
$tempFolder = storage_path('tmp');
$path = $tempFolder.'/env.zip';
if (File::isDirectory($tempFolder)) {
File::deleteDirectory($tempFolder);
}
File::makeDirectory($tempFolder);
$remote_file_contents = file_get_contents($url);
file_put_contents($path, $remote_file_contents);
// Unzip
$this->comment('Unzipping package...');
$zipArchive = new ZipArchive();
if ($zipArchive->open($path)) {
$zipArchive->extractTo($tempFolder);
$zipArchive->close();
// Delete the zip file.
File::delete($path);
$sourceFolder = $tempFolder.'/'.static::$packageName;
// Move files.
$versions = $manifest[0]['python_versions'];
$versions[] = '';
foreach ($versions as $version) {
$folder = static::$packageName;
if (strlen($version) > 0) {
$folder .= '-'.$version;
}
$destinationFolder = $this->homePath('Library/ApplicationSupport/iTerm2/'.$folder);
$this->comment("Moving package to: $destinationFolder");
$this->terminal()->output($this)->with([
'source' => $sourceFolder.'/',
'destination' => $destinationFolder,
])->run('rsync --progress --stats --human-readable --recursive --timeout=300 {{ $source }} {{ $destination }}');
}
// Cleanup
$this->comment('Cleaning up...');
File::deleteDirectory($tempFolder);
}
$this->line('python for iTerm2 installed.');
}
}