๐ 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::convertPathFromUnix
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::convertPathFromUnix "/path/to/file"
Handles paths starting with
/mnt/x/
or/x/
in pure bash, handles other msys2 paths usingcygpath
.
โก windows::convertPathToUnix
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::convertPathToUnix "C:\path\to\file"
Handles paths starting with
X:\
.
โก windows::createLink
Create a soft or hard link (original โ link).
Reminder:
- A soft (symbolic) link is a new file that contains a reference to another file or directory in the form of an absolute or relative path.
- A hard link is a directory entry that associates a new pathname with an existing file (inode + data block) on a file system.
Inputs:
$1
: linked path as string:the path to link to (the original file)
$2
: link path as string:the path where to create the link
${hardlink}
as boolean:(optional) True to create a hard link, false to create a symbolic link
(defaults to false)
${force}
as boolean:(optional) True to overwrite the link or file if it already exists. Otherwise, the function will fail on an existing link.
(defaults to false)
Example usage:
windows::createLink "/path/to/link" "/path/to/linked"
windows::createLink "/path/to/link" "/path/to/linked" hardlink=true force=true
On Windows, the function uses
powershell
(and optionally ls to check the existing link). If you have the windows “developer mode” enabled + MSYS=winsymlinks:nativestrict, then it uses the ln command.
โก 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::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.30.1455 (2025-08-18).