PowerShell
Overview
PowerShell is Microsoft's cross-platform command line interface and scripting language environment. Originally designed for system administration, it has expanded into a general-purpose tool supporting Windows, macOS, and Linux. This article describes how to integrate x-cmd into PowerShell on the Windows platform.
Installing x-cmd
Currently, using x-cmd in PowerShell requires calling through Git-Bash. Ensure Git Bash is installed on your system and x-cmd is properly installed in the Git Bash environment.
- Method 1: One-Line Installation (Recommended)
Execute the following PowerShell command, and x-cmd will automatically download, install, and configure:
powershell[System.Text.Encoding]::GetEncoding("utf-8").GetString($(Invoke-WebRequest -Uri "https://get.x-cmd.com/x-cmd.ps1").RawContentStream.ToArray()) | Invoke-ExpressionThis command will automatically download Git Bash and x-cmd as needed, and execute
x pwsh --setupto complete configuration. - Method 2: Manual Configuration Using Git Bash
Execute in Git Bash:
bashx pwsh --setup
Important: PowerShell Execution Policy
PowerShell's default execution policy may be Restricted, which does not allow running any scripts (including configuration files), preventing x-cmd from working properly.
Use Get-ExecutionPolicy -List to check the current execution policy. It is recommended to use Set-ExecutionPolicy RemoteSigned -Scope CurrentUser to set the execution policy, allowing scripts from trusted sources to run.
For more information, see PowerShell Execution Policies and Set-ExecutionPolicy Documentation.
Theme Customization
Although x-cmd theme only supports POSIX shells, you can achieve stunning visual effects in PowerShell through Oh My Posh and starship:
x starshipx ohmyposhx-cmd's ohmyposh and starship modules provide theme previews and unified control commands. After installation and activation, the theme loads automatically when PowerShell starts, no additional configuration needed.
How x pwsh --setup Works
x pwsh --setup adds the following to the PowerShell profile:
if (Test-Path "$Home\.x-cmd.root\local\data\pwsh\_index.ps1") { Set-ExecutionPolicy Bypass -Scope Process; . "$Home\.x-cmd.root\local\data\pwsh\_index.ps1" }; # boot up x-cmd.This code automatically loads the _index.ps1 file when PowerShell starts. See x pwsh setup code and x-cmd source for more details.
INFO
Set-ExecutionPolicy Bypass -Scope Process sets the current process permission level to Bypass, ensuring scripts execute smoothly.
FAQ
Configuration Recommendation
If you install other tools through x-cmd (such as fzf, asdf), additional configuration may be required in the profile file according to those tools' requirements. It is recommended to add custom configuration code after the x-cmd startup code.
Using @ Commands
Due to the special meaning of @ in PowerShell, some x-cmd commands (such as @gpt, @gemini) have been changed to a:gpt, a:gemini in the PowerShell environment.
If you have any questions, feel free to provide feedback at the x-cmd source repository.
Help us make these docs great!
All X-CMD docs are generated from command help and multiple data sources. See something that's wrong or unclear? Feel free to let us know through any of these ways~