How do I customize the PowerShell Integrated Console prompt in VSCode on Mac?





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







0















In Microsoft's VSCode, I want to customize the integrated PowerShell prompt like I can with my .bash_profile.



It appears you can edit it to your liking according to this document, but I am unsure where to save my .ps1 file with the function prompt { } , and unsure how to get VSCode to invoke it when opening a new console.



It seems every session sets up a temporary profile in Users/<username>/.config/powershell/Microsoft.VSCode_profile.ps1, but doing a ls on my ~/.config directory shows no powershell directory whatsoever. If I create the directory, will VSCode read it when I open a console?



Has anyone succeeded with this?



Output from Get-Host:



Name             : Visual Studio Code Host
Version : 1.11.0
InstanceId : 8d0a98e7-12e1-41b1-b27e-02879107cf00
UI : System.Management.Automation.Internal.Host.InternalHostUserInterface
CurrentCulture : en-US
CurrentUICulture : en-US
PrivateData : Microsoft.PowerShell.EditorServices.EditorServicesPSHost+ConsoleColorProxy
DebuggerEnabled : True
IsRunspacePushed : False
Runspace : System.Management.Automation.Runspaces.LocalRunspace









share|improve this question





























    0















    In Microsoft's VSCode, I want to customize the integrated PowerShell prompt like I can with my .bash_profile.



    It appears you can edit it to your liking according to this document, but I am unsure where to save my .ps1 file with the function prompt { } , and unsure how to get VSCode to invoke it when opening a new console.



    It seems every session sets up a temporary profile in Users/<username>/.config/powershell/Microsoft.VSCode_profile.ps1, but doing a ls on my ~/.config directory shows no powershell directory whatsoever. If I create the directory, will VSCode read it when I open a console?



    Has anyone succeeded with this?



    Output from Get-Host:



    Name             : Visual Studio Code Host
    Version : 1.11.0
    InstanceId : 8d0a98e7-12e1-41b1-b27e-02879107cf00
    UI : System.Management.Automation.Internal.Host.InternalHostUserInterface
    CurrentCulture : en-US
    CurrentUICulture : en-US
    PrivateData : Microsoft.PowerShell.EditorServices.EditorServicesPSHost+ConsoleColorProxy
    DebuggerEnabled : True
    IsRunspacePushed : False
    Runspace : System.Management.Automation.Runspaces.LocalRunspace









    share|improve this question

























      0












      0








      0








      In Microsoft's VSCode, I want to customize the integrated PowerShell prompt like I can with my .bash_profile.



      It appears you can edit it to your liking according to this document, but I am unsure where to save my .ps1 file with the function prompt { } , and unsure how to get VSCode to invoke it when opening a new console.



      It seems every session sets up a temporary profile in Users/<username>/.config/powershell/Microsoft.VSCode_profile.ps1, but doing a ls on my ~/.config directory shows no powershell directory whatsoever. If I create the directory, will VSCode read it when I open a console?



      Has anyone succeeded with this?



      Output from Get-Host:



      Name             : Visual Studio Code Host
      Version : 1.11.0
      InstanceId : 8d0a98e7-12e1-41b1-b27e-02879107cf00
      UI : System.Management.Automation.Internal.Host.InternalHostUserInterface
      CurrentCulture : en-US
      CurrentUICulture : en-US
      PrivateData : Microsoft.PowerShell.EditorServices.EditorServicesPSHost+ConsoleColorProxy
      DebuggerEnabled : True
      IsRunspacePushed : False
      Runspace : System.Management.Automation.Runspaces.LocalRunspace









      share|improve this question














      In Microsoft's VSCode, I want to customize the integrated PowerShell prompt like I can with my .bash_profile.



      It appears you can edit it to your liking according to this document, but I am unsure where to save my .ps1 file with the function prompt { } , and unsure how to get VSCode to invoke it when opening a new console.



      It seems every session sets up a temporary profile in Users/<username>/.config/powershell/Microsoft.VSCode_profile.ps1, but doing a ls on my ~/.config directory shows no powershell directory whatsoever. If I create the directory, will VSCode read it when I open a console?



      Has anyone succeeded with this?



      Output from Get-Host:



      Name             : Visual Studio Code Host
      Version : 1.11.0
      InstanceId : 8d0a98e7-12e1-41b1-b27e-02879107cf00
      UI : System.Management.Automation.Internal.Host.InternalHostUserInterface
      CurrentCulture : en-US
      CurrentUICulture : en-US
      PrivateData : Microsoft.PowerShell.EditorServices.EditorServicesPSHost+ConsoleColorProxy
      DebuggerEnabled : True
      IsRunspacePushed : False
      Runspace : System.Management.Automation.Runspaces.LocalRunspace






      command-line bash powershell visual-studio-code






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Mar 12 at 2:56









      DrKumarDrKumar

      145




      145






















          2 Answers
          2






          active

          oldest

          votes


















          0














          Did some experimenting. Yes, create ~/.config/powershell if it doesn't exist, and save your profile in a file named exactly Microsoft.VSCode_profile.ps1



          Example:



          function prompt {
          "$(Get-Date) $(Resolve-Path -Relative -Path $(Get-Location))> "
          }


          ...will return something like this if your path is /Users/<you>/Documents/powershellscripts/



          03/11/2019 20:11:32 ../powershellscripts>





          share|improve this answer
























          • Correct, you need the profile for such use cases, and again, you have to set OSX to start with pwsh.exe in the user setting of VSCode by setting the terminal path and that part is in the terminal section of the docs.

            – postanote
            Mar 12 at 3:48



















          0














          This is fully documented in the VSCode docs and on this site and all over the web.



          A simple search using 'vscode custom prompt' would give the links for this use case.



          It's just a function you add to your profile. I like to keep things a simple as possible, so, here mine on Windows. It's a blank prompt line with the path displayed in the GUI title bar that I use for all my profiles (PowerShell, ISE, VSCode).



          Function Prompt 
          {
          # get the last command from history
          $command = Get-History -Count 1

          # set it to the window title
          if ($command)
          {
          $CurrentUser = [System.Security.Principal.WindowsIdentity]::GetCurrent()
          $principal = new-object System.Security.principal.windowsprincipal($CurrentUser)
          if ($principal.IsInRole("Administrators")) { $Role = 'Administrator: ' }
          Else { $Role = 'User: ' }

          $host.ui.rawui.WindowTitle = $Role + $PWD
          }


          # specify your custom prompt, e.g. the default PowerShell:
          " "
          }


          So, the above works, but in VSCode, it does not change the title bar, because that is tied to the file you have open. Yet, you are just looking at the prompt. So, this approach should get you there.



          This has been covered on stackexchange as well..



          How to customize the shell prompt in the VS Code terminal on macOS



          Also, see the VSCode docs for more on the terminal setup / customization.



          Integrated Terminal




          In Visual Studio Code, you can open an integrated terminal, initially
          starting at the root of your workspace. This can be convenient as you
          don't have to switch windows or alter the state of an existing
          terminal to perform a quick command-line task.







          share|improve this answer


























          • Please note that I was asking specifically about the PowerShell console that comes with the PowerShell extension. While there are documents and posts everywhere regarding the default terminal (VSCode defaults to bash on Mac), I searched exhaustively for PowerShell specific docs/SE questions, and could not find them.

            – DrKumar
            Mar 12 at 3:40













          • You have to set OSX to default to PowerShell. For this... Name : Visual Studio Code Host … it's the same prompt function. That console, is the ISE version of the console in VSCode. You still have the console host one as well and can be run together as needed. Of course you can add others. You just set it using the OSX paths / format you'd want.

            – postanote
            Mar 12 at 3:44














          Your Answer








          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "3"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1413269%2fhow-do-i-customize-the-powershell-integrated-console-prompt-in-vscode-on-mac%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          2 Answers
          2






          active

          oldest

          votes








          2 Answers
          2






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          Did some experimenting. Yes, create ~/.config/powershell if it doesn't exist, and save your profile in a file named exactly Microsoft.VSCode_profile.ps1



          Example:



          function prompt {
          "$(Get-Date) $(Resolve-Path -Relative -Path $(Get-Location))> "
          }


          ...will return something like this if your path is /Users/<you>/Documents/powershellscripts/



          03/11/2019 20:11:32 ../powershellscripts>





          share|improve this answer
























          • Correct, you need the profile for such use cases, and again, you have to set OSX to start with pwsh.exe in the user setting of VSCode by setting the terminal path and that part is in the terminal section of the docs.

            – postanote
            Mar 12 at 3:48
















          0














          Did some experimenting. Yes, create ~/.config/powershell if it doesn't exist, and save your profile in a file named exactly Microsoft.VSCode_profile.ps1



          Example:



          function prompt {
          "$(Get-Date) $(Resolve-Path -Relative -Path $(Get-Location))> "
          }


          ...will return something like this if your path is /Users/<you>/Documents/powershellscripts/



          03/11/2019 20:11:32 ../powershellscripts>





          share|improve this answer
























          • Correct, you need the profile for such use cases, and again, you have to set OSX to start with pwsh.exe in the user setting of VSCode by setting the terminal path and that part is in the terminal section of the docs.

            – postanote
            Mar 12 at 3:48














          0












          0








          0







          Did some experimenting. Yes, create ~/.config/powershell if it doesn't exist, and save your profile in a file named exactly Microsoft.VSCode_profile.ps1



          Example:



          function prompt {
          "$(Get-Date) $(Resolve-Path -Relative -Path $(Get-Location))> "
          }


          ...will return something like this if your path is /Users/<you>/Documents/powershellscripts/



          03/11/2019 20:11:32 ../powershellscripts>





          share|improve this answer













          Did some experimenting. Yes, create ~/.config/powershell if it doesn't exist, and save your profile in a file named exactly Microsoft.VSCode_profile.ps1



          Example:



          function prompt {
          "$(Get-Date) $(Resolve-Path -Relative -Path $(Get-Location))> "
          }


          ...will return something like this if your path is /Users/<you>/Documents/powershellscripts/



          03/11/2019 20:11:32 ../powershellscripts>






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Mar 12 at 3:19









          DrKumarDrKumar

          145




          145













          • Correct, you need the profile for such use cases, and again, you have to set OSX to start with pwsh.exe in the user setting of VSCode by setting the terminal path and that part is in the terminal section of the docs.

            – postanote
            Mar 12 at 3:48



















          • Correct, you need the profile for such use cases, and again, you have to set OSX to start with pwsh.exe in the user setting of VSCode by setting the terminal path and that part is in the terminal section of the docs.

            – postanote
            Mar 12 at 3:48

















          Correct, you need the profile for such use cases, and again, you have to set OSX to start with pwsh.exe in the user setting of VSCode by setting the terminal path and that part is in the terminal section of the docs.

          – postanote
          Mar 12 at 3:48





          Correct, you need the profile for such use cases, and again, you have to set OSX to start with pwsh.exe in the user setting of VSCode by setting the terminal path and that part is in the terminal section of the docs.

          – postanote
          Mar 12 at 3:48













          0














          This is fully documented in the VSCode docs and on this site and all over the web.



          A simple search using 'vscode custom prompt' would give the links for this use case.



          It's just a function you add to your profile. I like to keep things a simple as possible, so, here mine on Windows. It's a blank prompt line with the path displayed in the GUI title bar that I use for all my profiles (PowerShell, ISE, VSCode).



          Function Prompt 
          {
          # get the last command from history
          $command = Get-History -Count 1

          # set it to the window title
          if ($command)
          {
          $CurrentUser = [System.Security.Principal.WindowsIdentity]::GetCurrent()
          $principal = new-object System.Security.principal.windowsprincipal($CurrentUser)
          if ($principal.IsInRole("Administrators")) { $Role = 'Administrator: ' }
          Else { $Role = 'User: ' }

          $host.ui.rawui.WindowTitle = $Role + $PWD
          }


          # specify your custom prompt, e.g. the default PowerShell:
          " "
          }


          So, the above works, but in VSCode, it does not change the title bar, because that is tied to the file you have open. Yet, you are just looking at the prompt. So, this approach should get you there.



          This has been covered on stackexchange as well..



          How to customize the shell prompt in the VS Code terminal on macOS



          Also, see the VSCode docs for more on the terminal setup / customization.



          Integrated Terminal




          In Visual Studio Code, you can open an integrated terminal, initially
          starting at the root of your workspace. This can be convenient as you
          don't have to switch windows or alter the state of an existing
          terminal to perform a quick command-line task.







          share|improve this answer


























          • Please note that I was asking specifically about the PowerShell console that comes with the PowerShell extension. While there are documents and posts everywhere regarding the default terminal (VSCode defaults to bash on Mac), I searched exhaustively for PowerShell specific docs/SE questions, and could not find them.

            – DrKumar
            Mar 12 at 3:40













          • You have to set OSX to default to PowerShell. For this... Name : Visual Studio Code Host … it's the same prompt function. That console, is the ISE version of the console in VSCode. You still have the console host one as well and can be run together as needed. Of course you can add others. You just set it using the OSX paths / format you'd want.

            – postanote
            Mar 12 at 3:44


















          0














          This is fully documented in the VSCode docs and on this site and all over the web.



          A simple search using 'vscode custom prompt' would give the links for this use case.



          It's just a function you add to your profile. I like to keep things a simple as possible, so, here mine on Windows. It's a blank prompt line with the path displayed in the GUI title bar that I use for all my profiles (PowerShell, ISE, VSCode).



          Function Prompt 
          {
          # get the last command from history
          $command = Get-History -Count 1

          # set it to the window title
          if ($command)
          {
          $CurrentUser = [System.Security.Principal.WindowsIdentity]::GetCurrent()
          $principal = new-object System.Security.principal.windowsprincipal($CurrentUser)
          if ($principal.IsInRole("Administrators")) { $Role = 'Administrator: ' }
          Else { $Role = 'User: ' }

          $host.ui.rawui.WindowTitle = $Role + $PWD
          }


          # specify your custom prompt, e.g. the default PowerShell:
          " "
          }


          So, the above works, but in VSCode, it does not change the title bar, because that is tied to the file you have open. Yet, you are just looking at the prompt. So, this approach should get you there.



          This has been covered on stackexchange as well..



          How to customize the shell prompt in the VS Code terminal on macOS



          Also, see the VSCode docs for more on the terminal setup / customization.



          Integrated Terminal




          In Visual Studio Code, you can open an integrated terminal, initially
          starting at the root of your workspace. This can be convenient as you
          don't have to switch windows or alter the state of an existing
          terminal to perform a quick command-line task.







          share|improve this answer


























          • Please note that I was asking specifically about the PowerShell console that comes with the PowerShell extension. While there are documents and posts everywhere regarding the default terminal (VSCode defaults to bash on Mac), I searched exhaustively for PowerShell specific docs/SE questions, and could not find them.

            – DrKumar
            Mar 12 at 3:40













          • You have to set OSX to default to PowerShell. For this... Name : Visual Studio Code Host … it's the same prompt function. That console, is the ISE version of the console in VSCode. You still have the console host one as well and can be run together as needed. Of course you can add others. You just set it using the OSX paths / format you'd want.

            – postanote
            Mar 12 at 3:44
















          0












          0








          0







          This is fully documented in the VSCode docs and on this site and all over the web.



          A simple search using 'vscode custom prompt' would give the links for this use case.



          It's just a function you add to your profile. I like to keep things a simple as possible, so, here mine on Windows. It's a blank prompt line with the path displayed in the GUI title bar that I use for all my profiles (PowerShell, ISE, VSCode).



          Function Prompt 
          {
          # get the last command from history
          $command = Get-History -Count 1

          # set it to the window title
          if ($command)
          {
          $CurrentUser = [System.Security.Principal.WindowsIdentity]::GetCurrent()
          $principal = new-object System.Security.principal.windowsprincipal($CurrentUser)
          if ($principal.IsInRole("Administrators")) { $Role = 'Administrator: ' }
          Else { $Role = 'User: ' }

          $host.ui.rawui.WindowTitle = $Role + $PWD
          }


          # specify your custom prompt, e.g. the default PowerShell:
          " "
          }


          So, the above works, but in VSCode, it does not change the title bar, because that is tied to the file you have open. Yet, you are just looking at the prompt. So, this approach should get you there.



          This has been covered on stackexchange as well..



          How to customize the shell prompt in the VS Code terminal on macOS



          Also, see the VSCode docs for more on the terminal setup / customization.



          Integrated Terminal




          In Visual Studio Code, you can open an integrated terminal, initially
          starting at the root of your workspace. This can be convenient as you
          don't have to switch windows or alter the state of an existing
          terminal to perform a quick command-line task.







          share|improve this answer















          This is fully documented in the VSCode docs and on this site and all over the web.



          A simple search using 'vscode custom prompt' would give the links for this use case.



          It's just a function you add to your profile. I like to keep things a simple as possible, so, here mine on Windows. It's a blank prompt line with the path displayed in the GUI title bar that I use for all my profiles (PowerShell, ISE, VSCode).



          Function Prompt 
          {
          # get the last command from history
          $command = Get-History -Count 1

          # set it to the window title
          if ($command)
          {
          $CurrentUser = [System.Security.Principal.WindowsIdentity]::GetCurrent()
          $principal = new-object System.Security.principal.windowsprincipal($CurrentUser)
          if ($principal.IsInRole("Administrators")) { $Role = 'Administrator: ' }
          Else { $Role = 'User: ' }

          $host.ui.rawui.WindowTitle = $Role + $PWD
          }


          # specify your custom prompt, e.g. the default PowerShell:
          " "
          }


          So, the above works, but in VSCode, it does not change the title bar, because that is tied to the file you have open. Yet, you are just looking at the prompt. So, this approach should get you there.



          This has been covered on stackexchange as well..



          How to customize the shell prompt in the VS Code terminal on macOS



          Also, see the VSCode docs for more on the terminal setup / customization.



          Integrated Terminal




          In Visual Studio Code, you can open an integrated terminal, initially
          starting at the root of your workspace. This can be convenient as you
          don't have to switch windows or alter the state of an existing
          terminal to perform a quick command-line task.








          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Mar 12 at 3:55

























          answered Mar 12 at 3:36









          postanotepostanote

          1,163133




          1,163133













          • Please note that I was asking specifically about the PowerShell console that comes with the PowerShell extension. While there are documents and posts everywhere regarding the default terminal (VSCode defaults to bash on Mac), I searched exhaustively for PowerShell specific docs/SE questions, and could not find them.

            – DrKumar
            Mar 12 at 3:40













          • You have to set OSX to default to PowerShell. For this... Name : Visual Studio Code Host … it's the same prompt function. That console, is the ISE version of the console in VSCode. You still have the console host one as well and can be run together as needed. Of course you can add others. You just set it using the OSX paths / format you'd want.

            – postanote
            Mar 12 at 3:44





















          • Please note that I was asking specifically about the PowerShell console that comes with the PowerShell extension. While there are documents and posts everywhere regarding the default terminal (VSCode defaults to bash on Mac), I searched exhaustively for PowerShell specific docs/SE questions, and could not find them.

            – DrKumar
            Mar 12 at 3:40













          • You have to set OSX to default to PowerShell. For this... Name : Visual Studio Code Host … it's the same prompt function. That console, is the ISE version of the console in VSCode. You still have the console host one as well and can be run together as needed. Of course you can add others. You just set it using the OSX paths / format you'd want.

            – postanote
            Mar 12 at 3:44



















          Please note that I was asking specifically about the PowerShell console that comes with the PowerShell extension. While there are documents and posts everywhere regarding the default terminal (VSCode defaults to bash on Mac), I searched exhaustively for PowerShell specific docs/SE questions, and could not find them.

          – DrKumar
          Mar 12 at 3:40







          Please note that I was asking specifically about the PowerShell console that comes with the PowerShell extension. While there are documents and posts everywhere regarding the default terminal (VSCode defaults to bash on Mac), I searched exhaustively for PowerShell specific docs/SE questions, and could not find them.

          – DrKumar
          Mar 12 at 3:40















          You have to set OSX to default to PowerShell. For this... Name : Visual Studio Code Host … it's the same prompt function. That console, is the ISE version of the console in VSCode. You still have the console host one as well and can be run together as needed. Of course you can add others. You just set it using the OSX paths / format you'd want.

          – postanote
          Mar 12 at 3:44







          You have to set OSX to default to PowerShell. For this... Name : Visual Studio Code Host … it's the same prompt function. That console, is the ISE version of the console in VSCode. You still have the console host one as well and can be run together as needed. Of course you can add others. You just set it using the OSX paths / format you'd want.

          – postanote
          Mar 12 at 3:44




















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Super User!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1413269%2fhow-do-i-customize-the-powershell-integrated-console-prompt-in-vscode-on-mac%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Probability when a professor distributes a quiz and homework assignment to a class of n students.

          Aardman Animations

          Are they similar matrix