Skip to content

๐Ÿ“‚ windows

โšก windows::addToPath

Add the given path to the PATH environment variable on Windows (current user only).

Will also export the PATH variable in the current bash.

Inputs:

  • $1: path as string:

    the path to add to the PATH environment variable. The path can be in unix format, it will be converted to windows format.

  • ${prepend} as bool:

    (optional) True to prepend the path to the PATH, false to append it.

    (defaults to false)

Example usage:

windows::addToPath "/path/to/bin"
windows::addToPath "/path/to/bin" prepend=true

This function is only available on Windows, it uses powershell to directly modify the registry.

โšก windows::createTempDirectory

Create a temporary directory on Windows and return the path both for Windows and Unix.

This is useful for creating temporary directories that can be used in both Windows and Unix.

Returns:

  • ${REPLY}: The Windows path.
  • ${REPLY2}: The Unix path.

Example usage:

windows::createTempDirectory

Directories created this way are automatically cleaned up by the fs::cleanTempFiles function when valet ends.

โšก windows::createTempFile

Create a temporary file on Windows and return the path both for Windows and Unix.

This is useful for creating temporary files that can be used in both Windows and Unix.

Returns:

  • ${REPLY}: The Windows path.
  • ${REPLY2}: The Unix path.

Example usage:

windows::createTempFile

Files created this way are automatically cleaned up by the fs::cleanTempFiles function when valet ends.

โšก windows::endPs1Batch

This function will run all the commands that were batched with windows::startPs1Batch.

Returns:

  • ${REPLY_CODE}:
    • 0 if the command was successful
    • 1 otherwise.
  • ${REPLY}: The content of stdout.
  • ${REPLY2}: The content of stderr.

Example usage:

windows::startPs1Batch
windows::runPs1 "Write-Host \"Hello\""
windows::runPs1 "Write-Host \"World\""
windows::endPs1Batch

โšก windows::getEnvVar

Get the value of an environment variable for the current user on Windows.

Inputs:

  • $1: variable name as string:

    the name of the environment variable to get.

Returns:

  • ${REPLY}: the value of the environment variable.

Example usage:

windows::getEnvVar "MY_VAR"
echo "${REPLY}"

โšก windows::getUnixPathFromWindowsPath

Convert a Windows path to a unix path.

Inputs:

  • $1: path as string:

    the path to convert

Returns:

  • ${REPLY}: The unix path.

Example usage:

windows::getUnixPathFromWindowsPath "C:\path\to\file"

Handles paths starting with X:\.

โšก windows::getWindowsPathFromUnixPath

Convert a unix path to a Windows path.

Inputs:

  • $1: path as string:

    the path to convert

Returns:

  • ${REPLY}: The Windows path.

Example usage:

windows::getWindowsPathFromUnixPath "/path/to/file"

Handles paths starting with /mnt/x/ or /x/ in pure bash, handles other msys2 paths using cygpath.

โšก windows::runPs1

Runs a PowerShell command. This is mostly useful on Windows.

Inputs:

  • $1: command as string:

    the command to run.

  • ${runAsAdmin} as bool:

    (optional) Wether to run the command as administrator.

    (defaults to false).

  • ${noFail} as bool:

    (optional) A boolean to indicate if the function should call core::fail (exit) in case the execution fails. If true and the execution fails, the script will exit.

    (defaults to false)

Returns:

  • ${REPLY_CODE}:
    • 0 if the command was successful
    • 1 otherwise.
  • ${REPLY}: The content of stdout.
  • ${REPLY2}: The content of stderr.

Example usage:

windows::runPs1 "Write-Host \"Press any key:\"; Write-Host -Object ('The key that was pressed was: {0}' -f [System.Console]::ReadKey().Key.ToString());"
windows::runPs1 "Write-Host \"Hello\"" runAsAdmin=true noFail=true

โšก windows::setEnvVar

Set an environment variable for the current user on Windows.

Inputs:

  • $1: variable name as string:

    The name of the environment variable to set.

  • $2: variable value as string:

    The value of the environment variable to set. An empty string will unset the variable.

Example usage:

windows::setEnvVar "MY_VAR" "my_value"

This function is only available on Windows, it uses powershell to directly modify the registry.

โšก windows::startPs1Batch

After running this function, all commands that should be executed by windows::runPs1 will be added to a batch that will only be played when windows::endPs1Batch is called.

This is a convenient way to run multiple commands in a single PowerShell session. It makes up for the fact that running a new PowerShell session for each command is slow.

Example usage:

windows::startPs1Batch
windows::runPs1 "Write-Host \"Hello\""
windows::runPs1 "Write-Host \"World\""
windows::endPs1Batch

Important

Documentation generated for the version 0.37.1138 (2026-05-12).