20200120 powershell + oh-my-posh,windows终端体验不再单一

586 阅读1分钟

安装 ohmyposh.dev/docs/

# git 
Install-Module posh-git -Scope CurrentUser
# 本尊
Install-Module oh-my-posh -Scope CurrentUser

编辑配置文件命令

if (!(Test-Path -Path $PROFILE )) { New-Item -Type File -Path $PROFILE -Force }
notepad $PROFILE

在配置文件中增加一下内容

 $DefaultUser = $env:USERNAME
 Import-Module posh-git
 Import-Module oh-my-posh
 #import loacal module
 Import-Module -Name C:\Users\****\Documents\PowerShell\Modules\posh-git-alias\posh-git-alias.ps1
 #主题
 Set-Theme Honukai 

新建git别名module C:\Users\****\Documents\PowerShell\Modules\posh-git-alias\posh-git-alias.ps1

  # zsh
  function gco($arg){
      git checkout $arg
  }

  function gcd(){
      gco develop
  }

  function gcm(){
      gco master
  }

  function gup(){
      git pull --rebase
  }

  function gst(){
      git status
  }

  # custom
  function git-push(){
      git push origin HEAD
  }

  function git-push-force(){
      git push origin HEAD --force
  }

  function git-commit($msg, $author){
      if(!$msg){
          $msg = 'no msg'
      }

      git add .

      if(!$author){
          git commit -am $msg
      }else{
          git commit -am $msg --author=$author
      }
  }

  function git-branch-create($newBranch,$baseBranch){
      if(!$newBranch){
          echo 'input branch name'
          return
      }

      if(!$baseBranch){
          $baseBranch = 'master'
      }

      gco $baseBranch
      gup
      git checkout -b $newBranch $baseBranch
      git push origin $newBranch
  }

  function git-branch-remove($branchName){
      if(!$branchName){
          echo 'input branch name'
          return
      }

      git branch -D $branchName
      git push origin :$branchName
  }

vscode终端可能需要配置字体