Open4

現時点でのターミナルの環境を晒す

ピン留めされたアイテム
紅孔雀紅孔雀

備忘録も兼ねてます。いいなと思った設定があったらパクって行ってください。
細かい設定ファイルの中身は下記リンク。

紅孔雀紅孔雀

必要条件

zsh: バージョン 4.3.9 以上
git: バージョン 1.7 以上
awk: mawk 以外の AWK 処理系

紅孔雀紅孔雀

下準備

  • Homebrewのインストール
    $ /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
    
  • zplugpecofzfjqghqtmuxanyenvのインストール
    $ brew install zplug peco fzf jq ghq tmux anyenv
    
  • anyenvに一時的にPATHを通す
    $ anyenv install --init
    $ eval "$(anyenv init -)"
    
  • anyenv-updateのインストール
    $ mkdir -p $(anyenv root)/plugins
    $ git clone https://github.com/znz/anyenv-update.git $(anyenv root)/plugins/anyenv-update
    
  • pyenvのインストール
    $ anyenv install pyenv
    
  • miniforge3-4.10.3-10のインストール(arm64(M1 Mac)ではpyenvでPython3系のコンパイルが上手くいかないため)
    $ pyenv install miniforge3-4.10.3-10
    $ pyenv global miniforge3-4.10.3-10
    
  • powerline-statusのインストール
    $ pip install powerline-status
    
  • tmux-powerlineのインストール
    $ git clone https://github.com/erikw/tmux-powerline ~/.tmux/tmux-powerline
    
  • ターミナルアプリやVSCodeなどのターミナルをPowerlineに対応した日本語フォントに変更。
    今回は別の端末にてMigu 1MをベースにFont Mergerfontforgeを使用して生成したMigu 1M for Powerlineをインストールして使用した。(参考: ターミナルでアイコンフォントを使う理由 | IIJ Engineers Blog)
紅孔雀紅孔雀

