How to display a clock in tmux?

Quick Answer

To display a clock in tmux, press Ctrl+b t. This shows a full-screen digital clock in the current pane. Toggle between digital and analog styles with the A key while the clock is displayed. Exit clock mode by pressing Escape or q.

Ctrl+b t

Detailed Explanation

The clock feature in tmux is a simple utility that can display the current time in either digital or analog format. It takes over the current pane temporarily but doesn't interfere with your running processes.

Basic Clock Mode Usage

# Enter clock mode
Ctrl+b t

# Exit clock mode
q
# or
Escape

When in clock mode, you can:

  • Press A to toggle between digital and analog display
  • Press q or Escape to exit clock mode
  • Press C to toggle between 12-hour and 24-hour format (digital mode only)

Using Clock Mode via Command

You can also enter clock mode using the tmux command interface:

# Enter digital clock mode
Ctrl+b :clock-mode

# Enter analog clock mode
Ctrl+b :clock-mode -t analog

# Enter digital clock mode with 24-hour time format
Ctrl+b :clock-mode -t digital

Customizing Clock Colors

You can customize the appearance of the clock by adding these settings to your ~/.tmux.conf file:

# Set the clock mode color
set-window-option -g clock-mode-colour green

# Set the 24-hour style (1 for 24h, 0 for 12h AM/PM)
set-window-option -g clock-mode-style 1

The clock-mode-colour can be set to any color name or hex value that tmux supports.

Persistent Clock in Status Bar

Instead of using the temporary clock mode, you might prefer to have a permanent clock in your tmux status bar:

# Add time to the right side of status bar
set -g status-right '%H:%M %d-%b-%y'

# For a more detailed timestamp
set -g status-right '%Y-%m-%d %H:%M:%S'

# For time with timezone
set -g status-right '%H:%M %Z'

The format string follows the standard strftime format used in many programming languages.

Creating a Dedicated Clock Window

For a permanent clock in a separate window, you can create a dedicated window with this command:

# Create a new window with a clock
Ctrl+b :new-window -n clock 'while true; do clear; date; sleep 1; done'

# Or for a fancier ASCII clock using tput
Ctrl+b :new-window -n clock 'while true; do tput clear; tput cup 0 0; date +"%H:%M:%S"; sleep 1; done'

Pro Tip

Create a special key binding for a dedicated clock window in your ~/.tmux.conf:

# Add a dedicated key binding for clock window
bind C new-window -n "⏰ Clock" 'while true; do clear; figlet -c $(date +"%H:%M:%S"); sleep 1; done'

This example uses figlet to create an ASCII art clock. You'll need to install figlet first (apt install figlet on Debian/Ubuntu, brew install figlet on macOS).

Clock Mode in Scripts

You can use clock mode in tmux scripts and automation. For example, to create a new session with a clock:

tmux new-session -d -s clocks
tmux send-keys -t clocks:0 'tmux clock-mode' C-m

This can be useful for creating dashboard displays or monitoring setups where you want a visible time reference.