Mega-ZBlog

You are here.

Mega-ZBlog header image

Display the Path in the Command Prompt Title Bar

August 27th, 2008 · 19 Comments · Windows

Well I messed around a bit and came up with a rather nice solution. This emulates a feature of Linux’s gnome-terminal where you can set the titlebar to always reflect the terminal’s current directory.

Scroll down for code and instructions, or read on for “the process”.

I used this as a basis, but there are a number of things wrong with that article. First of all, the %=c:% variable returns the current directory on C:, not on the current drive. Since everyone except maybe some ultralight laptop owners have more than just a C: drive (I spend most of my time on E:, F:, and G: myself) this is unacceptable to me.

I quick search turned up %cd% which returns the current directory. Much nicer.

Now we have another little problem in the form of an extra prompt line that appears. I discovered by inserting “echo off” (which suppresses the prompt) before the first command in the doskey macro, then “echo on” at the end, this problem goes away quite nicely. I was almost done.

Then I just have to duplicate this doskey macro for other commands the article fails to consider, for example pushd and popd, plus all the drive letters. A for loop takes care of the latter, although I still can’t avoid the tedious typing of every letter in the alphabet (I need to start using powershell or cygwin bash or something).

In the end, here is what I have. Place both files in your system path somewhere (C:\WINDOWS\system32 meets this requirement).

titlepath.cmd

@echo off
doskey cd=echo off$Tcd $*$Ttitlepathhelper$Techo on
doskey chdir=echo off$Tchdir $*$Ttitlepathhelper$Techo on
doskey pushd=echo off$Tpushd $*$Ttitlepathhelper$Techo on
doskey popd=echo off$Tpushd $*$Ttitlepathhelper$Techo on
for %%x in (a b c d e f g h i j k l m n o p q r s t u v w x y z) do doskey %%x:=echo off$T%%x: $*$Ttitlepathhelper$Techo on
titlepathhelper

titlepathhelper.cmd

@title %cd%

You’ll notice titlepath takes a little bit to churn away… if it bothers you, you can remove some of the drive letters from the for list or remove that line completely if you don’t mind the title not updating when you change drives.

One last thing is if you want this to happen every time you launch a command prompt without having to type titlepath in.

Open HKEY_CURRENT_USER\Software\Microsoft\Command Processor in Registry Editor and make an AutoRun string value and set it to titlepath.cmd. Interestingly my batch file shouldn’t work at all according to this caveat, but I can’t get it to AutoRun when running through a for loop… odd.

Tags: ···

19 responses so far ↓

  • 1 Olivier Dagenais // Aug 27, 2011 at 1:56 pm

    Awesome, thank you for sharing! My console window titles are no longer this mysterious, opaque thing that I have to click on to find out which window is which, while secretly cursing the lack of a more *NIXish bash 🙂

    Cheers,
    – Oli

  • 2 Johnny Baloney // Dec 9, 2011 at 10:39 am

    Nice! Thanks 😀

  • 3 Donnie // Sep 12, 2013 at 8:35 pm

    Thanks so much for this post!

  • 4 Jayce // Oct 1, 2013 at 11:41 am

    Awesome!!! Even though it doesn’t auto update, I usually stay in the same folder all the time anyways. The only reason I do change is because I can’t find the prompt i’m looking for! Now I can!

    Thanks!

  • 5 ciprofloxacin cost walmart // Apr 25, 2020 at 5:35 am

    ciprofloxacin cost walmart

    Display the Path in the Command Prompt Title Bar

  • 6 albuterol inhaler // Apr 27, 2020 at 4:03 am

    albuterol inhaler

    Display the Path in the Command Prompt Title Bar

  • 7 viagra sales // Apr 28, 2020 at 2:02 pm

    viagra sales

    Display the Path in the Command Prompt Title Bar

  • 8 cialis no prescription // Apr 29, 2020 at 6:37 pm

    cialis no prescription

    Display the Path in the Command Prompt Title Bar

  • 9 chloroquine mexico over the counter // May 27, 2020 at 1:19 am

    chloroquine mexico over the counter

    Display the Path in the Command Prompt Title Bar

  • 10 hydroxychloroquine tablet price in india // Jun 3, 2020 at 2:03 am

    hydroxychloroquine tablet price in india

    Display the Path in the Command Prompt Title Bar

  • 11 buy cialis // Jul 1, 2020 at 1:02 pm

    buy cialis

    Display the Path in the Command Prompt Title Bar

  • 12 canadian healthcare viagra sales // Jul 11, 2020 at 10:24 am

    canadian healthcare viagra sales

    Display the Path in the Command Prompt Title Bar

  • 13 generic cialis 20mg // Jul 14, 2020 at 6:06 pm

    generic cialis 20mg

    Display the Path in the Command Prompt Title Bar

  • 14 generic viagra cheap // Jul 26, 2020 at 9:18 am

    generic viagra cheap

    Display the Path in the Command Prompt Title Bar

  • 15 cheapest 100 viagra uk // Jul 29, 2020 at 7:48 am

    cheapest 100 viagra uk

    Display the Path in the Command Prompt Title Bar

  • 16 buy hydroxychloroquine online // Aug 7, 2020 at 9:00 pm

    buy hydroxychloroquine online

    Display the Path in the Command Prompt Title Bar

  • 17 price of sildenafil 100mg // Sep 16, 2020 at 8:14 am

    price of sildenafil 100mg

    Display the Path in the Command Prompt Title Bar

  • 18 cialistodo.com // Sep 22, 2020 at 6:50 am

    cialistodo.com

    Display the Path in the Command Prompt Title Bar

  • 19 generic viagra without subscription walmart // Sep 22, 2020 at 6:39 pm

    generic viagra without subscription walmart

    Display the Path in the Command Prompt Title Bar

You must log in to post a comment.