設定ファイル編集

  • ~/.zshrcを以下の内容に編集
    if type brew > /dev/null 2>&1; then
      # brew install zplug
      export ZPLUG_HOME="$(brew --prefix zplug)"
    else
      # git clone https://github.com/zplug/zplug ~/.zsh/zplug
      export ZPLUG_HOME="${HOME}/.zsh/zplug"
    fi
    source "${ZPLUG_HOME}/init.zsh"
    
    MY_REPO="redpeacock78/1bcf09ddc288f75adf8c3d182e870ae2"
    
    zplug "mafredri/zsh-async"
    zplug "b4b4r07/enhancd", use:init.sh
    zplug "b4b4r07/emoji-cli", if:'type fzf && type jq'
    zplug "zsh-users/zsh-completions"
    zplug "zdharma-continuum/fast-syntax-highlighting", use:fast-syntax-highlighting.plugin.zsh
    zplug "${MY_REPO}", from:gist, use:alias.zsh
    zplug "${MY_REPO}", from:gist, use:default-set.zsh
    zplug "${MY_REPO}", from:gist, use:environment.zsh, defer:1
    zplug "${MY_REPO}", from:gist, use:pip-ext.zsh
    zplug "${MY_REPO}", from:gist, use:256-color.zsh
    zplug "${MY_REPO}", from:gist, use:tmux.zsh, if:'type tmux', defer:2
    zplug "${MY_REPO}", from:gist, use:git-swich-peco.zsh, if:'type peco'
    zplug "${MY_REPO}", from:gist, use:peco-select-history.zsh, if:'type peco'
    zplug "${MY_REPO}", from:gist, use:peco-ghq.zsh, if:'type peco && type ghq'
    zplug "${MY_REPO}", from:gist, use:redpeacock78s.zsh-theme, as:theme
    zplug "PythonNut/auto-fu.zsh", use:auto-fu.zsh, defer:2
    zplug "${MY_REPO}", from:gist, use:auto-fu.zsh, defer:3
    
    if ! zplug check --verbose; then
      printf "Install? [y/N]: "
      if read -q; then
        echo
        zplug install
      fi
    fi
    
    zplug load
    
  • ~/.tmux/tmux-powerline/config/default.shを以下の内容に編集
    # Default values for non segment configuration options.
    
    export TMUX_POWERLINE_DEBUG_MODE_ENABLED_DEFAULT="false"
    export TMUX_POWERLINE_PATCHED_FONT_IN_USE_DEFAULT="true"
    export TMUX_POWERLINE_THEME_DEFAULT="default"
    
    #Statusline_left
    if [ -z $TMJX_POWERLINE_LEFT_STATUSSEGMENTS ]; then
      TMUX_POWERLINE_LEFT_STATUS_SEGMENTS=(
        "tmux_session_info 148 022" \ #session
        "hostname 031 117" \ #host_name
        "vcs_compare 60 255" \ #Compare
        "vcs_modifierd 9 255" \ #Staged
        "ifstat 30 255" \ #network_use_%
      )
    fi
    
    #statusline_right
    if [ -z $TMUX_POWERLINE_RIGHT_STATUS_SEGMENTS ]; then
      TMUX_POWERLINE_RIGHT_STATUS_SEGMENTS=(
        "vcs_branch 031 117" \ #branch_name
        "date 161 7 ${TMUX_POWERLINE_SEPARATOR_LEFT_THIN}" \ #date
        "date_day 161 007" \ #day
        "time 148 022 ${TMUX_POWERLINE_SEPARATOR_LEFT_THIN}" \ #time
      )
    fi
    
  • ~/.tmux.confを以下の内容に編集
    ###Prefixキーをctrl+t変更###
    set -g prefix C-t
    
    ###コピーモードをvi風にする###
    setw -g mode-keys vi
    
    ###マウス操作を有効化###
    set -g mouse on
    bind-key -T edit-mode-vi WheelUpPane send-keys -X scroll-up
    bind-key -T edit-mode-vi WheelDownPane send-keys -X scroll-down
    tmux_commands_with_legacy_scroll="nano less more man git bat"
    bind-key -T root WheelUpPane \
    	if-shell -Ft= '#{?mouse_any_flag,1,#{pane_in_mode}}' \
    		'send -Mt=' \
    		'if-shell -t= "#{?alternate_on,true,false} || echo \"#{tmux_commands_with_legacy_scroll}\" | grep -q \"#{pane_current_command}\"" \
    			"send -t= Up" "copy-mode -et="'
    
    bind-key -T root WheelDownPane \
    	if-shell -Ft = '#{?pane_in_mode,1,#{mouse_any_flag}}' \
    		'send -Mt=' \
    		'if-shell -t= "#{?alternate_on,true,false} || echo \"#{tmux_commands_with_legacy_scroll}\" | grep -q \"#{pane_current_command}\"" \
    			"send -t= Down" "send -Mt="'
    bind-key -T copy-mode-vi MouseDragEnd1Pane send-keys -X copy-pipe-and-cancel "tmux copy-buffer pbcopy"
    
    ###Config更新バインド(ctrl-t+r)###
    bind r source-file ~/.tmux.conf \; display "Reload Config!"
    
    ###|でペインを縦分割###
    bind | split-window -h
    
    ###-でペインを横分割###
    bind - split-window -v
    
    ###tmuxで256色表示###
    set-option -g default-terminal screen-256color
    
    ###tmux-powerline###
    run-shell "powerline-daemon -q"
    run-shell "powerline-config tmux setup"
    set-option -g status on
    set-option -g status-interval 2
    set-option -g status-justify "left"
    set-option -g status-left-length 60
    set-option -g status-right-length 90
    set-option -g status-left "#(~/.tmux/tmux-powerline/powerline.sh left)"
    set-option -g status-right "#(~/.tmux/tmux-powerline/powerline.sh right)"