Search

Dark theme | Light theme

March 18, 2026

Nushell Niceties: Bumping Semantic Version

In a previous blogpost you can learn about the semver command in Nushell to transform a string value into a semver type. With the semver bump command you can increase one of the components of the semver type. For example to increase the major version part you can use semver bump major. This command will also update the minor and patch parts if needed. The result is a semver type and you can use into value to transform it to a string type.

In the following example several of the semver bump commands are used:

use std/assert

# After installing the nu_plugin_semver plugin and
# adding it to the plugin registry you can use
# the plugin for Nushell code.
plugin use semver

# Transform string to semver value.
let version = '4.0.2'

# Bumping major part of version by adding 1 to the current value.
assert equal ($version | semver bump major | into value) '5.0.0'

# Bumping minor part by adding 1 to the value.
# The option `--ignore-errors` makes sure when an error occurs the
# original input value is returned. The shorthand `-i` is also valid.
assert equal ($version | semver bump minor --ignore-errors | into value) '4.1.0'

# Bumping patch part by adding 1 to the value.
assert equal ($version | semver bump patch | into value) '4.0.3'

# Bumping to a release candidate version, patch is unchanged.
assert equal ($version | semver bump rc | into value) '4.0.2-rc.1'

# Bumping to a next alpha version by adding 1 to patch value and
# pre-release part `alpha.1`.
assert equal ($version | semver bump alpha | into value) '4.0.3-alpha.1'

# Bumping to a next beta version by adding 1 to patch value and
# pre-release part `beta.1`.
assert equal ($version | semver bump beta | into value) '4.0.3-beta.1'

# Using `bump release` will remove the pre (release) part of semver value.
assert equal ('4.0.3-rc.1' | semver bump release | into value) '4.0.3'


# The same bump commands can be used for a semver type input.
let full_version = '4.0.2-rc.1+build-20260205' | into semver

assert equal ($full_version | semver bump major | into value) '5.0.0'
assert equal ($full_version | semver bump minor | into value) '4.1.0'
assert equal ($full_version | semver bump patch | into value) '4.0.2+build-20260205'
assert equal ($full_version | semver bump rc | into value) '4.0.2-rc.2+build-20260205'
assert equal ($full_version | semver bump release | into value) '4.0.2+build-20260205'


# The `semver bump` command support the `--build-metadata` (or shorthand `-b`)
# option to add build metadata to a semver or string value.
(assert equal
        ('4.2.8' | semver bump minor --build-metadata 'build-20260205' | into value)
        '4.3.0+build-20260205')

Written with Nushell 0.111.0.