ohmyposh 安装 - 基于 powershell7.2.1 - 最后改成 profile自定义

今天偶然下载了 powershell7.2.1

安装准备先装scoop

看默认可以装个winget,win10环境,可是装半天没装上

// powershell7.2.1
set-executionpolicy remotesigned -s cu
iex (new-object net.webclient).downloadstring('https://get.scoop.sh')

安装ohmyposh

scoop install https://github.com/JanDeDobbeleer/oh-my-posh/releases/latest/download/oh-my-posh.json

下载字体

Windows Terminal美化(oh-my-posh3)

https://blog.csdn.net/dietime1943/article/details/122968934

最后失败了

好吧,最后vscode也没搞上,直接点开始菜单的出来了,但是要3秒多,太慢了。我还是默认的吧。88

  • Import-Module posh-git
  • 最后就留下了 Powershell7 和这个 posh-git

最后方案改成了 直接改 Powershell7 风格

code $profile

  • 修改最后的样式 带git分支信息

  • 代码备份
# 20220922
# powershell7
# Import-Module posh-git

# # 提示插件: PSReadLine 如果是使用 PowerShell 7.1 或以上版本则自带了 PSReadLine 2.1,不需要手动安装。
# # 如果你是7.1以下的powershell7 就需要安装
# # Install-Module PSReadLine
# # 设置预测文本来源为历史记录
Set-PSReadLineOption -PredictionSource History
# # 设置向上键为后向搜索历史记录
Set-PSReadLineKeyHandler -Key UpArrow -Function HistorySearchBackward
# # 设置向下键为前向搜索历史纪录
Set-PSReadLineKeyHandler -Key DownArrow -Function HistorySearchForward

set-alias ls         Get-ChildItemColor

function prompt
{
    $my_path = $(get-location).toString()
    $my_pos = ($my_path).LastIndexOf("\") + 1
    if( $my_pos -eq ($my_path).Length ) { $my_path_tail = $my_path }
    else { $my_path_tail = ($my_path).SubString( $my_pos, ($my_path).Length - $my_pos ) }
    Write-Host ("➥ ") -nonewline -foregroundcolor 'DarkCyan'
    # Write-Host ($my_path) -nonewline -foregroundcolor 'DarkCyan'
    Write-Host ($my_path_tail) -nonewline -foregroundcolor 'DarkCyan'
    $GitStatus = Get-GitStatus
    $status = $GitStatus.Branch
    if ($status) {
      Write-Host (" [$status]") -nonewline -foregroundcolor 'DarkBlue'
    }
    # Write-GitStatus $GitStatus
    Write-Host (" $ ") -nonewline -foregroundcolor 'Magenta'
    return ""
}

function Get-ChildItemColor {  
<#  
.Synopsis  
  Returns childitems with colors by type.  
.Description  
  This function wraps Get-ChildItem and tries to output the results  
  color-coded by type:  
  Directories - Cyan  
  Compressed - Red  
  Executables - Green  
  Text Files - Gray  
  Image Files - Magenta  
  Others - Gray  
.ReturnValue  
  All objects returned by Get-ChildItem are passed down the pipeline  
  unmodified.  
.Notes  
  NAME:      Get-ChildItemColor  
  AUTHOR:    blueky 
#>  
  # 这个函数用来做正则匹配,并为不同的文件配置不同的颜色。
  $regex_opts = ([System.Text.RegularExpressions.RegexOptions]::IgnoreCase -bor [System.Text.RegularExpressions.RegexOptions]::Compiled)
  $fore = $Host.UI.RawUI.ForegroundColor  
  $compressed = New-Object System.Text.RegularExpressions.Regex(  
      '\.(zip|tar|gz|rar|7z|tgz|bz2)', $regex_opts)  
  $executable = New-Object System.Text.RegularExpressions.Regex(  
      '\.(exe|bat|cmd|py|pl|ps1|psm1|vbs|rb|reg|sh)', $regex_opts)  
  $text_files = New-Object System.Text.RegularExpressions.Regex(  
      '\.(txt|cfg|conf|ini|csv|log)', $regex_opts)  
  $image_files = New-Object System.Text.RegularExpressions.Regex(  
      '\.(bmp|jpg|png|gif|jpeg)', $regex_opts)  

  Invoke-Expression ("Get-ChildItem $args") |  
    %{  
      if ($_.GetType().Name -eq 'DirectoryInfo') { $Host.UI.RawUI.ForegroundColor = 'Cyan' }  
      elseif ($compressed.IsMatch($_.Name)) { $Host.UI.RawUI.ForegroundColor = 'Red' }  
      elseif ($executable.IsMatch($_.Name)) { $Host.UI.RawUI.ForegroundColor = 'Green' }  
      elseif ($text_files.IsMatch($_.Name)) { $Host.UI.RawUI.ForegroundColor = 'Gray' }  
      elseif ($image_files.IsMatch($_.Name)) { $Host.UI.RawUI.ForegroundColor = 'Magenta' }  
      else { $Host.UI.RawUI.ForegroundColor = 'Gray' }  
      # echo $_.Name
      Write-Host -NoNewline $_.Name "  "
      # echo $_
      $Host.UI.RawUI.ForegroundColor = $fore  
    }  
}  

function Show-Color( [System.ConsoleColor] $color )
{
    $fore = $Host.UI.RawUI.ForegroundColor
    $Host.UI.RawUI.ForegroundColor = $color
    echo ($color).toString()
    $Host.UI.RawUI.ForegroundColor = $fore
}

function Show-AllColor
{
    Show-Color('Black')
    Show-Color('DarkBlue')
    Show-Color('DarkGreen')
    Show-Color('DarkCyan')
    Show-Color('DarkRed')
    Show-Color('DarkMagenta')
    Show-Color('DarkYellow')
    Show-Color('Gray')
    Show-Color('DarkGray')
    Show-Color('Blue')
    Show-Color('Green')
    Show-Color('Cyan')
    Show-Color('Red')
    Show-Color('Magenta')
    Show-Color('Yellow')
    Show-Color('White')
}

# code $PROFILE
set code "C:\Users\Reciter\AppData\Local\Programs\Microsoft VS Code\Code.exe"
# set-alias d 'npm run dev'
set-alias n 'nest'
function gitpush ($m) {
  # git push 的简称 gp
  git add .
  git commit -m "$m"
  git push
}
function d { npm run dev }
# defineConfig 定义配置
function dc { &$code C:\Users\Reciter\Documents\PowerShell\Microsoft.PowerShell_profile.ps1 }
# 打包发布到远程
function pp { npm run buildAndPublic }
# 任免表
function rmb { &$code C:\project\renmianbiaobianjiqiz\appointeditweb }
# 任免表运行
function rmbRun { C:\GreenSoft\aardio\aardio.exe C:\GreenSoft\aardio\project\rmbRun-aardio\default.aproj }
# 任免表后台
# function rmbServer { &$code E:\root\Personal\giteez\koa2\koa2-backend }
function rmbServer { 
  cd E:\root\Personal\giteez\koa2\koa2-backend
  npm run dev }

# vuejsdev
function vuejs { &$code E:\root\Personal\giteez\vuejsdev-com }
# 周报
function note { &$code C:\project\mdNote }
# 导航
function navi { &$code C:\project\navigator }
# 平台
function pt { &$code C:\project\aizzb_project_web }
# 单点登录
function dd { &$code C:\project\aizzb_single_login }
# nestjs-api
function nestjs { &$code C:\Users\Reciter\Desktop\nestjs-study\nestjs-api }
posted @ 2022-09-21 16:06  彭成刚  阅读(162)  评论(0编辑  收藏  举报