Skip to content

Instantly share code, notes, and snippets.

@mmattozzi
Created March 3, 2011 16:15
Show Gist options
  • Save mmattozzi/853024 to your computer and use it in GitHub Desktop.
Save mmattozzi/853024 to your computer and use it in GitHub Desktop.
OSX: Changing iterm tab with each cd
I created a perl script:
#!/usr/bin/perl -w
my $dir = `pwd`;
chomp $dir;
$dir =~ s/\/trunk$//;
$dir = substr($dir, rindex($dir, "/") + 1);
print "\033]0;$dir\007";
Then set the PROMPT_COMMAND variable in my ~/.bash_profile:
export PROMPT_COMMAND="$HOME/scripts/dir.pl"
Now whenever I change directories, the tab title is set in iterm. Also, if I am in a trunk directory
(as is often the case) the terminal tab will be set to the name of the directory above it.
@mmattozzi
Copy link
Author

Also works in regular Mac Terminal.

And yes, this means every time you run any command, perl will run. Is that bad? I think today's machines should be able to handle it. Although it'd be nice to find a way to do this sort of string manipulation in just bash. Not sure if that's possible anyway without invoking sed or something.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment