Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1 | :: Start Vim on a copy of the tutor file. |
| 2 | @echo off |
RestorerZ | e7ea4ba | 2024-12-02 20:07:58 +0100 | [diff] [blame] | 3 | SetLocal |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4 | |
RestorerZ | e7ea4ba | 2024-12-02 20:07:58 +0100 | [diff] [blame] | 5 | :: Usage: |
| 6 | :: vimtutor [/?|{/ | -}h|{/ | --}help] [{/ | -}c|{/ | --}chapter NUMBER] [{/ | --}console] [xx] |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7 | :: |
| 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 Brabandt | 7841ca1 | 2025-06-16 19:48:03 +0200 | [diff] [blame] | 15 | for %%G in (%TMP% %TEMP% .) do ( |
RestorerZ | e7ea4ba | 2024-12-02 20:07:58 +0100 | [diff] [blame] | 16 | call :TestDirWritable "%~f0" %%G |
| 17 | if not ERRORLEVEL 1 goto DirOk |
Bram Moolenaar | 37f471d | 2020-03-19 17:13:40 +0100 | [diff] [blame] | 18 | ) |
| 19 | |
RestorerZ | e7ea4ba | 2024-12-02 20:07:58 +0100 | [diff] [blame] | 20 | echo: |
| 21 | echo:No working directory is found. |
| 22 | goto End |
Bram Moolenaar | 37f471d | 2020-03-19 17:13:40 +0100 | [diff] [blame] | 23 | |
RestorerZ | e7ea4ba | 2024-12-02 20:07:58 +0100 | [diff] [blame] | 24 | :TestDirWritable |
| 25 | set TUTORCOPY=%2\$tutor$ |
Christian Brabandt | 7841ca1 | 2025-06-16 19:48:03 +0200 | [diff] [blame] | 26 | copy %1 %TUTORCOPY% >nul 2>&1 |
RestorerZ | e7ea4ba | 2024-12-02 20:07:58 +0100 | [diff] [blame] | 27 | goto DelTmpCopy |
Bram Moolenaar | 37f471d | 2020-03-19 17:13:40 +0100 | [diff] [blame] | 28 | |
RestorerZ | e7ea4ba | 2024-12-02 20:07:58 +0100 | [diff] [blame] | 29 | :DirOk |
| 30 | title Tutorial on the Vim editor |
| 31 | set "use=Gui" |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 32 | |
RestorerZ | e7ea4ba | 2024-12-02 20:07:58 +0100 | [diff] [blame] | 33 | for /F "usebackq tokens=2 delims=:" %%G in (`chcp`) do ( |
| 34 | set /a "_sav_chcp=%%G" |
| 35 | 1> nul chcp 65001 |
Paul Desmond Parker | 17c71da | 2024-11-03 20:47:53 +0100 | [diff] [blame] | 36 | ) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 37 | |
RestorerZ | e7ea4ba | 2024-12-02 20:07:58 +0100 | [diff] [blame] | 38 | :GetChptLngs |
| 39 | for %%G in (tutor1;tutor2) do ( |
Damien Lejay | 8d9d2b2 | 2025-06-22 19:39:04 +0200 | [diff] [blame] | 40 | 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 | ) |
RestorerZ | e7ea4ba | 2024-12-02 20:07:58 +0100 | [diff] [blame] | 45 | ) |
| 46 | :EndGetChptLngs |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 47 | |
RestorerZ | e7ea4ba | 2024-12-02 20:07:58 +0100 | [diff] [blame] | 48 | :ParseArgs |
| 49 | if "%*"=="" goto Use%use% |
| 50 | if "%1"=="/?" goto Usage |
| 51 | if "%1"=="/h" goto Usage |
| 52 | if "%1"=="-h" goto Usage |
| 53 | if "%1"=="/help" goto Usage |
| 54 | if "%1"=="--help" goto Usage |
| 55 | if "%1"=="/list" goto List |
| 56 | if "%1"=="--list" goto List |
| 57 | :DoShift |
| 58 | if "%1"=="/c" (call :ChkChpt %2 && (shift & shift & goto DoShift) || goto End) |
| 59 | if "%1"=="-c" (call :ChkChpt %2 && (shift & shift & goto DoShift) || goto End) |
| 60 | if "%1"=="/chapter" ( |
| 61 | call :ChkChpt %2 && (shift & shift & goto DoShift) || goto End |
| 62 | ) |
| 63 | if "%1"=="--chapter" ( |
| 64 | call :ChkChpt %2 && (shift & shift & goto DoShift) || goto End |
| 65 | ) |
| 66 | if "%1"=="/console" (set "use=Vim" & shift & goto DoShift) |
| 67 | if "%1"=="--console" (set "use=Vim" & shift & goto DoShift) |
| 68 | call :ChkLng %1 && shift || goto End |
| 69 | if not "%1"=="" goto DoShift |
| 70 | goto Use%use% |
| 71 | |
| 72 | :UseGui |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 73 | :: 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. |
RestorerZ | e7ea4ba | 2024-12-02 20:07:58 +0100 | [diff] [blame] | 78 | start "dummy" /B /W "%~dp0gvim.exe" -u NONE -c "so $VIMRUNTIME/tutor/tutor.vim" |
| 79 | if ERRORLEVEL 1 goto UseVim |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 80 | |
RestorerZ | e7ea4ba | 2024-12-02 20:07:58 +0100 | [diff] [blame] | 81 | :: Start gvim without any .vimrc, set 'nocompatible' and 'showcmd' |
| 82 | start "dummy" /B /W "%~dp0gvim.exe" -u NONE -c "set nocp sc" %TUTORCOPY% |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 83 | |
RestorerZ | e7ea4ba | 2024-12-02 20:07:58 +0100 | [diff] [blame] | 84 | goto End |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 85 | |
RestorerZ | e7ea4ba | 2024-12-02 20:07:58 +0100 | [diff] [blame] | 86 | :UseVim |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 87 | :: The script tutor.vim tells Vim which file to copy |
RestorerZ | e7ea4ba | 2024-12-02 20:07:58 +0100 | [diff] [blame] | 88 | call "%~dp0vim.exe" -u NONE -c "so $VIMRUNTIME/tutor/tutor.vim" |
| 89 | if ERRORLEVEL 1 goto NoExecutable |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 90 | |
Damien Lejay | 8d9d2b2 | 2025-06-22 19:39:04 +0200 | [diff] [blame] | 91 | :: Start vim without any .vimrc, set 'nocompatible' and 'showcmd' |
RestorerZ | e7ea4ba | 2024-12-02 20:07:58 +0100 | [diff] [blame] | 92 | call "%~dp0vim.exe" -u NONE -c "set nocp sc" %TUTORCOPY% |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 93 | |
RestorerZ | e7ea4ba | 2024-12-02 20:07:58 +0100 | [diff] [blame] | 94 | goto End |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 95 | |
RestorerZ | e7ea4ba | 2024-12-02 20:07:58 +0100 | [diff] [blame] | 96 | :NoExecutable |
| 97 | echo: |
| 98 | echo: |
| 99 | echo:No vim or gvim found in current directory or %%PATH%%. |
| 100 | echo:Check your installation or re-run install.exe. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 101 | |
RestorerZ | e7ea4ba | 2024-12-02 20:07:58 +0100 | [diff] [blame] | 102 | goto End |
| 103 | |
| 104 | :ChkChpt |
| 105 | if defined CHAPTER ( |
| 106 | echo:Error. Invalid command line arguments. |
| 107 | echo:See %~nx0 /? for help. |
| 108 | exit /B 1 |
| 109 | ) |
| 110 | for /F %%G in ('echo %1 ^| findstr /R "\<[1-2]\>"') do ( |
| 111 | set "CHAPTER=%%G" & exit /B 0 |
| 112 | ) |
| 113 | echo:Error. The chapter argument must contain only the digits 1 or 2. |
| 114 | exit /B 1 |
| 115 | |
| 116 | :ChkLng |
| 117 | if "%1"=="" exit /B 0 |
| 118 | if defined xx ( |
| 119 | echo:Error. Invalid command line arguments. |
| 120 | echo:See %~nx0 /? for help. |
| 121 | exit /B 1 |
| 122 | ) |
| 123 | for /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 | ) |
| 127 | set "_t=%1" |
| 128 | if ""=="%_t:~1%" ( |
| 129 | echo:Error. The language code must be 2 or 3 characters only. |
| 130 | exit /B 1 |
| 131 | ) |
| 132 | if not ""=="%_t:~3%" ( |
| 133 | echo:Error. The language code must be 2 or 3 characters only. |
| 134 | exit /B 1 |
| 135 | ) |
| 136 | SetLocal EnableDelayedExpansion |
| 137 | if "!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 |
| 146 | echo: |
| 147 | echo:== USAGE ================================================================= |
| 148 | echo: |
| 149 | echo:%~nx0 /? ^| ^{/ ^| -^}h ^| ^{/ ^| --^}help |
| 150 | echo:or |
| 151 | echo:%~nx0 ^{/ ^| --^}list |
| 152 | echo:or |
| 153 | echo:%~nx0 ^[^{/ ^| -^}c ^| ^{/ ^| --}chapter NUMBER^] ^[^{/ ^| --^}console^] ^[lng^] |
| 154 | echo: |
| 155 | echo:where: |
| 156 | echo:/? or /h or -h or /help or --help |
| 157 | echo: Display the quick help and exit. |
| 158 | echo: |
| 159 | echo:/list or --list |
| 160 | echo: Display the available chapters and languages |
| 161 | echo: of the tutorial and exit. |
| 162 | echo: |
| 163 | echo:/c or -c or /chapter or --chapter NUMBER |
| 164 | echo: Specified chapter of the tutorial. |
| 165 | echo: The NUMBER should be 1 or 2. |
| 166 | echo: By default, the first chapter. |
| 167 | echo: |
| 168 | echo:/console or --console |
| 169 | echo: Open the tutorial in the console instead of GUI. |
| 170 | echo: |
| 171 | echo:lng |
| 172 | echo: Is a 2 or 3 character ISO639 language code |
| 173 | echo: like "es", "nl" or "bar". |
| 174 | echo: The default language is English. |
| 175 | echo: |
| 176 | echo:Examples: |
| 177 | echo: %~nx0 es /c 1 /console |
| 178 | echo: %~nx0 --chapter 2 de |
| 179 | echo: %~nx0 fr |
| 180 | echo: |
| 181 | |
| 182 | :EndUsage |
| 183 | goto End |
| 184 | |
| 185 | :List |
| 186 | |
| 187 | :GetLngName |
| 188 | if defined TMP (set "pscult_fl=%TMP%\pscult.tmp") else ( |
| 189 | set "pscult_fl=%TEMP%\pscult.tmp") |
| 190 | |
| 191 | powershell.exe -NoLogo -NoProfile -Command ^ |
| 192 | [system.globalization.cultureinfo]::GetCultures('AllCultures') ^| ^ |
Damien Lejay | 8d9d2b2 | 2025-06-22 19:39:04 +0200 | [diff] [blame] | 193 | Where DisplayName -NotLike "Invariant*" ^| %%{$_.Name.Replace('-','_') + ^ |
| 194 | \"`t\" + $_.DisplayName + \"`t\" + $_.NativeName} ^| ^ |
RestorerZ | e7ea4ba | 2024-12-02 20:07:58 +0100 | [diff] [blame] | 195 | Sort-Object ^| Out-File -FilePath "%pscult_fl%" -Encoding utf8 |
| 196 | |
| 197 | if defined lngs_tutor1 (set "lngs=%lngs_tutor1%") |
| 198 | if 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 | |
| 203 | if defined lngs ( |
| 204 | for %%G in (%lngs%) do ( |
| 205 | for /F "tokens=2,* delims= " %%H in ( |
Damien Lejay | 8d9d2b2 | 2025-06-22 19:39:04 +0200 | [diff] [blame] | 206 | '2^> nul findstr /IBR "\<%%G\>" "%pscult_fl%"' |
RestorerZ | e7ea4ba | 2024-12-02 20:07:58 +0100 | [diff] [blame] | 207 | ) do (set "%%G_name=%%H %%I") |
| 208 | ) |
| 209 | set "bar_name=Bavarian Boarisch" |
| 210 | set "eo_name=Esperanto Esperanto" |
| 211 | ) |
| 212 | :EndGetLngName |
| 213 | |
| 214 | echo: |
| 215 | echo:The following chapters and languages are available in the current |
| 216 | echo:installation tutorial: |
| 217 | echo: |
| 218 | if 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 | |
| 226 | if 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 | ) |
| 232 | echo: |
| 233 | goto End |
| 234 | |
| 235 | :DelTmpCopy |
Damien Lejay | 8d9d2b2 | 2025-06-22 19:39:04 +0200 | [diff] [blame] | 236 | :: deleted the copy of the tutor |
RestorerZ | e7ea4ba | 2024-12-02 20:07:58 +0100 | [diff] [blame] | 237 | if exist %TUTORCOPY% del /F /Q %TUTORCOPY% |
| 238 | goto :EOF |
| 239 | |
| 240 | :End |
Damien Lejay | 8d9d2b2 | 2025-06-22 19:39:04 +0200 | [diff] [blame] | 241 | :: deleted the copy of the tutor and the pscult.tmp file |
RestorerZ | e7ea4ba | 2024-12-02 20:07:58 +0100 | [diff] [blame] | 242 | if exist %TUTORCOPY% del /F /Q %TUTORCOPY% |
| 243 | if exist %pscult_fl% del /F /Q %pscult_fl% |
| 244 | chcp %_sav_chcp% 1> nul |
| 245 | title %ComSpec% |
| 246 | EndLocal |
| 247 | |
| 248 | @rem vim:ft=dosbatch:ts=8:sts=2:sw=2:noet: |