zoukankan      html  css  js  c++  java
  • Windows Terminal && PowerShell

    PowerShell

    PowerShell具备自动执行脚本,远程控制,传输文件的能力,十分强大

    并且具备了cmd的各种命令,也可以集成git等一众插件

    1. 安装Windows Terminal

    使用window10的终端来管理各种控制台工具

    从git上下载最新版本的Windows Terminal

    2. 下载PowerShell

    从git上下载最新版本的PowerShell

    3. 右键启动PWL

    从git上下载配置脚本Here

    常用命令

    安装模块

    常规手段安装

    Install-Module oh-my-posh -Force -Verbose
    

    模块名称:oh-my-posh

    详情:-Force -Verbose //用来查看日志

    手动安装nupkg模块包

    VERBOSE: Downloading 'https://www.powershellgallery.com/api/v2/package/oh-my-posh/3.139.0'.
    

    通过上面的安装命令,可以看到安装日志中一直卡在下载nupkg包上。我们可以通过其他手段下载到这个包。

    然后将文件后缀改为zip,并且解压到powershell的module的目录中

    C:Program FilesPowerShell7Modules

    1. 打开PWL配置文件

    2. 手动导入模块

      Import-Module 'C:	oolsposhgitdahlbyk-posh-git-9bda399srcposh-git.psd1'
      Import-Module 'C:Program FilesPowerShell7Modulesoh-my-posh.3.139.0oh-my-posh.psd1'
      

    卸载模块

    $Module = Get-Module PSWindowsUpdate
    Remove-Module $Module.Name
    Remove-Item $Module.ModuleBase -Recurse -Force
    

    查看模块

    module
    

    配置PWL

    notepad.exe $Profile
    

    Chocolatey

    Chocolatey是一个Windows下的包管理器,类似于Linux下的apt-get或yum

    很多模块直接使用 install命令因为网络原因,进度缓慢。所以可以使用choc下载好之后再安装。

    搜索软件

    choco search oh-my-posh
    

    安装软件

    Install-Module oh-my-posh -Scope CurrentUser -Verbose
    

    -Verbose :显示安装日志

    界面美化

    Request:安装新版本的Windows Terminal ,新版本PowerShell

    1. 安装字体

    Fira Code Nerd Font字体支持众多特殊符号

    2.安装PowerShell插件

    # 1. 安装 PSReadline 包,该插件可以让命令行很好用,类似 zsh
    Install-Module -Name PSReadLine -AllowPrerelease -Force -Verbose
    
    # 2. 安装 posh-git 包,让你的 git 更好用
    Install-Module posh-git -Scope CurrentUser -Verbose
    
    # 3. 安装 oh-my-posh 包,让你的命令行更酷炫、优雅
    Install-Module oh-my-posh -Scope CurrentUser -Verbose
    

    3. 配置Windows Terminal界面

    自定义Homebrew主题

    
    {
                "background": "#283033",
                "black": "#000000",
                "blue": "#6666E9",
                "brightBlack": "#666666",
                "brightBlue": "#0000FF",
                "brightCyan": "#00E5E5",
                "brightGreen": "#00D900",
                "brightPurple": "#E500E5",
                "brightRed": "#E50000",
                "brightWhite": "#E5E5E5",
                "brightYellow": "#E5E500",
                "cursorColor": "#FFFFFF",
                "cyan": "#00A6B2",
                "foreground": "#00FF00",
                "green": "#00A600",
                "name": "Homebrew",
                "purple": "#B200B2",
                "red": "#FC5275",
                "selectionBackground": "#FFFFFF",
                "white": "#BFBFBF",
                "yellow": "#999900"          
     },
     
    

    配置PowerShell样式

    {
    	"guid": "{574e775e-4f2a-5b96-ac1e-a2962a402336}",
        "hidden": false,
        "name": "pwsh",
        // 注意:一定要写上 -nologo,否则开启 powershll 会有一段话输出,很讨厌!
        "commandline": "C:/Program Files/PowerShell/7-preview/pwsh.exe -nologo",
        "source": "Windows.Terminal.PowershellCore",
        // 启动菜单一定要设置为 <.>,否则后面重要的一步将会无效!
        "startingDirectory": ".",
        // 字体一定要 Nerd Font 版本
        "fontFace": "FiraCode Nerd Font",
        "fontSize": 11,
        "historySize": 9001,
        "padding": "5, 5, 20, 25",
        "snapOnInput": true,
        "useAcrylic": false,
        // 颜色
        "colorScheme": "Homebrew"
    },
    

    4.配置PWL启动参数

    pwl运行 notepad.exe $Profile

    
    #------------------------------- Import Modules BEGIN -------------------------------
    # 引入 posh-git 放在环境变量也可以
    Import-Module posh-git
    
    # 引入 oh-my-posh 绝对路径也可以
    Import-Module 'C:Program FilesPowerShell7Modulesoh-my-posh.3.139.0oh-my-posh.psd1'
    
    # 设置 PowerShell 主题
    Set-PoshPrompt -Theme Paradox
    #------------------------------- Import Modules END   -------------------------------
    
    
    
    
    
    #-------------------------------  Set Hot-keys BEGIN  -------------------------------
    # 设置 Tab 键补全
    # Set-PSReadlineKeyHandler -Key Tab -Function Complete
    
    # 设置 Ctrl+d 为菜单补全和 Intellisense
    Set-PSReadLineKeyHandler -Key "Tab" -Function MenuComplete
    
    # 设置 Ctrl+d 为退出 PowerShell
    Set-PSReadlineKeyHandler -Key "Ctrl+d" -Function ViExit
    
    # 设置 Ctrl+z 为撤销
    Set-PSReadLineKeyHandler -Key "Ctrl+z" -Function Undo
    
    # 设置向上键为后向搜索历史记录
    Set-PSReadLineKeyHandler -Key UpArrow -Function HistorySearchBackward
    
    # 设置向下键为前向搜索历史纪录
    Set-PSReadLineKeyHandler -Key DownArrow -Function HistorySearchForward
    #-------------------------------  Set Hot-keys END    -------------------------------
    
    
    
    
    
    #-------------------------------    Functions BEGIN   -------------------------------
    # Python 直接执行
    $env:PATHEXT += ";.py"
    
    # 更新 pip 的方法
    function Update-Packages {
        # update pip
        Write-Host "Step 1: 更新 pip" -ForegroundColor Magenta -BackgroundColor Cyan
        $a = pip list --outdated
        $num_package = $a.Length - 2
        for ($i = 0; $i -lt $num_package; $i++) {
            $tmp = ($a[2 + $i].Split(" "))[0]
            pip install -U $tmp
        }
    
        # update TeX Live
        $CurrentYear = Get-Date -Format yyyy
        Write-Host "Step 2: 更新 TeX Live" $CurrentYear -ForegroundColor Magenta -BackgroundColor Cyan
        tlmgr update --self
        tlmgr update --all
    }
    #-------------------------------    Functions END     -------------------------------
    
    
    
    
    
    #-------------------------------   Set Alias Begin    -------------------------------
    # 1. 编译函数 make
    function MakeThings {
        nmake.exe $args -nologo
    }
    Set-Alias -Name make -Value MakeThings
    
    # 2. 更新系统 os-update
    Set-Alias -Name os-update -Value Update-Packages
    
    # 3. 查看目录 ls & ll
    function ListDirectory {
        (Get-ChildItem).Name
        Write-Host("")
    }
    Set-Alias -Name ls -Value ListDirectory
    Set-Alias -Name ll -Value Get-ChildItem
    #-------------------------------    Set Alias END     -------------------------------
    
  • 相关阅读:
    微软新一代Surface,该怎么看?
    Windows 8创新之路——样章分享
    微软新一代Surface发布,参数曝光
    从MS Word到Windows Live Writer
    《计算机科学基础》学习笔记_Part 1 Computer and Data
    我看Windows 8.1
    Hyper-V初涉_早期Windows安装虚拟硬件驱动
    2020.09.05【省选组】模拟 总结
    2020.08.15【NOIP提高组】模拟 总结
    2020.08.14【省选B组】模拟 总结
  • 原文地址:https://www.cnblogs.com/tangpeng97/p/14673275.html
Copyright © 2011-2022 走看看