-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathx-cmd.bat
80 lines (62 loc) · 2.95 KB
/
x-cmd.bat
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
@echo off
setlocal
REM Copyright 2022-? Li Junhao ([email protected]). Licensed under the GNU AFFERO GENERAL PUBLIC LICENSE, Version 3.
echo INFO: Check if Git-For-Windows is installed
set gitbash=%USERPROFILE%\.x-cmd.root\data\git-for-windows\bin\bash.exe
if EXIST "%gitbash%" goto :start-git-bash
set gitbash=%PROGRAMFILES%\Git\bin\bash.exe
if EXIST "%gitbash%" goto :start-git-bash
set gitbash=%USERPROFILE%\scoop\apps\git\current\bin\bash.exe
if EXIST "%gitbash%" goto :start-git-bash
set gitbash=%USERPROFILE%\AppData\Local\Programs\Git\bin\bash.exe
if EXIST "%gitbash%" goto :start-git-bash
set gitbash=git-bash
where.exe "%gitbash%" >nul 2>&1
if %errorlevel% == 0 goto :start-git-bash
if EXIST %USERPROFILE%\.x-cmd.root\data\git-for-windows goto :init
echo INFO: create directory to place git-for-windows -- %USERPROFILE%\.x-cmd.root\data\git-for-windows
mkdir %USERPROFILE%\.x-cmd.root\data\git-for-windows
:init
echo INFO: cd into %USERPROFILE%\.x-cmd.root\data\git-for-windows
set gitbash=%USERPROFILE%\.x-cmd.root\data\git-for-windows\bin\bash.exe
cd /d %USERPROFILE%\.x-cmd.root\data\git-for-windows
echo .
echo --------------------------------------------------------------------------------------------------------
echo STEP 1: Download git-for-windows to %USERPROFILE%\.x-cmd.root\data\git-for-windows
echo --------------------------------------------------------------------------------------------------------
echo .
curl -L -o git-for-windows.7z.exe https://github.com/x-cmd-build/git-for-windows/releases/download/v2.47.0/git-for-windows.7z.exe
if %errorlevel% equ 0 goto :install
echo ERROR: Download failure. Press any key to exit.
pause
exit 1
:install
echo .
echo --------------------------------------------------------------------------------------------------------
echo STEP 2: Install git-for-windows. It might take a few minutes. Don't close this window.
echo --------------------------------------------------------------------------------------------------------
echo .
git-for-windows.7z.exe -y
if %errorlevel% equ 0 goto :robocopy
@echo ERROR: Installation failure. Press any key to exit.
pause
exit 1
:robocopy
echo .
echo --------------------------------------------------------------------------------------------------------
echo STEP 3: Using robocopy to relocate the git-for-windows folder
echo --------------------------------------------------------------------------------------------------------
echo .
robocopy PortableGit %cd% /E /MOVE /np /nfl /ndl /njh /njs
if EXIST "%gitbash%" goto :start-git-bash
echo ERROR: Fail to install git-for-windows. Press any key to exit.
exit 1
:start-git-bash
echo INFO: start git-bash "%gitbash%"
if NOT EXIST "%USERPROFILE%\.x-cmd.root\X" (
echo INFO: x-cmd init
echo [ -f "$HOME/.x-cmd.root/X" ] ^|^| eval "$(curl https://get.x-cmd.com)" >%USERPROFILE%\.x-cmd.init.bash
"%gitbash%" %USERPROFILE%\.x-cmd.init.bash
del %USERPROFILE%\.x-cmd.init.bash
)
"%gitbash%" %*