blob: 822bf3f1436886f9c8c383505e3c71022ed023ec [file] [log] [blame]
Bram Moolenaar071d4272004-06-13 20:20:40 +00001:: Start Vim on a copy of the tutor file.
2@echo off
RestorerZe7ea4ba2024-12-02 20:07:58 +01003SetLocal
Bram Moolenaar071d4272004-06-13 20:20:40 +00004
RestorerZe7ea4ba2024-12-02 20:07:58 +01005:: Usage:
6:: vimtutor [/?|{/ | -}h|{/ | --}help] [{/ | -}c|{/ | --}chapter NUMBER] [{/ | --}console] [xx]
Bram Moolenaar071d4272004-06-13 20:20:40 +00007::
8:: -console means gvim will not be used
9:: xx is a language code like "es" or "nl".
10:: When an xx argument is given, it tries loading that tutor.
11:: When this fails or no xx argument was given, it tries using 'v:lang'
12:: When that also fails, it uses the English version.
13
14:: Use Vim to copy the tutor, it knows the value of $VIMRUNTIME
Christian Brabandt7841ca12025-06-16 19:48:03 +020015for %%G in (%TMP% %TEMP% .) do (
RestorerZe7ea4ba2024-12-02 20:07:58 +010016 call :TestDirWritable "%~f0" %%G
17 if not ERRORLEVEL 1 goto DirOk
Bram Moolenaar37f471d2020-03-19 17:13:40 +010018)
19
RestorerZe7ea4ba2024-12-02 20:07:58 +010020echo:
21echo:No working directory is found.
22goto End
Bram Moolenaar37f471d2020-03-19 17:13:40 +010023
RestorerZe7ea4ba2024-12-02 20:07:58 +010024:TestDirWritable
25set TUTORCOPY=%2\$tutor$
Christian Brabandt7841ca12025-06-16 19:48:03 +020026copy %1 %TUTORCOPY% >nul 2>&1
RestorerZe7ea4ba2024-12-02 20:07:58 +010027goto DelTmpCopy
Bram Moolenaar37f471d2020-03-19 17:13:40 +010028
RestorerZe7ea4ba2024-12-02 20:07:58 +010029:DirOk
30title Tutorial on the Vim editor
31set "use=Gui"
Bram Moolenaar071d4272004-06-13 20:20:40 +000032
RestorerZe7ea4ba2024-12-02 20:07:58 +010033for /F "usebackq tokens=2 delims=:" %%G in (`chcp`) do (
34 set /a "_sav_chcp=%%G"
35 1> nul chcp 65001
Paul Desmond Parker17c71da2024-11-03 20:47:53 +010036)
Bram Moolenaar071d4272004-06-13 20:20:40 +000037
RestorerZe7ea4ba2024-12-02 20:07:58 +010038:GetChptLngs
39for %%G in (tutor1;tutor2) do (
Damien Lejay8d9d2b22025-06-22 19:39:04 +020040 if exist "%~dp0tutor\%%G" (set "lngs_%%G=en;")
41 for /F "tokens=2 delims=." %%H in (
42 '2^> nul dir /B /A:-D "%~dp0tutor\%%G.???" "%~dp0tutor\%%G.??_??"') do (
43 call set "lngs_%%G=%%lngs_%%G%%%%H;"
44 )
RestorerZe7ea4ba2024-12-02 20:07:58 +010045)
46:EndGetChptLngs
Bram Moolenaar071d4272004-06-13 20:20:40 +000047
RestorerZe7ea4ba2024-12-02 20:07:58 +010048:ParseArgs
49if "%*"=="" goto Use%use%
50if "%1"=="/?" goto Usage
51if "%1"=="/h" goto Usage
52if "%1"=="-h" goto Usage
53if "%1"=="/help" goto Usage
54if "%1"=="--help" goto Usage
55if "%1"=="/list" goto List
56if "%1"=="--list" goto List
57:DoShift
58if "%1"=="/c" (call :ChkChpt %2 && (shift & shift & goto DoShift) || goto End)
59if "%1"=="-c" (call :ChkChpt %2 && (shift & shift & goto DoShift) || goto End)
60if "%1"=="/chapter" (
61 call :ChkChpt %2 && (shift & shift & goto DoShift) || goto End
62)
63if "%1"=="--chapter" (
64 call :ChkChpt %2 && (shift & shift & goto DoShift) || goto End
65)
66if "%1"=="/console" (set "use=Vim" & shift & goto DoShift)
67if "%1"=="--console" (set "use=Vim" & shift & goto DoShift)
68call :ChkLng %1 && shift || goto End
69if not "%1"=="" goto DoShift
70goto Use%use%
71
72:UseGui
Bram Moolenaar071d4272004-06-13 20:20:40 +000073:: Try making a copy of tutor with gvim. If gvim cannot be found, try using
74:: vim instead. If vim cannot be found, alert user to check environment and
75:: installation.
76
77:: The script tutor.vim tells Vim which file to copy.
RestorerZe7ea4ba2024-12-02 20:07:58 +010078start "dummy" /B /W "%~dp0gvim.exe" -u NONE -c "so $VIMRUNTIME/tutor/tutor.vim"
79if ERRORLEVEL 1 goto UseVim
Bram Moolenaar071d4272004-06-13 20:20:40 +000080
RestorerZe7ea4ba2024-12-02 20:07:58 +010081:: Start gvim without any .vimrc, set 'nocompatible' and 'showcmd'
82start "dummy" /B /W "%~dp0gvim.exe" -u NONE -c "set nocp sc" %TUTORCOPY%
Bram Moolenaar071d4272004-06-13 20:20:40 +000083
RestorerZe7ea4ba2024-12-02 20:07:58 +010084goto End
Bram Moolenaar071d4272004-06-13 20:20:40 +000085
RestorerZe7ea4ba2024-12-02 20:07:58 +010086:UseVim
Bram Moolenaar071d4272004-06-13 20:20:40 +000087:: The script tutor.vim tells Vim which file to copy
RestorerZe7ea4ba2024-12-02 20:07:58 +010088call "%~dp0vim.exe" -u NONE -c "so $VIMRUNTIME/tutor/tutor.vim"
89if ERRORLEVEL 1 goto NoExecutable
Bram Moolenaar071d4272004-06-13 20:20:40 +000090
Damien Lejay8d9d2b22025-06-22 19:39:04 +020091:: Start vim without any .vimrc, set 'nocompatible' and 'showcmd'
RestorerZe7ea4ba2024-12-02 20:07:58 +010092call "%~dp0vim.exe" -u NONE -c "set nocp sc" %TUTORCOPY%
Bram Moolenaar071d4272004-06-13 20:20:40 +000093
RestorerZe7ea4ba2024-12-02 20:07:58 +010094goto End
Bram Moolenaar071d4272004-06-13 20:20:40 +000095
RestorerZe7ea4ba2024-12-02 20:07:58 +010096:NoExecutable
97echo:
98echo:
99echo:No vim or gvim found in current directory or %%PATH%%.
100echo:Check your installation or re-run install.exe.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000101
RestorerZe7ea4ba2024-12-02 20:07:58 +0100102goto End
103
104:ChkChpt
105if defined CHAPTER (
106 echo:Error. Invalid command line arguments.
107 echo:See %~nx0 /? for help.
108 exit /B 1
109)
110for /F %%G in ('echo %1 ^| findstr /R "\<[1-2]\>"') do (
111 set "CHAPTER=%%G" & exit /B 0
112)
113echo:Error. The chapter argument must contain only the digits 1 or 2.
114exit /B 1
115
116:ChkLng
117if "%1"=="" exit /B 0
118if defined xx (
119 echo:Error. Invalid command line arguments.
120 echo:See %~nx0 /? for help.
121 exit /B 1
122)
123for /F %%G in ('echo %1 ^| findstr /R "[-0-9\._\[\]\$\^\*/!@#&(|)=+\\]"') do (
124 echo:Error. The language code must contain only alphabetic characters.
125 exit /B 1
126)
127set "_t=%1"
128if ""=="%_t:~1%" (
129 echo:Error. The language code must be 2 or 3 characters only.
130 exit /B 1
131)
132if not ""=="%_t:~3%" (
133 echo:Error. The language code must be 2 or 3 characters only.
134 exit /B 1
135)
136SetLocal EnableDelayedExpansion
137if "!lngs_tutor%CHAPTER%:%1;=!"=="!lngs_tutor%CHAPTER%!" (
138 echo:The current installation does not have the %1 language.
139 echo:English will be used for the tutorial.
140 echo:To view the available languages, use the `%~nx0 /list` command.
141 1> nul timeout /T 2
142 EndLocal & set "xx=en" & exit /B 0
143) else (EndLocal & set "xx=%1" & exit /B 0)
144
145:Usage
146echo:
147echo:== USAGE =================================================================
148echo:
149echo:%~nx0 /? ^| ^{/ ^| -^}h ^| ^{/ ^| --^}help
150echo:or
151echo:%~nx0 ^{/ ^| --^}list
152echo:or
153echo:%~nx0 ^[^{/ ^| -^}c ^| ^{/ ^| --}chapter NUMBER^] ^[^{/ ^| --^}console^] ^[lng^]
154echo:
155echo:where:
156echo:/? or /h or -h or /help or --help
157echo: Display the quick help and exit.
158echo:
159echo:/list or --list
160echo: Display the available chapters and languages
161echo: of the tutorial and exit.
162echo:
163echo:/c or -c or /chapter or --chapter NUMBER
164echo: Specified chapter of the tutorial.
165echo: The NUMBER should be 1 or 2.
166echo: By default, the first chapter.
167echo:
168echo:/console or --console
169echo: Open the tutorial in the console instead of GUI.
170echo:
171echo:lng
172echo: Is a 2 or 3 character ISO639 language code
173echo: like "es", "nl" or "bar".
174echo: The default language is English.
175echo:
176echo:Examples:
177echo: %~nx0 es /c 1 /console
178echo: %~nx0 --chapter 2 de
179echo: %~nx0 fr
180echo:
181
182:EndUsage
183goto End
184
185:List
186
187:GetLngName
188if defined TMP (set "pscult_fl=%TMP%\pscult.tmp") else (
189 set "pscult_fl=%TEMP%\pscult.tmp")
190
191powershell.exe -NoLogo -NoProfile -Command ^
192[system.globalization.cultureinfo]::GetCultures('AllCultures') ^| ^
Damien Lejay8d9d2b22025-06-22 19:39:04 +0200193Where DisplayName -NotLike "Invariant*" ^| %%{$_.Name.Replace('-','_') + ^
194\"`t\" + $_.DisplayName + \"`t\" + $_.NativeName} ^| ^
RestorerZe7ea4ba2024-12-02 20:07:58 +0100195Sort-Object ^| Out-File -FilePath "%pscult_fl%" -Encoding utf8
196
197if defined lngs_tutor1 (set "lngs=%lngs_tutor1%")
198if defined lngs_tutor2 if defined lngs (
199 for %%G in (%lngs_tutor2%) do (call set "lngs=%%lngs:%%G;=%%")
200 set "lngs=%lngs%%lngs_tutor2%"
201 ) else (set "lngs=%lngs_tutor2%")
202
203if defined lngs (
204 for %%G in (%lngs%) do (
205 for /F "tokens=2,* delims= " %%H in (
Damien Lejay8d9d2b22025-06-22 19:39:04 +0200206 '2^> nul findstr /IBR "\<%%G\>" "%pscult_fl%"'
RestorerZe7ea4ba2024-12-02 20:07:58 +0100207 ) do (set "%%G_name=%%H %%I")
208 )
209 set "bar_name=Bavarian Boarisch"
210 set "eo_name=Esperanto Esperanto"
211)
212:EndGetLngName
213
214echo:
215echo:The following chapters and languages are available in the current
216echo:installation tutorial:
217echo:
218if defined lngs_tutor1 (
219 echo:Chapter: 1
220 for %%G in (%lngs_tutor1%) do if "en"=="%%G" (
221 call echo:%%G %%%%G_name%% by default) else (
222 call echo:%%G %%%%G_name%%)
223 echo:
224)
225
226if defined lngs_tutor2 (
227 echo:Chapter: 2
228 for %%G in (%lngs_tutor2%) do if "en"=="%%G" (
229 call echo:%%G %%%%G_name%% by default) else (
230 call echo:%%G %%%%G_name%%)
231)
232echo:
233goto End
234
235:DelTmpCopy
Damien Lejay8d9d2b22025-06-22 19:39:04 +0200236:: deleted the copy of the tutor
RestorerZe7ea4ba2024-12-02 20:07:58 +0100237if exist %TUTORCOPY% del /F /Q %TUTORCOPY%
238goto :EOF
239
240:End
Damien Lejay8d9d2b22025-06-22 19:39:04 +0200241:: deleted the copy of the tutor and the pscult.tmp file
RestorerZe7ea4ba2024-12-02 20:07:58 +0100242if exist %TUTORCOPY% del /F /Q %TUTORCOPY%
243if exist %pscult_fl% del /F /Q %pscult_fl%
244chcp %_sav_chcp% 1> nul
245title %ComSpec%
246EndLocal
247
248@rem vim:ft=dosbatch:ts=8:sts=2:sw=2:noet: