Skip to content

Instantly share code, notes, and snippets.

@colelawrence
Created December 3, 2025 03:19
Show Gist options
  • Select an option

  • Save colelawrence/f1b999a685163ea507a65e0b45e6d165 to your computer and use it in GitHub Desktop.

Select an option

Save colelawrence/f1b999a685163ea507a65e0b45e6d165 to your computer and use it in GitHub Desktop.
iTerm2 Profile title renamer for Amp - /Users/cole/Library/Application Support/iTerm2/Scripts/AutoLaunch/amp_title.py
#!/usr/bin/env python3
import iterm2
import os
import re
async def main(connection):
@iterm2.TitleProviderRPC
async def custom_amp_title(
auto_name=iterm2.Reference("autoName?"),
pwd=iterm2.Reference("path?")):
dirname = os.path.basename(pwd) if pwd else ""
if not auto_name:
return dirname or ""
# Strip "amp - " prefix
cleaned = re.sub(r'^amp - ', '', auto_name)
# Strip any path suffix (e.g., " - ~/foo/bar" or " - /foo/bar")
cleaned = re.sub(r'\s*-\s*~?/.*$', '', cleaned)
# If we have a meaningful name after cleaning, show it + dirname
if cleaned and cleaned != dirname:
if dirname:
return f"{cleaned} · {dirname}"
return cleaned
return dirname or ""
await custom_amp_title.async_register(
connection,
display_name="Amp Title (cleaned)",
unique_identifier="com.phosphor.amp-title")
iterm2.run_forever(main)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment