Skip to content

Commit a2f3e72

Browse files
Fatme HavaluovaFatme Havaluova
Fatme Havaluova
authored and
Fatme Havaluova
committed
Share autocompletion code
1 parent 484e793 commit a2f3e72

File tree

2 files changed

+4
-76
lines changed

2 files changed

+4
-76
lines changed

lib/commands/post-install.ts

Lines changed: 3 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,9 @@ import path = require("path");
55
import util = require("util");
66

77
export class PostInstallCommand implements ICommand {
8-
private static CALL_PROFILE_SCRIPT =
9-
"if [ -f ~/.profile ]; then\n" +
10-
" . ~/.profile\n" +
11-
"fi\n";
128

13-
constructor(private $fs: IFileSystem,
14-
private $childProcess: IChildProcess,
15-
private $logger: ILogger,
9+
constructor(private $autocompletionService: IAutoCompletionService,
10+
private $fs: IFileSystem,
1611
private $staticConfig: IStaticConfig) { }
1712

1813
public disableAnalytics = true;
@@ -23,74 +18,7 @@ export class PostInstallCommand implements ICommand {
2318
this.$fs.chmod(this.$staticConfig.adbFilePath, "0777").wait();
2419
}
2520

26-
this.enableAutoCompletion().wait();
27-
}).future<void>()();
28-
}
29-
30-
private enableAutoCompletion(): IFuture<void> {
31-
return (() => {
32-
var scriptsOk = true;
33-
34-
try {
35-
this.updateShellScript(".profile").wait();
36-
this.updateShellScript(".bashrc").wait();
37-
38-
this.updateBashProfile().wait();
39-
40-
// zsh - http://www.acm.uiuc.edu/workshops/zsh/startup_files.html
41-
this.updateShellScript(".zshrc").wait();
42-
} catch(err) {
43-
this.$logger.out("Failed to update all shell start-up scripts. Auto-completion may not work. " + err);
44-
scriptsOk = false;
45-
}
46-
47-
if(scriptsOk) {
48-
this.$logger.out("Restart your shell to enable command auto-completion.");
49-
}
50-
}).future<void>()();
51-
}
52-
53-
private updateShellScript(fileName: string): IFuture<void> {
54-
return (() => {
55-
var filePath = this.getHomePath(fileName);
56-
57-
var doUpdate = true;
58-
if (this.$fs.exists(filePath).wait()) {
59-
var contents = this.$fs.readText(filePath).wait();
60-
if (contents.match(/nativescript\s+completion\s+--\s+/) || contents.match(/tns\s+completion\s+--\s+/)) {
61-
doUpdate = false;
62-
}
63-
}
64-
65-
if(doUpdate) {
66-
this.updateShellScriptCore(filePath).wait();
67-
}
68-
69-
}).future<void>()();
70-
}
71-
72-
private updateShellScriptCore(filePath: string): IFuture<void> {
73-
return (() => {
74-
this.$childProcess.exec("nativescript completion >> " + filePath).wait();
75-
}).future<void>()();
76-
}
77-
78-
private getHomePath(fileName: string): string {
79-
return path.join(osenv.home(), fileName);
80-
}
81-
82-
private updateBashProfile(): IFuture<void> {
83-
return (() => {
84-
var bashProfileFileName = this.getHomePath(".bash_profile");
85-
if (this.$fs.exists(bashProfileFileName).wait()) {
86-
var contens = this.$fs.readText(bashProfileFileName).wait();
87-
if (contens.indexOf(PostInstallCommand.CALL_PROFILE_SCRIPT) < 0) {
88-
this.updateShellScript(".bash_profile");
89-
}
90-
} else {
91-
this.$fs.writeFile(bashProfileFileName, PostInstallCommand.CALL_PROFILE_SCRIPT).wait();
92-
this.updateShellScriptCore(bashProfileFileName).wait();
93-
}
21+
this.$autocompletionService.enableAutoCompletion().wait();
9422
}).future<void>()();
9523
}
9624
}

0 commit comments

Comments
 (0)