Skip to content

Commit d85c1ac

Browse files
author
Itamar Shalev
committed
tldr: env: Add TLDR_PLATFORM env var to override platform detection
Add support for the TLDR_PLATFORM environment variable to let users specify the desired platform (e.g., "linux", "macos", "windows") for fetching TLDR pages. This overrides the default platform detection. The --platform option remains supported for per-command overrides. Signed-off-by: Itamar Shalev <[email protected]>
1 parent 829e05c commit d85c1ac

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,22 @@ export TLDR_CACHE_MAX_AGE=720
9191
export TLDR_PAGES_SOURCE_LOCATION="https://raw.githubusercontent.com/tldr-pages/tldr/main/pages"
9292
export TLDR_DOWNLOAD_CACHE_LOCATION="https://github.com/tldr-pages/tldr/releases/latest/download/tldr.zip"
9393
export TLDR_OPTIONS=short
94+
export TLDR_PLATFORM=linux
9495
```
9596
97+
### Platform
98+
The platform that tldr will use is determined by the `TLDR_PLATFORM` environment variable.
99+
If it is not set, the client will try to determine the platform automatically based on the system it is running on.
100+
The following values are supported:
101+
- `linux`
102+
- `windows`
103+
- `android`
104+
- `freebsd`
105+
- `netbsd`
106+
- `openbsd`
107+
- `osx`
108+
- `sunos`
109+
96110
### Cache
97111
98112
Cache is downloaded from `TLDR_DOWNLOAD_CACHE_LOCATION` (defaults to the one described in [the client specification](https://github.com/tldr-pages/tldr/blob/main/CLIENT-SPECIFICATION.md#caching)), unzipped and extracted into the [local cache directory](#cache-location). Pages are loaded directly from `TLDR_PAGES_SOURCE_LOCATION` if `tldr <command>` is used.

tldr.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,13 @@ def update_page_for_platform(
202202

203203

204204
def get_platform() -> str:
205+
if platform := os.environ.get('TLDR_PLATFORM'):
206+
platform = platform.lower()
207+
if platform in OS_DIRECTORIES:
208+
return OS_DIRECTORIES[platform]
209+
else:
210+
print("Warning: Invalid platform specified in environment variable TLDR_PLATFORM.")
211+
205212
for key in OS_DIRECTORIES:
206213
if sys.platform.startswith(key):
207214
return OS_DIRECTORIES[key]

0 commit comments

Comments
 (0)