Mac OS X Cmdline

From HerzbubeWiki
Jump to navigation Jump to search

Terminal.app preferences

Colors

The colors in the following list are given as decimal RGB values.

  • Cursor: 85, 85, 85 (dark gray)
  • Normal text: 0, 0, 0 (black)
  • Selected text: 170, 170, 170 (light gray)
  • Bold text: 22, 227, 255 (cyan)
  • Background: 128, 133, 176 (dark lilac)


bash

Startup files

A login shell (regardless of whether or not it is interactive) reads/executes the following startup files:

    • /etc/profile
    • the first of the following files that exists
      • ~/.bash_profile
      • ~/.bash_login
      • ~/.profile

An interactive shell that is not a login shell (e.g. the shell started by Terminal.app) reads/executes the following startup files:

  • ~/.bashrc

A non-interactive shell that is not a login shell (e.g. to run a shell script, also during cron execution) reads/executes the following startup files:

  • the file listed by the environment variable BASH_ENV

This page does not discuss the bash behaviour, that is even more different, when bash is

  • invoked with the name sh
  • started with --posix
  • run by the remote shell daemon (e.g. rshd
  • run with an effective user/group id different from the real user/group id


zsh

After switching to macOS 14 and the default shell "zsh", I found that quite a few things were different compared to "bash", although zsh is labeled as "bash compatible".

Initialization files

  • Instead of ~/.profile and ~/.bashrc (bash) the zsh uses the files ~/.zprofile and ~/.zshrc.

Key bindings

  • Various key bindings that I am used from bash do not work as expected. Examples: Ctrl+A / Ctrl+E going to the beginning / end of the line, or Ctrl+R to search through the command history.
  • It seems that zsh sets its key bindings based on the value of the EDITOR or VISUAL envvars. In my case EDITOR was set to vim which causes the keymap "viins" to be selected.
  • Apparently what I am used to is the keymap "emacs". This can be set with the command bindkey -e. The setting is not inherited by sub-shells, to be available it therefore must be executed in ~/.zshrc.
  • I have added corresponding handling to my HTB script collection.
  • More options about the bindkey built-in can be found in the documentation of the zsh line editor (zshle).


Shell environment

Regardless of which shell I use, I set up my shell environment using my personal script collection. See the HTB wiki page.

Historic note: Old versions of **this** wiki page contain information how to set up bash differently.


Locale

Terminal.app preferences

In the "Emulation" tab:

  • Nicht-ASCII-Zeichen in Escape-Sequenz umwandeln = true

In the "Darstellung" tab

  • Zeichensatz-Codierung = Unicode (UTF-8)


Keyboard input

Note: This section is probably outdated.

Configure ~/.inputrc (possibly /usr/local/etc/linked.inputrc, making a symlink to it in your home directory)

192:~ --> cat .inputrc 

# ------------------------------------------------------------
# The following settings influence 8-bit character
# processing, e.g. Umlaute. The comments were taken
# from the man page of bash
# ------------------------------------------------------------
# If set to "on", readline converts 8-bit characters
# to 7-bit characters (i.e. remove the 8th bit) and
# prefix the character with an escacpe character
set convert-meta off

# If set to "on", readline enables 8-bit input
# (i.e. it doesn't strip the 8th bit from the input)
# regardless of what the terminal claims it can
# support
set input-meta on

# If set to "on", readline displays 8-bit characters
# directly instead of as an escape sequence
set output-meta on


Environment

Various commands installed through fink sometimes print helpful information. That information expects some kind of locale to be set. Do this by setting the LANG environment variable to some useful value. I set the variable in /usr/local/etc/setvar

LANG=de_CH.UTF-8

To get all available locales:

locale -a


vi

Add to ~/.vimrc

syntax enable
set encoding=utf-8