win7 powershell配色方案

首先我是参考微软的word的, look~

Windows PowerShell 配置文件

要配置powershell很简单, 就几步

1.显示 Windows PowerShell 配置文件的路径

$profile

2.确定是否已经在系统上创建了 Windows PowerShell 配置文件,请键入:

test-path $profile

如果存在配置文件,则响应为 True:否则响应为 False。(我的显示是False)

3.创建 Windows PowerShell 配置文件,请键入:

new-item -path $profile -itemtype file -force

4.在记事本中打开配置文件,请键入:

notepad $profile

然后把下面的配置方案扔进去

set-alias ll         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 'Green'
    Write-Host ("Chenglee") -nonewline -foregroundcolor 'Red'
    Write-Host ("@") -nonewline -foregroundcolor 'Yellow'
    Write-Host ("WIN7 ") -nonewline -foregroundcolor 'Magenta'
    Write-Host ($my_path_tail) -nonewline -foregroundcolor 'Blue'
    Write-Host ("]#") -nonewline -foregroundcolor 'Green'
    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:    Tojo2000 <tojo2000@tojo2000.com>
#>
  $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 $_
      $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')
}

启动powershell(可能会报错, 不管它)执行下面命令:

Set-ExecutionPolicy RemoteSigned

选择Y

OK!

重新启动powershell!

以后要修改配置方案的话直接换C:\Users\hp\Documents\WindowsPowerShell目录下的Microsoft.PowerShell_profile.ps1文件即可。

 

转载于:https://www.cnblogs.com/chenglee/p/9167059.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值