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:
Allan Odgaard
2013-09-24 21:33:30 +02:00
parent 40233245e2
commit 4363a27897

View File

@@ -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()))