mirror of
https://github.com/textmate/textmate.git
synced 2026-04-28 03:00:34 -04:00
Source bash_init.sh for code in snippets that have no shebang
This is consistent with TextMate 1.x behavior. Fixes ruby.tmbundle#56
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
#include "transform.h"
|
||||
#include "indent.h"
|
||||
#include <bundles/bundles.h>
|
||||
#include <command/runner.h>
|
||||
#include <text/case.h>
|
||||
#include <text/ctype.h>
|
||||
#include <text/classification.h>
|
||||
@@ -376,16 +377,14 @@ namespace ng
|
||||
__block int status = 0;
|
||||
__block std::string output, error;
|
||||
|
||||
std::string scriptPath = NULL_STR;
|
||||
std::vector<std::string> argv{ "/bin/sh", "-c", cmd };
|
||||
if(cmd.substr(0, 2) == "#!")
|
||||
{
|
||||
argv = { scriptPath = path::temp("snippet_command") };
|
||||
path::set_content(scriptPath, cmd);
|
||||
chmod(scriptPath.c_str(), S_IRWXU);
|
||||
}
|
||||
std::string script = cmd;
|
||||
command::fix_shebang(&script);
|
||||
|
||||
if(io::process_t process = io::spawn(argv, environment))
|
||||
std::string scriptPath = path::temp("snippet_command");
|
||||
path::set_content(scriptPath, script);
|
||||
chmod(scriptPath.c_str(), S_IRWXU);
|
||||
|
||||
if(io::process_t process = io::spawn(std::vector<std::string>{ scriptPath }, environment))
|
||||
{
|
||||
close(process.in);
|
||||
|
||||
@@ -404,8 +403,7 @@ namespace ng
|
||||
dispatch_release(group);
|
||||
}
|
||||
|
||||
if(scriptPath != NULL_STR)
|
||||
unlink(scriptPath.c_str());
|
||||
unlink(scriptPath.c_str());
|
||||
|
||||
std::string const& res = WIFEXITED(status) && WEXITSTATUS(status) == 0 ? output : error;
|
||||
if(!utf8::is_valid(res.begin(), res.end()))
|
||||
|
||||
Reference in New Issue
Block a user