24

Whenever I open tmux for the first time, it throws the following error.

/home/user/.tmux.conf:67: no current window

The relevant parts of the conf file are as follows.

 52 set-window-option -g window-status-fg "#666666"
 53 set-window-option -g window-status-bg default
 54 set-window-option -g window-status-attr default
 55 set-window-option -g window-status-current-fg red
 56 set-window-option -g window-status-current-bg default
 57 set-window-option -g window-status-current-attr default
 58 set-option -g message-fg white
 59 set-option -g message-bg black
 60 set-option -g message-attr bright
 61 set -g status-left " "
 62 set -g status-justify left
 63 setw -g window-status-format         ' #(echo "[#{window_index}]#{window_name}") '
 64 #setw -g window-status-current-format         ' #(echo "[#{window_index}]#{window_name}") '
 65 setw -g window-status-current-format ' #(echo "#{window_name}") '
 66 set -g status-right "#(echo $(date))"
 67 set allow-rename off
 68 set -sg escape-time 0

This error appears only for the first session I open, for subsequent sessions, the error does not appear.

Haran Rajkumar
  • 2,155
  • 16
  • 24

2 Answers2

37

You don't have -g on that set command so it needs a window to set the option on, but no windows exist yet.

Nicholas Marriott
  • 3,148
  • 9
  • 12
  • 3
    My `tmux.conf` only had `set mouse on`, but it was really the same problem and the same solution – Vince Feb 08 '21 at 09:17
  • What might output `no current client` with such a setup on the default config on the very first attach to a new main Tmux session where, for example, `TMUX='' tmux new-session -ds 'main'; exec tmux attach -t 'main';` outside of Tmux and without `main` prior set. Does it deserve a difference StackOverflow question since all the checked did not result in an expected enlightenment? ^^ – Artfaith Mar 20 '23 at 20:40
0

In addition to @Nicholas Marriott, for example, a script for the first Tmux launch (e.g. .bashrc):

TmuxSessionInit()
{
    declare sessionName="$1";
    shift;

    # Check if the Tmux session exists
    if ! tmux has-session -t="$sessionName" 2> '/dev/null';
    then
        # Create the Tmux session
        TMUX='' tmux new-session -ds "$sessionName";
    fi

    # Switch if inside of Tmux
    if [[ "${TMUX-}" != '' ]];
    then
        exec tmux switch-client -t "$sessionName";
    fi

    # Attach if outside of Tmux
    exec tmux attach -t "$sessionName";
}

TmuxSessionInit '0';

Related:
- https://en.wikipedia.org/wiki/Exec_(system_call)
- https://github.com/tmux/tmux/issues/769 (Feature request: session-base-index...)

Artfaith
  • 1,183
  • 4
  • 19
  • 29