From d2821fa462a12a2cbc4252584591559f3ad064e4 Mon Sep 17 00:00:00 2001 From: bchanot Date: Tue, 6 Oct 2026 13:09:34 +0200 Subject: [PATCH] feat(tmux): deploy the config on Linux too; prefix i / - splits - install.sh: deploy_tmux_config runs on both OSes after the bashrc (gated on tmux) - tmux.conf: clipboard via if-shell (pbcopy on macOS, tmux buffer + OSC 52 elsewhere) - bashrc-linux exports XDG_CACHE_HOME like the macOS rc files - prefix i = side-by-side split, prefix - = stacked split (h/j/k/l kept) - verified in an Ubuntu 24.04 container (tmux 3.4): deploy, bindings, split, plugins, libtmux --- .claude/tasks/TODO.md | 7 +++++++ CLAUDE.md | 2 +- README.md | 6 +++--- bash/bashrc-linux | 3 +++ install.sh | 21 +++++++++++++-------- tmux.conf | 16 ++++++++-------- 6 files changed, 35 insertions(+), 20 deletions(-) diff --git a/.claude/tasks/TODO.md b/.claude/tasks/TODO.md index 403c6a5..3981032 100644 --- a/.claude/tasks/TODO.md +++ b/.claude/tasks/TODO.md @@ -107,3 +107,10 @@ Branch: feature/tmux-config (off develop, "met ca dans develop" = finish into de - [x] README macOS step + CLAUDE.md layout - [x] shellcheck, bash -n, zsh -n; run deploy_tmux_config against a temp HOME; tmux parses the config - [x] cloudpex: `install_cloudpex` → `offer_cloudpex` ([y/N] via confirm, with the other Linux offers); README/CLAUDE.md wording + +## tmux follow-ups (2026-10-06, branch bugfix/tmux-macos-keys) +- [x] tmux.conf: pbcopy/pbpaste, `bind C-a send-prefix`, is_vim via pane_current_command +- [x] pane moves ctrl+u/h/j/k (arrow layout, AZERTY/QWERTY invariant), resize mirrors with prefix; C-l free +- [x] splits: prefix i (side by side) and prefix - (stacked), h/j/k/l kept +- [x] Linux: deploy_tmux_config on both OSes (gated on tmux), clipboard if-shell (pbcopy else tmux buffer + OSC 52), XDG_CACHE_HOME in bashrc-linux +- [x] Verified: shellcheck/bash -n, macOS test server, Ubuntu 24.04 container (tmux 3.4) full deploy + bindings + split + plugins + libtmux diff --git a/CLAUDE.md b/CLAUDE.md index c52fa1f..81e76d6 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -22,7 +22,7 @@ vim/autoload/ pathogen loader (committed) vim/colors/ molokai colorscheme (committed) bash/bashrc-{linux,osx} OS-detected bashrc (exports USER/EMAIL identity) gitconfig user-scope ~/.gitconfig template, @USER@/@EMAIL@ filled at install -tmux.conf tmux config (vi keys, tpm plugins) → ~/.config/tmux/tmux.conf, macOS only +tmux.conf tmux config (vi keys, tpm plugins) → ~/.config/tmux/tmux.conf, both OSes (tmux ≥ 3.1) zsh/{zshrc-osx,bchanot.zsh-theme} macOS zsh option: oh-my-zsh zshrc + theme porting the bash prompt bin/{dt,dtach-router,claude-provider} CLI scripts deployed to ~/.local/bin etc/profile.d/disk-usage-warning.sh login-time low-disk warning → /etc/profile.d (Linux only) diff --git a/README.md b/README.md index 99be53b..a56a102 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ curl -fsSL https://git.bchanot.fr/bchanot/config/raw/branch/master/remote-instal | Path | Purpose | | -------------------- | -------------------------------------------------------------- | | `install.sh` | Linux: installs apt packages + Docker + code-server + RDP (gnome-remote-desktop), backs up old config, deploys vim + bashrc (OS-detected), installs CLI scripts, pipx tools and a low-disk login warning; ends by offering three extras (`/tmp` on disk, SSH memory guard, the `cloudpex` NAS mount helper). macOS: same tooling through Homebrew (see [macOS](#macos)), deploys the tmux config, then prints what was not installed compared with Linux. | -| `tmux.conf` | tmux config (vi keys, mouse, status bar, tpm plugins: resurrect + continuum session restore, window-name). Deployed on macOS to `~/.config/tmux/tmux.conf`. | +| `tmux.conf` | tmux config (vi keys, mouse, status bar, tpm plugins: resurrect + continuum session restore, window-name). Deployed on both OSes to `~/.config/tmux/tmux.conf` (tmux ≥ 3.1). | | `cloudpex/` | On-demand SMB mount of a NAS share (`cloudpex` command + its installer, offered `[y/N]` at the end of a Linux install). Site values (host, share, SMB user, mount point, SMB version) are prompted at install and stored in `/etc/cloudpex.conf`, never in the script. French README inside. | | `etc/tmpfiles.d/tmp.conf` | Cleanup rules for a disk-backed `/tmp` (wiped at boot, 10-day purge). Deployed by the `/tmp` on disk offer. | | `etc/systemd/ssh.service.d/override.conf` | `ssh.service` drop-in: sshd exempt from the OOM killer + memory reclaim protection. Deployed by the SSH memory guard offer. | @@ -66,7 +66,7 @@ What it does: 3. Moves any existing `~/.vim`, `~/.vimrc`, `~/.bashrc`, `~/.Sublivim` to `~/Oldconfig`. 4. Clones the `syntastic` and `nerdtree` vim plugins into `~/.vim/bundle/`. 5. Copies the tracked vim files into `~/.vim` and symlinks `~/.vimrc`. -6. Picks the bashrc by OS: macOS → `bashrc-osx` (falls back to `bashrc-linux` if missing), everything else → `bashrc-linux`. Copies it to `~/.bashrc`. Then renders `gitconfig` into `~/.gitconfig` with that bashrc's `USER` / `EMAIL`. A different existing `~/.gitconfig` is saved as `~/.gitconfig.backup-`; an identical one is left alone. It is the global level only: a repo's own `.git/config` still overrides it. `core.excludesfile` points at `~/.gitignore`, ignored by git when the file does not exist. +6. Picks the bashrc by OS: macOS → `bashrc-osx` (falls back to `bashrc-linux` if missing), everything else → `bashrc-linux`. Copies it to `~/.bashrc`. Then renders `gitconfig` into `~/.gitconfig` with that bashrc's `USER` / `EMAIL`. A different existing `~/.gitconfig` is saved as `~/.gitconfig.backup-`; an identical one is left alone. It is the global level only: a repo's own `.git/config` still overrides it. `core.excludesfile` points at `~/.gitignore`, ignored by git when the file does not exist. Then deploys `tmux.conf` to `~/.config/tmux/tmux.conf` (both OSes, tmux ≥ 3.1: Ubuntu 22.04+, brew), clones [tpm](https://github.com/tmux-plugins/tpm) and fetches the listed plugins headlessly; details under [macOS](#macos) step 6, the step is the same. On Linux, `y` copies into tmux's buffer and the terminal clipboard through OSC 52; macOS uses `pbcopy`/`pbpaste`. 7. Installs Python CLIs via `pipx` (`PyMuPDF` → `pymupdf`, `Markdown` → `markdown_py`) — skipped if `pipx` is absent. 8. Copies the `bin/` scripts (`dt`, `dtach-router`, `claude-provider`) into `~/.local/bin`. The dtach session-resume menu ships in the deployed bashrc (both OSes), so every interactive shell offers it — including VS Code Remote-SSH terminals, which are non-login and never read `~/.profile`. The installer also strips any older dtach block left in `~/.profile` so a plain SSH login doesn't prompt twice. 9. On Linux, installs `etc/profile.d/disk-usage-warning.sh` to `/etc/profile.d/` (needs `sudo`) so each login warns when `/` or `/home` cross 85% usage. @@ -105,7 +105,7 @@ The same `./install.sh` detects macOS and replaces `apt-get` with Homebrew. It f 3. Docker: `colima` (the Linux VM) + `docker docker-compose docker-buildx`. Writes `~/.docker/config.json` with `cliPluginsExtraDirs` so `docker compose` works, only when that file does not exist yet (otherwise prints the line to add). 4. Starts `colima`, `code-server` and `mariadb` as `brew services` (the `systemctl enable --now` equivalent), skipping any already started. 5. Deploys `bashrc-osx`, then appends one line to `~/.bash_profile` that sources `~/.bashrc`: macOS terminals open login shells, which never read `~/.bashrc` on their own. Done for both choices, so `bash` stays usable. -6. Deploys `tmux.conf` to `~/.config/tmux/tmux.conf` (brew's tmux reads it there), clones [tpm](https://github.com/tmux-plugins/tpm) into `~/.config/tmux/plugins/tpm` and fetches the listed plugins headlessly (resurrect + continuum restore your sessions, window-name renames windows after what runs in them). A `~/.tmux.conf` would be read instead, so one found is moved to `~/.tmux.conf.backup-`; a differing `~/.config/tmux/tmux.conf` becomes `tmux.conf.backup-`. `libtmux` (needed by window-name) goes in the python user site; brew's python blocks that by default, so the install retries with `--break-system-packages`. Both plugin steps only warn on failure: `prefix` + `I` inside tmux fetches the plugins. Prefix is `C-a`. +6. Deploys `tmux.conf` to `~/.config/tmux/tmux.conf` (same step on Linux), clones [tpm](https://github.com/tmux-plugins/tpm) into `~/.config/tmux/plugins/tpm` and fetches the listed plugins headlessly (resurrect + continuum restore your sessions, window-name renames windows after what runs in them). A `~/.tmux.conf` would be read instead, so one found is moved to `~/.tmux.conf.backup-`; a differing `~/.config/tmux/tmux.conf` becomes `tmux.conf.backup-`. `libtmux` (needed by window-name) goes in the python user site; brew's python blocks that by default, so the install retries with `--break-system-packages`. Both plugin steps only warn on failure: `prefix` + `I` inside tmux fetches the plugins. Prefix is `C-a`. 7. **bash** chosen: makes brew's bash 5 the login shell (adds it to `/etc/shells` with `sudo`, then `chsh`, which asks for your password). macOS ships bash 3.2, too old for the bashrc. **zsh** chosen: installs oh-my-zsh with its official script (unattended, skipped if `~/.oh-my-zsh` exists), deploys `zsh/zshrc-osx` to `~/.zshrc` and the `bchanot` theme to `~/.oh-my-zsh/custom/themes/`, then makes `/bin/zsh` the login shell. An existing `~/.zshrc` that differs from the repo's is saved as `~/.zshrc.backup-` (outside `~/Oldconfig`, which every run wipes). Move your machine-specific lines (nvm, bun, tokens) into `~/.zshrc.local`: the deployed zshrc loads it. 8. Ends with the list of what the Linux install has and this one does not: `gcc` (Apple clang answers to `gcc`), `valgrind`, `dkms`, `net-tools`, `openssh-server` and the RDP desktop (both built into macOS, switched on in System Settings > Sharing), `cifs-utils`, `php-imagick`, the NVIDIA driver, the disk-usage warning, `cloudpex`, the security baseline and the two end-of-install offers. diff --git a/bash/bashrc-linux b/bash/bashrc-linux index 8e916f6..17c3da5 100644 --- a/bash/bashrc-linux +++ b/bash/bashrc-linux @@ -7,6 +7,9 @@ alias grep='grep --color=auto' # colored GCC warnings and errors export GCC_COLORS='error=01;31:warning=01;35:note=01;36:caret=01;32:locus=01:quote=01' +# XDG cache dir: tmux.conf saves resurrect/continuum sessions under it +export XDG_CACHE_HOME="${XDG_CACHE_HOME:-$HOME/.cache}" + # Ensure ~/.local/bin is on PATH (pipx CLIs + personal scripts from bin/) case ":$PATH:" in *":$HOME/.local/bin:"*) ;; diff --git a/install.sh b/install.sh index 3d293da..2ada84c 100755 --- a/install.sh +++ b/install.sh @@ -418,10 +418,11 @@ setup_macos_shell() { fi } -# tmux: tmux.conf goes to ~/.config/tmux/tmux.conf (tmux >= 3.1 reads it there) -# with tpm, which the config runs, in ~/.config/tmux/plugins/tpm. tmux reads a -# ~/.tmux.conf first, so one found is moved aside; a differing config is kept as -# tmux.conf.backup-, outside ~/Oldconfig which every run wipes. Idempotent. +# tmux, both OSes: tmux.conf goes to ~/.config/tmux/tmux.conf (read there since +# tmux 3.1: Ubuntu 22.04+, brew) with tpm, which the config runs, in +# ~/.config/tmux/plugins/tpm. tmux reads a ~/.tmux.conf first, so one found is +# moved aside; a differing config is kept as tmux.conf.backup-, outside +# ~/Oldconfig which every run wipes. Idempotent. deploy_tmux_config() { local dir="$HOME/.config/tmux" stamp stamp="$(date +%Y%m%d-%H%M%S)" @@ -456,9 +457,9 @@ install_tmux_plugins() { } # tmux-window-name (a listed plugin) is a python script importing libtmux. Brew's -# python refuses pip installs outside a venv (PEP 668), so the user-site install -# is retried with that guard lifted. Non-fatal: without it, windows keep tmux's -# own automatic-rename. +# python and Ubuntu 23.04+ refuse pip installs outside a venv (PEP 668), so the +# user-site install is retried with that guard lifted. Non-fatal: without it, +# windows keep tmux's own automatic-rename. install_libtmux() { python3 -c 'import libtmux' 2>/dev/null && return 0 echo "Installing libtmux (tmux-window-name plugin)" @@ -654,6 +655,11 @@ cp "$SCRIPT_DIR/$bashrc" "$HOME/.bashrc" # User-scope git config, identity taken from the bashrc just deployed. deploy_gitconfig "$SCRIPT_DIR/$bashrc" +# tmux config + plugins (tmux comes from the apt or brew list above). +if command -v tmux >/dev/null 2>&1; then + deploy_tmux_config +fi + # Python CLIs via pipx (run as the user, never sudo). Skipped if pipx is absent. if command -v pipx >/dev/null 2>&1; then echo "Installing pipx CLIs (PyMuPDF -> pymupdf, Markdown -> markdown_py)" @@ -685,7 +691,6 @@ fi # Linux install has that this one does not. if [ "$(uname -s)" = "Darwin" ]; then wire_bash_profile - deploy_tmux_config setup_macos_shell "${macos_shell:-bash}" print_macos_gaps fi diff --git a/tmux.conf b/tmux.conf index 59c16ff..5173bd1 100644 --- a/tmux.conf +++ b/tmux.conf @@ -139,14 +139,12 @@ bind -n C-k if-shell "$is_vim" "send-keys C-k" "select-pane -R" bind Escape copy-mode # bind vi-like 'normal' mode bind -Tcopy-mode-vi 'v' send -X begin-selection # bind vi-like visual mode -bind -Tcopy-mode-vi 'y' send -X copy-pipe-and-cancel "pbcopy" # macOS copy -bind p run "pbpaste | tmux load-buffer - ; tmux paste-buffer" # macOS paste -# bind vi-like copy/paste through 'normal' mode, (Note) {{{ -# Linux (X11) variant, xsel rather than xclip: xclip does not close STDOUT -# after reading tmux's buffer, so tmux waits for it and hangs. -# bind -Tcopy-mode-vi 'y' send -X copy-pipe-and-cancel "xsel -b -i" -# bind p run "xsel -b -o | tmux load-buffer - ; tmux paste-buffer" -# }}} +# Clipboard: pbcopy/pbpaste on macOS. Elsewhere tmux's own buffer, which tmux +# also hands to the terminal through OSC 52 (set-clipboard), so it reaches the +# local clipboard over ssh. xsel/xclip dropped: headless servers have no X. +if-shell 'command -v pbcopy >/dev/null' \ + 'bind -Tcopy-mode-vi y send -X copy-pipe-and-cancel pbcopy ; bind p run "pbpaste | tmux load-buffer - ; tmux paste-buffer"' \ + 'bind -Tcopy-mode-vi y send -X copy-selection-and-cancel ; bind p paste-buffer' bind-key -Tcopy-mode-vi Escape send -X cancel # cancel v mode bind-key -Tcopy-mode-vi ^v send -X rectangle-toggle # cancel v mode @@ -164,6 +162,8 @@ bind-key k "split-window -v -b -c '#{pane_current_path}'" bind-key h "split-window -h -b -c '#{pane_current_path}'" bind-key j "split-window -v -c '#{pane_current_path}'" bind-key l "split-window -h -c '#{pane_current_path}'" +bind-key i "split-window -h -c '#{pane_current_path}'" # i: side by side (vertical bar) +bind-key - "split-window -v -c '#{pane_current_path}'" # -: stacked (horizontal bar) bind q kill-window # Kill window bind Q kill-session # Kill the session (not server)