powershell - 在 VSCode 的 PowerShell 命令提示符中隐藏完整文件路径

标签 powershell visual-studio-code

所以我刚刚下载了 Visual Studio Code 作为我学习 Python 的默认 IDE。我在 64 位机器上运行,所以我制作了默认的终端 windows powershell。

我将保存大部分文件的地方大约有 8 个文件夹深,这些文件夹在写入任何命令之前都显示在终端中。有什么办法可以隐藏或缩短终端中的文件路径吗?

最佳答案

正如@Biclops 所建议的,这里有很好的信息:configure PowerShell to only show the current folder in the prompt

但是,我需要更多基本信息才能使其正常工作。这是一个非常好的入门资源:Windows PowerShell Profiles .所以我首先按照那里建议的步骤进行操作:

【一直使用vscode的集成终端使用PowerShell】

  • test-path $profile (是否设置了配置文件?)
  • new-item -path $profile -itemtype file -force (假设以上答案为假)
  • notepad $profile (打开记事本)
  • 粘贴(来自上面的 super 用户答案)
    function prompt {
      $p = Split-Path -leaf -path (Get-Location)
      "$p> "
    }
    
  • 保存(您不必选择一个位置,它已经为您完成了)
  • 重新加载 vscode - 您可能会收到有关运行脚本的错误消息(或者只是在重新加载之前执行下一步)
  • Set-ExecutionPolicy RemoteSigned -Scope CurrentUser (在您的集成终端 PS 提示符下,也来自 super 用户的回答)
  • 重新加载 vscode
  • 你应该很高兴去!
  • 关于powershell - 在 VSCode 的 PowerShell 命令提示符中隐藏完整文件路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52107170/

    相关文章:

    powershell - 当 ps 脚本路径包含空格且路径源自 %~dp0% 时,如何从批处理文件运行 powershell 脚本

    powershell - 无法从 Visual Studio 2012 登录 Azure

    powershell - 编写 PowerShell 帮助时如何使用 .PARAMETER?

    visual-studio-code - 替换但找不到下一个匹配项

    python - Visual Studio Code 停止运行 Python 脚本 - 似乎改为运行批处理文件

    powershell - 使用括号进行多个逻辑运算

    powershell - 无法使用 powershell 脚本在 Windows 8 上下载 zip 文件

    intellij-idea - 相当于 Jetbrains/IntelliJ/Rubymine 的 VScode 划痕(一次性笔记)

    visual-studio-code - 在 VS Code Ubuntu 中更改终端的复制和粘贴快捷方式

    react-native - 与流服务器的连接已关闭。查看输出以获取更多信息