Skip to main content

Language

What

A generic, fully configurable language/tool version segment. Use it to display the version of any executable without writing a dedicated segment: point it at one or more tools, a regex to parse their version output, and the files or folders that should trigger it.

Reach for a dedicated segment (like Fortran or Rust) when one already exists; use language for anything not already built in.

Sample Configuration

This example reproduces a GCC version segment purely through configuration.

{
"type": "language",
"style": "plain",
"template": "{{ if .Error }}{{ else }}  {{ .Full }}{{ end }}",
"options": {
"name": "gcc",
"extensions": [
"*.c",
"*.cpp",
"*.h",
"CMakeLists.txt"
],
"tools": [
{
"name": "gcc",
"executable": "gcc",
"args": [
"--version"
],
"regex": "(?P<version>(?P<major>\\d+)\\.(?P<minor>\\d+)\\.(?P<patch>\\d+))"
}
]
}
}

Options

NameTypeDefaultDescription
namestringa unique identifier for the segment, used as its version cache key. Required
toolsarray[]the executables that can report the version, tried in order until one succeeds. See Tools below. Required
home_enabledbooleanfalsedisplay the segment in the HOME folder or not
fetch_versionbooleantruefetch the version
cache_durationstringnonethe duration for which the version will be cached. The duration is a string in the format 1h2m3s and is parsed using the time.ParseDuration function from the Go standard library. To disable the cache, use none
missing_command_textstringtext to display when the command is missing
display_modestringcontext
  • always: the segment is always displayed
  • files: the segment is only displayed when file extensions listed are present
  • context: displays the segment when the environment or files is active
version_url_templatestringa go text/template template that creates the URL of the version info / release notes
extensions[]string[]the file extensions that trigger the segment
project_files[]string[]files to look for in a parent directory that trigger the segment; when matched, .InProjectDir is true
folders[]string[]the folder names that trigger the segment

Tools

Each entry in tools describes one executable that can report the segment's version:

NameTypeDescription
namestringa unique identifier for the tool. Required
executablestringthe executable to run to fetch the version. Required
args[]stringthe arguments to pass to the executable
regexstringthe regex used to parse the version, with a named version capture group; optionally major, minor, patch, prerelease, buildmetadata. Required
version_url_templatestringa go text/template template that creates the URL of the version info / release notes for this tool

Template (info)

default template
{{ if .Error }}{{ .Error }}{{ else }}{{ .Full }}{{ end }}

Properties

NameTypeDescription
.Fullstringthe full version
.Majorstringmajor number
.Minorstringminor number
.Patchstringpatch number
.Prereleasestringprerelease identifier
.BuildMetadatastringbuild identifier
.URLstringURL of the version info / release notes
.InProjectDirboolwhether the working directory is within a project_files match
.Errorstringerror encountered when fetching the version string