探索 Powershell
Get-Verb
Returns a list of verbs that most commands adhere to.Get-command
retrieves a list of all commands installed on your machine.Get-Member
operates on object based output and is able to discover what object, properties and methods are available for a command.Get-Help
displays a help page describing various parts of a command.
配置 powershell
-
安装 powershell
-
安装 scoop - A command-line installer for Windows
-
安装 Winget - Install and manage applications
-
安装 git for windows - Offer a lightweight, native set of tools
winget install -e --id Git.Git
-
安装
gcc
、neovim
scoop install gcc neovim
-
powershell 配置文件 - about _profiles
The $PROFILE variable
The
$profile
automatic variable stores the paths to the Powershell profiles that are available in the current session.The
$PROFILE
variable stores the path to the “Current User, Current Host” profile. The other profiles are saved in note properties of the$PROFILE
variable.Split-Path $PROFILE.CurrentUserCurrentHOST mkdir ~/.config/powershell nvim ~/.config/powershell/user_profile.ps1
创建
$PROFILE.CurrentUserCurrentHost
文件 ,并添加. $env:USEPROFILE\.config\powershell\user_profile.ps1
内容,重新启动终端,这时配置文件已生效。# Create a profile New-Item $PROFILE.CurrentUserCurrentHost # or nvim $PROFILE
-
安装
posh-git
和oh-my-posh
- Prompt for Git repositories
- A prompt theme engine for any shell
Install-Module posh-git -Scope CurrentUser -Force Install-Module oh-my-posh -Scope CurrentUser -Force
编辑
~/.config/powershell/user-profile.ps1
# Prompt Import-Module posh-git Import-Module oh-my-posh Set-PoshPrompt <themename>
-
自定义 prompt
-
安装 nvm
scoop install nvm
-
# Install-Module Install-Module -Name Terminal-Icons -Repository PSGallery -Force # or use scoop scoop bucket add extras scoop install terminal-icons Import-Module Terminal-Icons
-
安装 z
Install-Module -Name z -Force
-
安装 PSReadLine - autocompletion
Install-Module -Name PowerShellGet -Force Install-Module -Name PSReadLine -Force -SkipPublisherCheck -AllowPrerelease
To start using, just import the module:
Import-Module PSReadLine
To view the current key bindings:
Get-PSReadLineKeyHandler
To use Emacs key bindings, you can use:
Set-PSReadLineOption -EditMode Emacs
Specifies the source for PSReadLine to get predictive suggestions.
Set-PSReadLineOption -PredictionSource Hisory
Sets the style for the display of the predictive text. The default is InlineView.
Set-PSReadLineOption -PredictionViewStyle ListView
# user_profile.ps1 Import-Module PSReadLine Set-PSReadLineOption -EditMode Emacs Set-PSReadLineOption -PredictionSource HisoryAndPlugin Set-PSReadLineOption -PredictionViewStyle ListView
-
安装
fzf
PSFzfscoop install fzf Install-Module -Name PSFzf -Scope CurrentUser -Force
about_Environment_Provider
The environment Environment provider lets you get, add, change, clear, delete environment variables and values in Powershell.
Windows and Powershell use Environment variables to store persistent information that affect system and process execution.
Unlike PowerShell variables, environment variables are not subject to scope constraints.
The Environment provider supports the following cmdlets.
about_Environment_Variables
Environment variables store information about the operating system environment.
The environment variables store data that is used by the operating system and other programs.
about_CommonParameters
描述可与任何 cmdlet 一起使用的参数。****
常见问题
Windows terminal 下 git bash 乱码问题
在相应的 git-for-windows 的安装路径文件 **\Git\etc\bash.bashrc
末尾添加
# 让ls和dir命令显示中文和颜色
alias ls='ls --show-control-chars --color'
alias dir='dir -N --color'
# 设置为中文环境,使提示成为中文
export LANG="zh_CN"
# 输出为中文编码
export OUTPUT_CHARSET="utf-8"
# 可以输入中文
set meta-flag on
set output-meta on
set convert-meta off
命令
-
生成唯一标识 guid
[guid]::NewGuid()
-
设置代理
# powershell $env:HTTP_PROXY="http://127.0.0.1:1080" $env:HTTPS_PROXY="http://127.0.0.1:1080" # cmd set http_proxy=http://127.0.0.1:1080
技巧
- 按tab 键可自动补全命令
- Reset your video devicer:
Ctrl+shift+win+B