Debian Codegraph @

CodeLite/clConsoleBash.cpp

raw
1 #include "clConsoleBash.h"
2 #include "cl_standard_paths.h"
3 #include "fileutils.h"
4 #include <wx/arrstr.h>
5 #include <wx/utils.h>
6
7 clConsoleBash::clConsoleBash() {}
8
9 clConsoleBash::~clConsoleBash() {}
10
11 wxFileName clConsoleBash::PrepareExecScript() const
12 {
13 // Create a script
14 #ifdef __WXOSX__
15 wxFileName scriptPath("/tmp", "codelite-exec.sh");
16 #else
17 wxFileName scriptPath(clStandardPaths::Get().GetUserDataDir(), "codelite-exec.sh");
18 scriptPath.AppendDir("tmp");
19 scriptPath.AppendDir(::wxGetUserId());
20 scriptPath.Mkdir(wxS_DIR_DEFAULT, wxPATH_MKDIR_FULL);
21 #endif
22
23 if(!GetCommand().IsEmpty()) {
24 wxString fileContent;
25 fileContent << "#!/bin/bash\n";
26 fileContent << "command=\"" << GetCommand() << "\"\n";
27 wxString cdCommand;
28 #ifdef __WXOSX__
29 // on OSX, we need to set the working directory via the script
30 if(!GetWorkingDirectory().IsEmpty()) {
31 wxString workingDir = GetWorkingDirectory();
32 if(workingDir.Contains(" ")) {
33 workingDir.Prepend("\"").Append("\"");
34 }
35 cdCommand << "cd " << workingDir << " && ";
36 }
37 #endif
38 if(!GetCommandArgs().IsEmpty()) {
39 // Split the arguments line
40 wxArrayString arr = SplitArguments(GetCommandArgs());
41 // Create an array in the script
42 for(size_t i = 0; i < arr.size(); ++i) {
43 fileContent << "args[" << i << "]=\"" << arr[i] << "\"\n";
44 }
45 fileContent << cdCommand << "\"${command}\" \"${args[@]}\"\n";
46 } else {
47 fileContent << cdCommand << "\"${command}\"\n";
48 }
49 if(IsWaitWhenDone()) {
50 fileContent << "echo Hit any key to continue...\nread";
51 }
52 FileUtils::WriteFileContent(scriptPath, fileContent);
53 }
54 #ifdef __WXOSX__
55 // The script must have exec permissions
56 system("chmod +x /tmp/codelite-exec.sh");
57 #endif
58 return scriptPath;
59 }