Last active
September 2, 2024 16:37
-
-
Save danny8376/be9b45c7077fc7cb8ddec996e1af1178 to your computer and use it in GitHub Desktop.
rbenv for Windows helper stuff
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if [[ -z "$RBENV_INIT" ]]; then | |
export RBENV_SYSTEM_RUBY=$( powershell -Command '& {& "$env:RBENV_ROOT\rbenv\bin\rbenv.ps1" init *> $null ; echo $env:RBENV_SYSTEM_RUBY}' ) | |
export PATH="$RBENV_ROOT/rbenv/bin":"$RBENV_ROOT/shims":$PATH | |
if [[ -n "$RUBYLIB" ]]; then | |
export RUBYLIB="$RUBYLIB":"$RBENV_ROOT/rbenv/share" | |
else | |
export RUBYLIB="$RBENV_ROOT/rbenv/share" | |
fi | |
export RBENV_INIT=1 | |
fi | |
rbenv() { | |
local cmd=$1 | |
shift | |
case $cmd in | |
shell) | |
if [[ -z "$1" ]]; then | |
powershell "$RBENV_ROOT\\rbenv\\bin\\rbenv.ps1" help $cmd | |
elif [[ "$1" = "-" ]] || [[ "$1" = "--unset" ]]; then | |
# need to remove path if actually update PATH | |
unset RBENV_VERSION | |
else | |
# need to unset then set if actually update PATH | |
version=$( unset RBENV_VERSION ; powershell -Command '& {& "$env:RBENV_ROOT\rbenv\bin\rbenv.ps1" shell ' $1 ' *> $null ; echo $env:RBENV_VERSION}' ) | |
if [[ -n "$version" ]]; then | |
export RBENV_VERSION=$version | |
# maybe need to update PATH? | |
else | |
echo "rbenv: version $1 not installed" >&2 | |
fi | |
fi | |
;; | |
*) | |
powershell "$RBENV_ROOT\\rbenv\\bin\\rbenv.ps1" $cmd "$@" | |
;; | |
esac | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// gcc ruby.c -lshlwapi -o ruby.exe | |
#include <limits.h> | |
#include <Windows.h> | |
#include <shlwapi.h> | |
#include <strsafe.h> | |
#include <stdio.h> | |
#define ARG_MAX 32767 | |
int main (int argc, char *argv[]) { | |
wchar_t root[PATH_MAX]; | |
if (GetEnvironmentVariableW(L"RUBY_ROOT", root, PATH_MAX) == 0) { | |
printf("No RUBY_ROOT set!\n"); | |
return 1; | |
} | |
wchar_t exe[PATH_MAX]; | |
if (PathCombineW(exe, root, L"bin\\ruby.exe") == NULL) { | |
printf("PathCombine failed!\n"); | |
return 2; | |
} | |
LPWSTR cmdline = GetCommandLineW(); | |
int i; | |
for(i=0; i < wcslen(cmdline) && cmdline[i] != ' '; i++); | |
wchar_t* args = cmdline + i + 1; | |
wchar_t newline[ARG_MAX]; | |
if (FAILED(StringCchCopyW(newline, ARG_MAX, exe))) { | |
printf("StringCchCopy failed!\n"); | |
return 2; | |
} | |
if (FAILED(StringCchCatW(newline, ARG_MAX, L" "))) { | |
printf("StringCchCat failed!\n"); | |
return 2; | |
} | |
if (FAILED(StringCchCatW(newline, ARG_MAX, args))) { | |
printf("StringCchCat failed!\n"); | |
return 2; | |
} | |
STARTUPINFOW si; | |
PROCESS_INFORMATION pi; | |
ZeroMemory(&si, sizeof(si)); | |
si.cb = sizeof(si); | |
ZeroMemory(&pi, sizeof(pi)); | |
if (!CreateProcessW(NULL, newline, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi)) { | |
printf("CreateProcess failed!\n"); | |
return 2; | |
} | |
WaitForSingleObject(pi.hProcess, INFINITE); | |
CloseHandle(pi.hProcess); | |
CloseHandle(pi.hThread); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment