跳转到内容

❧ PowerShell7 使用指南

一、下载与安装

下载地址https://github.com/powershell/powershell/releases

从 GitHub 官方仓库下载最新版本的 PowerShell7(选择适合你的操作系统的安装包)

二、安装posh-git

Terminal window
# 安装 posh-git(只需一次)
Install-Module posh-git -Scope CurrentUser -Force
# 在 $PROFILE 中导入
Import-Module posh-git

默认安装路径:C:\Users\用户名\Documents\PowerShell\Modules\posh-git<版本号>\

三、常用配置

Terminal window
# 控制台编码设为 UTF-8
[Console]::OutputEncoding = [System.Text.Encoding]::UTF8
[Console]::InputEncoding = [System.Text.Encoding]::UTF8
# 全局 cmdlet 默认编码
$PSDefaultParameterValues['*:Encoding'] = 'utf8'
# 目录跳转
function root { Set-Location E:\root }
# 调用 bash 脚本(需要 Git Bash 在 PATH 中)
function devssh { bash E:\root\ssh\develop-server.sh $args }
function gmssh { bash E:\root\ssh\gm-server.sh $args }
# 简洁版,内联补全
function tt {
param([string]$d)
Set-Location $(if ($d) {"E:\root\ttproject\$d"} else {"E:\root\ttproject"})
}
function me {
param([string]$d)
Set-Location $(if ($d) {"E:\root\myproject\$d"} else {"E:\root\myproject"})
}
# 文件列表查看
function ll {
bash -c "LANG=zh_CN.UTF-8 ls -la --color=auto"
}
Remove-Alias ls -Force -ErrorAction SilentlyContinue
function ls { bash -c "LANG=zh_CN.UTF-8 ls --color=auto" }
# 导入posh-git
Import-Module posh-git