This document describes the terminal emulator detection subsystem in fastfetch, which identifies the terminal application that is currently running the process. Terminal detection operates primarily by walking up the process tree from the detected shell to find the first GUI application, supplemented by environment variable inspection and platform-specific registry lookups.
The detection result is exposed through the Terminal module and includes the terminal's process name, executable path, version, and TTY device. For shell-specific detection, see 3.2.1 Shell Detection Process For font-specific detection, see 3.2.3 Terminal Font Detection
Terminal emulator detection follows a multi-stage fallback strategy to maximize compatibility across platforms and terminal configurations.
Figure 1: Terminal Detection Flow
The detection process attempts three strategies in order:
TERM_PROGRAM, KITTY_PID).Sources: src/detection/terminalshell/terminalshell_linux.c435-460 src/detection/terminalshell/terminalshell_windows.c341-375
The primary detection method walks up the process tree from the shell's parent process, looking for the first application that matches known terminal patterns or characteristics.
On Linux and BSD, the algorithm iterates through parent processes, skipping known shells and wrappers.
Figure 2: Process Tree Walking Algorithm (Linux/BSD)
The detection skips these processes when walking up the tree to find the terminal emulator:
| Category | Process Names |
|---|---|
| Shells | bash, zsh, fish, dash, ksh, mksh, oksh, csh, tcsh, ash, pwsh, nu, elvish, xonsh, sh |
| Privilege/Login | sudo, su, login |
| Wrappers/Utilities | proot, script, run-parts, flatpak-*, chezmoi, clifm |
| Fastfetch | fastfetch, flashfetch |
| Pattern Matching | Ends with .sh, starts with Relay( (WSL2) |
Sources: src/detection/terminalshell/terminalshell_linux.c83-153
On Windows, the algorithm differs by checking for GUI applications, as console applications (like shells) typically don't create windows.
Figure 3: Windows GUI-based Process Walking
Sources: src/detection/terminalshell/terminalshell_windows.c22-74
When process tree traversal fails or returns a generic system process (like explorer.exe or init), detection falls back to inspecting environment variables.
| Priority | Environment Variable(s) | Detected Terminal |
|---|---|---|
| 1 | KITTY_PID, KITTY_INSTALLATION_DIR | kitty |
| 2 | WT_SESSION, WT_PROFILE_ID | Windows Terminal (WSL) |
| 3 | ConEmuPID | ConEmu (WSL) |
| 4 | ALACRITTY_SOCKET, ALACRITTY_LOG | Alacritty |
| 5 | TERMUX_VERSION | Termux |
| 6 | KONSOLE_VERSION | konsole |
| 7 | GNOME_TERMINAL_SCREEN | gnome-terminal |
| 8 | TERM_PROGRAM | Value of variable |
| 9 | TERM | Value of variable |
Sources: src/detection/terminalshell/terminalshell_linux.c172-282
Windows uses a similar priority list, specifically checking for ConEmuPID, WT_SESSION (Windows Terminal), and ALACRITTY_WINDOW_ID.
Sources: src/detection/terminalshell/terminalshell_windows.c118-179
Terminal version detection is handled by fftsGetTerminalVersion(), which implements terminal-specific strategies for extracting version information.
| Terminal | Strategy | Code Reference |
|---|---|---|
| Kitty | Reads constants.py or queries via escape sequence | src/detection/terminalshell/terminalshell.c623-703 |
| Foot | Queries via escape sequence \e<FileRef file-url="https://github.com/fastfetch-cli/fastfetch/blob/50dc260f/>c | [src/detection/terminalshell/terminalshell.c#L391-L406" min=391 max=406 file-path=">c` |
| Windows Terminal | Reads BuildInfo.xml or PE file version | src/detection/terminalshell/terminalshell.c284-361 |
| Alacritty | Executes alacritty --version | src/detection/terminalshell/terminalshell.c46-54 |
| Bash/Zsh | Binary string extraction (e.g., @(#)Bash version) | src/detection/terminalshell/terminalshell.c56-78 |
Sources: src/detection/terminalshell/terminalshell.c37-117 src/detection/terminalshell/terminalshell.c802-980
The terminal detection results are encapsulated in the FFTerminalResult structure and used by the terminal module.
Sources: src/detection/terminalshell/terminalshell.h20-31
The module src/modules/terminal/terminal.c consumes the detection result. If no custom format is provided, it prints the prettyName and version.
Sources: src/modules/terminal/terminal.c21-24
| Function | File | Purpose |
|---|---|---|
ffDetectTerminal() | src/detection/terminalshell/terminalshell_linux.c435 | Main detection entry point for Linux. |
getTerminalInfo() | src/detection/terminalshell/terminalshell_linux.c83 | Walks the process tree to find the terminal. |
getTerminalFromEnv() | src/detection/terminalshell/terminalshell_linux.c172 | Fallback for environment variable inspection. |
fftsGetTerminalVersion() | src/detection/terminalshell/terminalshell.c802 | Dispatches version detection to specific handlers. |
ffPrintTerminal() | src/modules/terminal/terminal.c7 | Prints the detected terminal information. |
Sources: src/detection/terminalshell/terminalshell_linux.c src/detection/terminalshell/terminalshell_windows.c src/modules/terminal/terminal.c
Refresh this wiki