iTerm2 icon indicating copy to clipboard operation
iTerm2 copied to clipboard

Add interactive directory actions popover to status bar

Open kud opened this issue 1 month ago • 5 comments

Summary

This PR enhances the Current Directory widget in iTerm2's status bar with an interactive popover interface, similar to the existing Job Name widget functionality.

Changes

When clicking on the Current Directory status bar widget, users now see a popover with 5 useful actions:

  1. Copy Full Path - Copies the complete directory path to clipboard
  2. Copy Directory Name - Copies just the directory name (basename) to clipboard
  3. Reveal in Finder - Opens Finder and shows the directory
  4. Open in New Window - Opens a new iTerm2 window in that directory
  5. Open in New Tab - Opens a new tab in the current window in that directory

Implementation Details

  • Created iTermDirectoryActionsViewController for the popover UI
  • Updated iTermStatusBarWorkingDirectoryComponent to show popover on click
  • Proper dark mode support using effectiveAppearance
  • Leverages iTermSessionLauncher for opening new windows/tabs
  • Follows existing code patterns from the Job Name widget

Testing

The feature has been implemented following iTerm2's existing patterns and should work seamlessly with both light and dark modes.

Screenshots

The popover provides a clean, native macOS interface that matches iTerm2's visual style and adapts to the current appearance mode.

kud avatar Nov 26 '25 22:11 kud

If you want to change only Current Directory then you should modify iTermStatusBarWorkingDirectoryComponent, not iTermStatusBarVariableBaseComponent. I don't think these actions make sense for other subclasses of iTermStatusBarVariableBaseComponent like username and hostname.

Also, why not stick with the existing NSMenu? It has the benefit of allowing mouse-down+drag and is a more consistent look with other components that show menus on click (git, actions, and snippets).

gnachman avatar Dec 01 '25 05:12 gnachman

@gnachman Like this?

kud avatar Dec 01 '25 19:12 kud

@gnachman Thanks, I will check this.

I'm not sure what I'm doing here, but I do feel it's frustrating not having any action on that widget. We are missing an opportunity here.

If you have any good idea, happy to implement it.

kud avatar Dec 02 '25 11:12 kud

Done! Changed both methods to use the mutable profile copy pattern with KEY_WORKING_DIRECTORY and KEY_CUSTOM_DIRECTORY. Thanks for the feedback!

kud avatar Dec 03 '25 22:12 kud

I would just put this in an NSMenu instead of creating a whole new view controller by adding it to the existing openMenuWithView: method.

gnachman avatar Dec 05 '25 17:12 gnachman