weird space before prompt using tmux on Mac OS Lion - zsh

it just happened on my Lion system, I am using zsh with tmux
normal in the zsh shell
double space in tmux screen
am I missing some config in zsh or tmux?

Start tmux with the -u option for unicode functionality. See this issue.
From man tmux:
-u
tmux attempts to guess if the terminal is likely to support UTF-8 by checking the first of the LC_ALL, LC_CTYPE and
LANG environment variables to be set for the string "UTF-8". This is not always correct: the -u flag explicitly
informs tmux that UTF-8 is supported.
If the server is started from a client passed -u or where UTF-8 is detected, the utf8 and status-utf8 options are
enabled in the global window and session options respectively.

I ran into this problem with zsh, byobu and tmux.
To fully solve it:
Add the following to ~/.zshrc:
export LC_ALL=en_US.UTF-8
export LANG=en_US.UTF-8
Add -u after byobu-lauch in ~/.zprofile:
_byobu_sourced=1 . /usr/bin/byobu-launch -u
Add the following to ~/.byobu/.tmux.conf:
set-option -g utf-8 on

I had the same problem when I changed system language to English. When I use command locale all fields was empty. And when I set format language in preferences (Language & Region -> Advanced) to Russian - command locale was with filled values and in tmux it was ok.

Related

Can tmux query physical terminal? (Maybe iTerm2 only)

I'm trying to detect the presence of iTerm2 and if I run the following in iTerm2 (echo -n $'\e[5n'; read -s -t 0.1 line; printf '%q\n' "$line") the terminal responds with $'\033'\[ITERM2\ 3.2.1n$'\033'\[0n
However, if I am running a tmux session in the terminal, then tmux responds and gives me nothing.
Any idea how I can ask tmux to query the physical terminal to report its status?
Footnotes
Here is a description of [5n in the tmux source: https://github.com/tmux/tmux/blob/486ce9b09855ae30a2bf5e576cb6f7ad37792699/tools/ansicode.txt#L577
This might be iTerm2 only, since I haven't seen a response on any other terminal
According to ft in freenode's #tmux (and as seen in this Super User answer), you can use:
'\ePtmux;\e" STUFF_FOR_THE_TERMINAL_HERE "\e\\'
So, it would be something like:
echo -n $'\ePtmux;\e\e[5n\e\\'

Scandinavian characters in tmux

# .tmux.conf
set -g status-utf8 on
setw -g utf8 on
Yet, still when I enter the scandinavian charaters æ, ø and å in the terminal window, I get the following output:
<00c3><00a6><00c3><00b8><00c3><00a5>
I'm using Iterm2 as my terminal, and the characters are printed correctly outside of tmux.
Are you using zsh? I was able to get it to produce a result like that (inside and outside tmux) by setting LC_CTYPE to en_US.US-ASCII while actually sending UTF-8 (i.e. lying to zsh (and other locale-sensitive programs) about what character set to expect).
Check that LC_ALL, LC_CTYPE, and/or LANG have an appropriate values inside your tmux session; you probably want to use a consistent value that ends with .UTF-8. You can use locale to view the active values and locale -a to list the available values.
You may also need to reset the errant variable(s) in your tmux global and/or sessions environments (so that new sessions/windows/panes do not keep getting the bad values). You can inspect the tmux global environment with
tmux show-environment -g | grep -E 'LC|LANG'
Adjust its values with (e.g.) tmux set-environment -g LANG "$your_value".
Each session can also override environment variables (for new windows and panes created in that session). You can inspect a session’s environment with
tmux show-environment -t "$session_name" | grep -E 'LC|LANG'
You can unset session environment values with (e.g.) tmux set-environment -t "$session_name" -u LANG (so that the global value will be used for new windows/panes), or adjust session values with tmux set-environment -t "$session_name" LANG "$your_value".
Or, if you do not have any important sessions, you could just restart the tmux server with a set of known-good locale environment variable values.

Change tmux default to zsh

When tmux opens, I would like it to use zsh instead of bash by default. How would I accomplish this?
From man tmux:
default-shell path
Specify the default shell. This is used as the login shell for new windows when the default-command option is set to empty, and must
be the full path of the executable. When started tmux tries to set a default value from the first suitable of the SHELL environment
variable, the shell returned by getpwuid(3), or /bin/sh. This option should be configured when tmux is used as a login shell.
So, in your tmux.conf:
# set shell
set -g default-shell /bin/zsh
and if you want you can add default command each time, when we start a new window:
# Retach userspaces
set -g default-command "reattach-to-user-namespace -l zsh"
You probably want zsh to be your default shell for most things, then (but this will not apply to cron). The following will make zsh your default shell, and you should then not need to tell tmux anything.
chsh -s /usr/bin/zsh
Note that some OSs still use /bin/zsh as the path to zsh.
If you prefer to set it individually for a session, but not for other (future) sessions, you can use
tmux new-session /bin/zsh \; set default-shell /bin/zsh

How do you switch to zsh when using Nitrous.io

Any ideas? I've tried using :
chsh -s /bin/zsh
But any password I've tried has failed.
You can't use zsh in the main console as you don't have root access, but you could utilize zsh with tmux (which is already installed on your Nitrous box).
You will just need to add this line into ~/.tmux.conf :
set-option -g default-shell /bin/zsh
Once this has been added, start a new tmux session by running:
tmux new -s session_name
Just put zsh at the end of ~/.bashrc to automatically start zsh in the main console when you log in.
Typing exit once will take you back to bash.

How to force emacs-style status-keys in tmux?

I have this problem with tmux 1.8: I want to set status-keys option to 'emacs' because I really dislike entering commands in vi-mode. However adding the following line to .tmux.conf has no effect:
set -g status-keys emacs
When tmux is restarted, tmux show-options -g | grep keys says emacs but the actual behaviour is vi-style.
The root of the problem is the $EDITOR environment variable, which it set to vim in my case. The documentations states:
status-keys [vi | emacs]
Use vi or emacs-style key bindings in the status line,
for example at the command prompt. The default is emacs,
unless the VISUAL or EDITOR environment variables are set
and contain the string `vi'.
So apparently when the environment variable is "vim" it forces vi status-keys.
Is there a way to override this behaviour and have the prompt behave emacs-style despite the environment variable? I can obviously hack around this (like starting tmux with other env variables and restoring the original later) but I hope there is a clean solution.
Thanks!
I had this problem and I think I just figured it out. Are you by chance also using ZSH (Z Shell)?
I found this post that says that ZSH will also switch to "vi mode" if your VISUAL and/or EDITOR is set to vi/vim. So the problem I was having in tmux as actually bubbling up from ZSH!
In short, make sure you can use emacs-style keys in your shell outside of tmux. If you're using ZSH you can add bindkey -e to .zshrc to set emacs bindings. Then in .tmux.conf:
set -g mode-keys emacs
set -g status-keys emacs
Both status-key and mode-keys default to vi if EDITOR contains vi, but this is only a default (during startup, before the configuration files are processed). Setting either of these options in your configuration should override the EDITOR-based default.
Are you also setting mode-keys (which controls the key maps used in copy-mode, and the choose-… commands)?
set -gw mode-keys emacs

Resources