Terminal: The ‘[‘ Marks the Spot

Using Terminal on macOS you may at some point have wondered about the small gray square brackets before the prompt. (There is also a counterpart closing bracket ‘]’ at the right side of Terminal window.)

Marks in Terminal

They appeared first in Terminal in El Capitan (10.11). They are called ‘Marks’ and simplify scrolling through the output in the Terminal window.

By default, every command that is executed automatically gets marked.

Jump to the Mark

You can quickly scroll the Terminal output to previous marks (i.e. command prompts) with ⌘↑ (Command-Up Arrow) and to next mark with ⌘↓ (Command Down-Arrow). This allow you to quickly skip through the command prompts in your window.

Select Output

You can quickly select output between Marks. ⌘⇧↑ (Command-Shift-Up) will select the output up to, but not including the previous command prompt. ⌘⇧↓ (Command-Shift-Down) will select the output up to, but not including the next command prompt. When you repeatedly hit this key combo the selection will be extended further, including the intermittent command prompts.

⌘⇧A (Command-Shift-A) or ‘Select Between Marks’ from the ‘Edit’ menu, will select to the previous mark, if you are the last (empty) command prompt, otherwise it will select to the next mark.

Clearing Output

You can also just remove the output of the previous command with ‘Clear to Previous Mark’ from the ‘Edit’ menu (⌘L). This is less destructive than clearing the entire screen or buffer.

Marks and Bookmarks

Marks are very useful. However, they are all the same, so jumping back to a specific mark in your Terminal scroll buffer will get harder and harder you have to hit ⌘↑ more and more often.

You can elevate a mark to a bookmark, which will allow you to jump directly to it. Jump to the line you want to bookmark or select some text and choose ‘Mark as Bookmark’ from the ‘Edit’ menu (⌘⌥U) or context menu.

Bookmarks have a bolder vertical bar ‘|’ at the left and right edge of the window.

You can jump to previous and next bookmarks with ⌘⌥↑ and ⌘⌥↓, or you jump directly to a bookmark from the list in the ‘Edit’ > ‘Bookmark’ menu.

The ‘Edit’ > ‘Bookmarks’ menu also has ‘Insert Bookmark’ and ‘Insert Bookmark with Name…’ items. These will mark the current command prompt as a bookmark, and give you the option of naming the bookmark, rather than having the default timestamp as the name.

Terminal will set an automatic bookmark when restoring a Terminal window (after a reboot). This setting is controlled in the ‘Resume’ area in the ‘Window’ Tab of the Profiles area of the settings.

Not Leaving Marks

If the grey brackets indicating the marks annoy you, you can hide them with ‘Hide Marks’ from the ‘View’ menu. This will only hide the marks and bookmarks, they will still be automatically (or manually) created and you can still jump to them.

You can disable automatic mark creation entirely by deselecting ‘Automatically Mark Prompt Lines’ from the ‘Edit’ > ‘Marks’ submenu. When you have disabled automatic marking, you can execute and manually mark a prompt with ⌘↩︎ (Command-Return).

With automatic marking enabled, you can execute a command without marking with ⌘⇧↩︎ (Command-Shift-Return).

You can also manually remove a mark, by scrolling or jumping to it and choosing ‘Unmark’ from the ‘Edit’ > ‘Marks’ menu or the context menu.

Marking Spots Programatically

I have added the following aliases to my .bash_profile:

alias mark="osascript -e 'if app \"Terminal\" is frontmost then tell app \"System Events\" to keystroke \"u\" using command down'"
alias bookmark="osascript -e 'if app \"Terminal\" is frontmost then tell app \"System Events\" to keystroke \"M\" using command down'"

This way I can put the mark in between two commands and just let them run:

$ system_profiler SPApplicationsDataType; mark; system_profiler SPExtensionsDataType

The downside of this approach that the aliases do not work when Terminal is in the background.

Published by

ab

Mac Admin, Consultant, and Author

5 thoughts on “Terminal: The ‘[‘ Marks the Spot”

  1. This is brilliant! Exactly what I was looking for to be able to select output of commands.

  2. Your mark alias even works inside of Python scripts when run with the subprocess module! Do you have any idea why it doesn’t work when the Terminal is in the background?

    1. The alias actively avoids running when Terminal is in background, because it achieves its goal by sending the keystrokes.

  3. Anybody know if there’s a configuration option somewhere to change the appearance of the bracket marks? I’d like to make them bold or a different color.

Comments are closed.