[英]how to get rid of present working directory in powershell
I am working on a project that is buried deep beneath the folders and directories and because of that my powershell's line is half filled with the path to the directory.我正在处理一个深埋在文件夹和目录下的项目,因此我的 powershell 行有一半是目录路径。 I want to know if it is possible to get rid of the long string of directory path that is constantly showing.
我想知道是否有可能摆脱不断显示的一长串目录路径。
Building on the last answer I usually put the current path in the title bar of the console window and use the history ID for the prompt.基于上一个答案,我通常将当前路径放在控制台窗口的标题栏中,并使用历史 ID 作为提示。 Something like:
就像是:
Function Prompt
{
$cwd = (get-location).Path
$LastHist = ( Get-History)[-1].Id + 1
$Host.UI.RawUI.WindowTitle = "SPoSh_$($PSVersionTable.PSVersion.Major) - $cwd | User: $($env:USERNAME)"
$Host.UI.Write("Green", $Host.UI.RawUI.BackGroundColor, "SPoSh_$($PSVersionTable.PSVersion.Major)")
" #$LastHist : "
}
So this would look like:所以这看起来像:
"SPoSh_5 #1: " “SPoSh_5 #1:”
I leave a space at the end which makes it easier to double click select a previous command without capturing any of the prompt itself.我在末尾留了一个空格,这样可以更轻松地双击选择上一个命令,而无需捕获任何提示本身。
Note: If you are working in the regular console the title bar additions let you know where you are without crowding the prompt.注意:如果您在常规控制台中工作,则添加的标题栏可以让您知道自己的位置,而不会挤满提示。
The title bar stuff doesn't show in some of the other non-colsole PowerShell hosts, like VSCode's integrated console, but during script dev the location is usually fairly static, so it's not too much trouble.标题栏内容不会显示在其他一些非 colsole PowerShell 主机中,例如 VSCode 的集成控制台,但在脚本开发期间,该位置通常是相当静态的,因此不会太麻烦。
Add this to your script, then call the function after starting your script.将其添加到您的脚本中,然后在启动脚本后调用该函数。
function prompt {
$p = Split-Path -leaf -path (Get-Location)
"$p> "
}
This way only the "leaf" folder will be shown for the prompt placeholder.这样,提示占位符只会显示“叶”文件夹。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.