0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

WIP Zellij を使おうと思った

Last updated at Posted at 2026-01-20

思ってること

  • tmux を使っているので,一旦戻ってもいい
    • 他人が使ってるのを見て,変えてもいいかもな.というのと,見た目分かり易そう
  • できれば,将来的には楽になりたい
    • 一時的な不便があってもよい
    • 新しい概念を導入してもいいけど,学習カーブがそれなりになると嬉しい

ふんわり(ユースケース)

  • 今までの使い方
    • session
      • メインは1つ
        • window は,別の仕事ができたら増やしたりする.workdir に cd するイメージ?
          • その window 内で pane を増やすことが多い
        • 固定のwindow と ↑ のようなtemp の window があって,固定の場所には数字で移動していた (ex. prefix + 0, 1, ...)
          • 仕事の切り替え,差し込み.みたいなことがよくあるイメージ
            • (ghq にしたっていいけど,とりあえず無しでもいい感じで自由
    • session の復活はしたい
      • attach の自動化みたいなことはやりたくなる.どうせ session は少ない(or 1つ)

よくわからない / できなそう

  • locked / normal の用語がよくわからないが,それで動いているのでそうしている
  • 数値で tab 移動するのは難しそう
    • tab がincr であって,位置を指定するのは難しい?
      • name を付ける方が自然なのかも
  • select-layout even-* ができないかもなので,先に分割(=layout) を決めるとか

WIP

まだ使い方が定まってないけど,
数値で絶対移動できないなら,名前を付けようという観点で,
znd でとりあえずなんとか.

.zshrc
# 抜粋

if whence -p zellij 2>&1 > /dev/null; then
  # zlj: attach to 'default' session if available, else create/resurrect it
  function zlj() {
    zellij attach -c "default"
  }
  
  # enable zsh completion
  # zellij setup --generate-completion zsh > ~/.zfunctions/Completion/_zellij

  # Helper to generate a unique tab name starting from #1
  function __zlj_unique_name() {
    local base_name=$1
    local existing_names=$(zellij action query-tab-names 2>/dev/null | sed '/^$/d')
    local n=1
    while echo "$existing_names" | grep -q "^${base_name} #${n}$"; do
      ((n++))
    done
    echo "${base_name} #${n}"
  }

  # znd: zellij new tab in directory with auto-naming
  # usage: znd [directory] [layout_name] [tab_name]
  ZND_SOURCES=("[[ -x \$(whence -p zoxide) ]] && zoxide query -l")
  function znd() {
    local dir=$1
    local layout=${2:-default}
    local name=$3
    if [[ -z "$dir" ]]; then
      # Gather directory candidates from ZND_SOURCES array (zoxide is included by default)
      dir=$( (
        for src in "${ZND_SOURCES[@]}"; do
          eval "$src" 2>/dev/null
        done
      ) | sed 's#/$##' | awk '!a[$0]++' | fzf --height 40% --reverse --no-sort --prompt "Select directory: " )
      [[ -z "$dir" ]] && return
    fi
    [[ ! -d "$dir" ]] && echo "Error: Directory '$dir' not found." && return 1
    local abs_dir=$(cd "$dir" && pwd)
    if [[ -z "$name" ]]; then
      name=$(basename "$abs_dir")
      name=$(__zlj_unique_name "$name")
    else
      local existing_names=$(zellij action query-tab-names 2>/dev/null | sed '/^$/d')
      if echo "$existing_names" | grep -q "^$name$"; then
        echo "Error: Tab name '$name' already exists."
        return 1
      fi
    fi
    zellij action new-tab --cwd "$abs_dir" --name "$name" --layout "$layout"
  }

  # Helper for layout completion
  function __zlj_layouts() {
    local -a layouts
    layouts=(${$(ls ~/.config/zellij/layouts/*.kdl 2>/dev/null):t:r})
    layouts+=("default" "compact")
    _describe 'layouts' layouts
  }
  
  # znd completion
  function _znd() {
    _arguments \
      '1:directory:_directories' \
      '2:layout:__zlj_layouts' \
      '3:tab_name: '
  }
  compdef _znd znd
fi
.config/zellij/config.kdl
// 抜粋

default_mode "locked"

keybinds clear-defaults=true {
    locked {
        bind "Ctrl z" { SwitchToMode "normal"; }
    }
    normal {
        bind "Ctrl z" { write 26; SwitchToMode "Locked"; }
        bind "w" {
            LaunchOrFocusPlugin "session-manager" {
                floating true
                move_to_focused_tab true
            }
            SwitchToMode "Locked"
        }
    }
}

Refs


.tmux.conf
# ウィンドウ番号基準値                                       
set-option -g base-index 1           
  • これは確かに.と思った
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?