Pedro Barros
Pedro Barros

Reputation: 183

Mac Terminal Bug With [ Character After Changing Colors

I just changed my colors in ~/.bash_profile using:

export PS1="\[\033[1;96m\]\u\[\033[0;0m\]:\[\033[1;33m\]\W\[\033[1;0m\]$ "

The problem is, I see a strange character on the previous lines of the prompt: (before "Pedro")

enter image description here

How can I fix this?

Upvotes: 0

Views: 226

Answers (1)

Chris Page
Chris Page

Reputation: 18693

These “square bracket” indicators surrounding a line are called “marks”. These indicate that the line was marked as a “prompt line”. They are not characters, they are visual markers drawn in the margins of the terminal view.

Marks provide structure to the terminal contents, enabling you to navigate, select, copy, delete, etc. lines of text in the terminal. By default, Terminal automatically marks prompt/input lines when you type Return, enabling you to perform operations on command lines and their output.

Marks were added to Terminal in OS X 10.11 El Capitan.

See the menu items in the Edit menu—especially the Marks, Bookmarks, and Navigate submenus—for Mark-related commands.

For example:

  • Edit > Navigate > Jump to Previous/Next Mark ⌘↑/⌘↓ : navigate to the previous/next command line. Add the Shift modifier to select text between marks.
  • Edit > Clear to Previous Mark ⌘L : delete the last command line and its output. This is context-sensitive and will clear the terminal content up to a mark selected via a Jump to… command, or to the start of the selection.
  • Edit > Select Marked Output ⇧⌘A : select the output of the last command (or between a selected mark and the next mark).

Note that many of the commands are designed to be used in combination, as well. For example, if you Select Marked Output then Clear to Start of Selection (⇧⌘A, ⌘L), it will delete the last command's output while leaving its command-line in place.

A Bookmark is a heavier-weight mark. Bookmarks are indicated with thick vertical lines in the view margins. The Edit > Bookmarks > Insert Bookmark ⇧⌘M command inserts a bookmarked line with the date and time (add the Option modifier to customize the text). Many of the Mark-related commands operate on (or restrict themselves to) Bookmarks if you add the Option modifier.

You can show or hide the visual mark indicators with View > Show/Hide Marks. All the Mark operations still work whether or not the indicators are displayed.

Upvotes: 1

Related Questions