Update ConEmu tab with current path

9

2

On ConEmu I'm opening a powershell console. I'd like the title of the tab to reflect the current folder I'm in. However, by default, the title is "Windows Powershell."

I specified the tab title in my task to be "C:\Code" and it updates, but that is hard coded.

Is there a way to open a powershell console, and as I navigate have it show me the current directory in the tab title?

taylonr

Posted 2013-08-21T14:17:38.177

Reputation: 193

Answers

10

PowerShell

Change prompt function in your powershell profile.

Open your profile in the editor, Notepad for example

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

Add following function to change (rename actually) ConEmu tab each time prompt appears

function prompt
{
  & "$env:ConEmuBaseDir\ConEmuC.exe" "/GUIMACRO", 'Rename(0,@"'$(Get-Location)'")' > $null
  return "PS " + $(Get-Location) + ">"
}

or use following code to change console title, but not tab

function prompt
{
  & "$env:ConEmuBaseDir\ConEmuC.exe" "/GUIMACRO", 'Rename(1,@"'$(Get-Location)'")' > $null
  return "PS " + $(Get-Location) + ">"
}

May be need to change this code, if you need to use PowerShell outside of ConEmu.


cmd (let it be in one answer)

If you are using cmd.exe, you may update ConEmu tab with cmd's current directory using prompt and ANSI. Just run your cmd as following:

cmd /k prompt $p$e]9;3;"$p"$e\$g & title cmd

To be able to process ANSI you need to enable Inject ConEmuHk and ANSI X3.64 options in the ConEmu's Features settings page (they are enabled by default). RightClick on the ConEmu's window title or press WinAltP to open Settings dialog.

Note, & title cmd in the example is not required, just for prettify window caption.

Maximus

Posted 2013-08-21T14:17:38.177

Reputation: 19 395

With latest version you may use %d macro in the tab template. However, may be you need to configure your shell https://code.google.com/p/conemu-maximus5/wiki/ShellWorkDir

– Maximus – 2014-09-11T08:11:20.800