Skip to content
Go back

Powershell101

Updated:
Edit page

Table of contents

Open Table of contents

探索 Powershell

配置 powershell

  1. 安装 Draula 主题

  2. 安装 powershell

  3. 配置 windows terminal

  4. 安装 scoop - A command-line installer for Windows

  5. 安装 Winget - Install and manage applications

  6. 安装 git for windows - Offer a lightweight, native set of tools

    winget install -e --id Git.Git
  7. 安装 gccneovim

    scoop install gcc neovim
  8. 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.

    $profile

    
    Split-Path $PROFILE.CurrentUserCurrentHOST

    创建 $PROFILE.CurrentUserCurrentHost 文件,如果它的父文件夹不存在,使用 -Force 选项强制创建文件夹。

    # Create a profile
    New-Item $PROFILE.CurrentUserCurrentHost
    # or
    New-Item -Path $PROFILE -ItemType "File" -Force 
    
    notepad $PROFILE
  9. 安装 posh-gitoh-my-posh

    • Prompt for Git repositories
    • A prompt theme engine for any shell
    Install-Module posh-git -Scope CurrentUser -Force
    
    winget install JanDeDobbeleer.OhMyPosh --source winget

    编辑 $ENV:USERPROFILE\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1

    # Prompt
    Import-Module posh-git
    oh-my-posh init pwsh --config 'spaceship' | Invoke-Expression
  10. 自定义 prompt

  11. 安装 nvm

    scoop install nvm
  12. 安装 terminal icons

    # Install-Module
    Install-Module -Name Terminal-Icons -Repository PSGallery -Force -Scope CurrentUser
    
    # or use scoop
    scoop bucket add extras
    scoop install terminal-icons

    配置powershell

    Import-Module Terminal-Icons
  13. 安装 z

  14. 安装 PSReadLine - autocompletion

    How to use PSReadLine

    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
  15. 安装 fzf PSFzf

    scoop install fzf
    Install-Module -Name PSFzf -Scope CurrentUser -Force
  16. 安装 git-aliases

    Install-Module git-aliases -Scope CurrentUser -AllowClobber

    配置 powershell

    Import-Module git-aliases -DisableNameChecking
  17. 重启 Powershell 配置文件

    . $PROFILE

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

命令

技巧

  1. 按tab 键可自动补全命令
  2. Reset your video devicer: Ctrl+shift+win+B

资源

https://www.powershellgallery.com/packages/PSFzf/2.0.0

https://www.powershellgallery.com/## Table of contents


Edit page
Share this post on:

Next Post
MySQL Docker 常用命令