自定义 PowerShell 提示 [英] Custom PowerShell prompts

查看:82
本文介绍了自定义 PowerShell 提示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找自定义 Powershell prompt 函数实现的不同示例.如果您有自己的自定义实现,请发布脚本.现有资源的链接也很好.

I'm looking for different examples of custom Powershell prompt function implementations. If you have a custom implementation of your own please post the script. Links to existing resources are good as well.

发布提示实际外观的屏幕截图(预览)的奖励积分.

Bonus points for posting a screenshot of what your prompt actually looks like (a preview).

推荐答案

我的:

function prompt {
   # our theme
   $cdelim = [ConsoleColor]::DarkCyan
   $chost = [ConsoleColor]::Green
   $cloc = [ConsoleColor]::Cyan

   write-host "$([char]0x0A7) " -n -f $cloc
   write-host ([net.dns]::GetHostName()) -n -f $chost
   write-host ' {' -n -f $cdelim
   write-host (shorten-path (pwd).Path) -n -f $cloc
   write-host '}' -n -f $cdelim
   return ' '
}

它使用这个辅助函数:

function shorten-path([string] $path) {
   $loc = $path.Replace($HOME, '~')
   # remove prefix for UNC paths
   $loc = $loc -replace '^[^:]+::', ''
   # make path shorter like tabs in Vim,
   # handle paths starting with \\ and . correctly
   return ($loc -replace '\\(\.?)([^\\])[^\\]*(?=\\)','\$1$2')
}

这篇关于自定义 PowerShell 提示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