代码拉取完成,页面将自动刷新
/** ------------------------------------------------------------
* File Name : ruby.d
* File Authors : Aoran Zeng <ccmywish@qq.com>
* Created On : <2023-02-11>
* Last Modified : <2024-09-02>
*
* ruby:
*
* 1. Cheat starship/oh-my-posh to get version info
* 2. Get correct version info for rbenv commands
* 3. Invoke the real ruby.exe
* ------------------------------------------------------------*/
import std.stdio;
import std.process : environment;
import std.file : getcwd;
import std.algorithm : canFind;
import std.process : spawnShell, wait, Config;
import std.array;
import rbenv.common;
// Written in the D programming language.
// --------------------------------------------------------------
string[] versionOptions = ["-v", "--version"];
int main(string[] args) {
auto arg_len = args.length;
VersionSetInfo vsi;
vsi = get_current_version_with_setmsg();
string pwd = getcwd();
if ("" == vsi.ver) {
// The last valid version to check is the global version, we've warned already
// warn("rbenv: No valid version has been set");
return -1;
}
// When user only input '-v' or '--version'
// we suppress invocation of real ruby.exe
// This supports starship/oh-my-posh to get answer more quickly
if(arg_len == 2 && versionOptions.canFind(args[1])) {
writeln("ruby ", vsi.ver, " ", vsi.setmsg);
return 0;
}
string[] escape_args = [];
foreach (arg; args) {
if (arg.canFind(" ")) {
escape_args ~= "\"" ~ arg ~ "\"";
} else if (""==arg) { // ruby -e ""
escape_args ~= `""`;
} else {
escape_args ~= arg;
}
}
string rubyexe = get_bin_path_for_version(vsi.ver) ~ "\\ruby.exe";
string shellcmd = join(rubyexe ~ escape_args[1..$], " ");
// writeln(shellcmd);
auto pid = spawnShell(shellcmd, // must be a string, rather than string array
null, // env
Config.none, // config
pwd // workDir
);
return wait(pid);
return 0;
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。