tmux 中的 $SHELL 与我启动它的 shell 中的 $SHELL 不同

tmux 中的 $SHELL 与我启动它的 shell 中的 $SHELL 不同

我已经为此苦苦挣扎了几个小时,这让我发疯。当我通过 SSH 连接到家里的机器时,我的默认 shell 是 zsh。我可以用 确认这一点echo $SHELL,它输出/usr/bin/zsh

当我从 zsh 调用 tmux 时,它会将我带入带有 bash shell 的 tmux 窗格。如果我运行echo $SHELL,它会输出/bin/bash.如果我然后运行chsh -s /usr/bin/zsh <user>, $SHELL 变量实际上并没有得到更新,并且仍然输出\bin\bash

我从 tmux 手册页中知道默认 shell 是在 ~/.tmux.conf 文件中设置的,我也这样做了,但似乎没有效果。我将在此处包含我的相关配置文件。

我应该提到,我的 .tmux.conf 中的其他配置生效;我的按键绑定工作,颜色匹配等。无法弄清楚,非常感谢任何帮助。

硬件是运行最新版本的 raspbian 的 Raspberry Pi 4。

〜/.tmux.conf:

unbind C-b
set-option -g prefix C-q
bind-key C-q send-prefix

bind h split-window 
bind v split-window -h

#set-option -g pane-border-fg colour235 #base02
#set-option -g pane-active-border-fg colour240 #base01

set -g default-terminal screen-256color
set -g status-keys vi
set -g history-limit 10000

setw -g mode-keys vi
setw -g monitor-activity on

bind-key -r J resize-pane -D 5
bind-key -r K resize-pane -U 5
bind-key -r H resize-pane -L 5
bind-key -r L resize-pane -R 5

bind-key -n M-K resize-pane -U 5
bind-key -n M-J resize-pane -D 5
bind-key -n M-H resize-pane -L 5
bind-key -n M-L resize-pane -R 5

# Shift arrow to switch windows
bind -n M-N  previous-window
bind -n M-M next-window

set -sg escape-time 0

# Smart pane switching with awareness of Vim splits.
# See: https://github.com/christoomey/vim-tmux-navigator
is_vim="ps -o state= -o comm= -t '#{pane_tty}' \
    | grep -iqE '^[^TXZ ]+ +(\\S+\\/)?g?(view|n?vim?x?)(diff)?$'"
bind-key -n C-h if-shell "$is_vim" "send-keys C-h"  "select-pane -L"
bind-key -n C-j if-shell "$is_vim" "send-keys C-j"  "select-pane -D"
bind-key -n C-k if-shell "$is_vim" "send-keys C-k"  "select-pane -U"
bind-key -n C-l if-shell "$is_vim" "send-keys C-l"  "select-pane -R"
bind-key -n C-\ if-shell "$is_vim" "send-keys C-\\" "select-pane -l"

set -g status-bg "black"
set -g status-fg "white"

~/.zshrc 是一个好的措施:

# OMZ home directory
export ZSH=/home/joe/.oh-my-zsh

# Set OMZ theme
ZSH_THEME=spaceship
SPACESHIP_CHAR_SUFFIX=' '
SPACESHIP_HOST_SHOW=always
SPACESHIP_USER_SHOW=always
SPACESHIP_PROMPT_ORDER=(
user          # Username section
host          # Hostname section
dir           # Current directory section
git           # Git section (git_branch + git_status)
exec_time     # Execution time
battery       # Battery level and status
vi_mode       # Vi-mode indicator
jobs          # Background jobs indicator
exit_code     # Exit code section
char          # Prompt character
)

# Couple OMZ settings
COMPLETION_WAITING_DOTS="true"
plugins=(git sudo wd tmux)

# Source OMZ file, needs to be *before* other aliases
source $ZSH/oh-my-zsh.sh

# Fixes some undesirable behavior in Termite with OMZ
export LC_CTYPE="en_US.UTF-8"
export ANDROID_HOME="/home/joe/Android/Sdk/"

# User Specified Aliases
alias ekeymap="vim /home/joe/qmk_firmware/keyboards/ergodox_ez/keymaps/josephemorgan91"
alias rename=perl-rename
alias zconfig="vim ~/.zshrc"
alias zsource="source ~/.zshrc"
alias ls="ls --color=auto"
alias la="ls -a --color=auto"
alias ll="ls -la --color=auto"
alias keyswapper="~/Scripts/keyswapper"
alias sheader="~/Scripts/student_header.sh"
alias ctags="ctags -R -f ./.git/tags ."
alias tmux="tmux -u"
alias R="R --quiet"
alias update-grub="sudo zsh ~/Scripts/update-grub"
alias vimconfig="vim ~/.vimrc"
alias emacs="emacs -nw"

# Setup folder for dev
    alias cconfig="cp ~/Scripts/ycm_c_config ./.ycm_extra_config.py"
    alias gitignore="cp ~/.dotfiles/.gitignore ./.gitignore"
    alias readme="cp ~/.dotfiles/.README_TEMPLATE ./README"
    alias gogit="readme & gitignore & git init"

    set_wallpaper() {
        echo "Setting wallpaper: $PWD/$1\n"
        ln -s -f -v $PWD/$1 /home/joe/.wallpaper.jpg
        ln -s -f -v $PWD/$2 /home/joe/.wallpaper-lh.jpg
        feh --bg-scale $PWD/$2 --bg-scale $PWD/$1
    }

# Uses xclip application to pipe output to clipboard.
# Usage - $ cat /path/to/a/file | xclip
# Works on any utility that produces output
alias xclip="xclip -selection c"

export EDITOR='vim'

export term="xterm-256color"

# if command -v tmux>/dev/null; then
#   [[ ! $TERM =~ screen ]] && [ -z $TMUX ] && exec tmux
# fi

stty -ixon

xset r rate 200 45

答案1

解决方案是将以下行添加到 .tmux.conf 中

set-option -g default-shell /bin/zsh

愚蠢的是我肯定知道这一点并且实际上确实添加了该行,但我似乎没有保存文件或在这样做后没有重新启动服务器。当我第二天连接时,一切开始正常工作。

相关内容