tmux/Pane/Q/What's the easiest way to bind a key that copies a pane's CWD to the clipboard or displays it?
Properties
- logseq-entity
- Logseq/Entity/Question
What's the easiest way to bind a key that copies a tmux/Pane's CWD to the clipboard, or displays it?
AI Answer
- Short answer: put a
bind-keyline in[[.tmux.conf.local]]that pipes#{pane_current_path}throughpbcopy; chain adisplay-messageonto it with\;for on-screen confirmation, or usedisplay-messagealone to just show it. Copy silently to the clipboard
bind-key y run-shell "printf '%s' '#{pane_current_path}' | pbcopy"run-shellexpands#{...}format variables itself before handing the string to/bin/sh, so there's no need to nest atmux display-message -pcall inside it.- Use
printf '%s', notecho -n— verified live: macOS's/bin/sh(bash in POSIX mode) doesn't treat-nas a flag there, soecho -n '...' | pbcopycopies the literal string-n /path/...instead of the path.
Copy and show a confirmation
bind-key y run-shell "printf '%s' '#{pane_current_path}' | pbcopy" \; display-message "copied #{pane_current_path}"\;chains a second tmux command onto the same binding — confirmed this registers as one atomic binding by loading it viatmux source-fileand checkinglist-keys. Typing an unescaped;straight at a shell prompt totmux bind-key ...does not chain the same way, since the shell strips the backslash first and tmux then treats it as two separate top-level commands; this only matters when testing from a shell prompt instead of a config file.
Just display it, no clipboard
- Add whichever binding to the managed tmux config and reload with
tmux source-file ~/.config/tmux/tmux.conf. (Correction: my oh-my-tmux /.tmux.conf.localadvice above no longer matches this machine — the dotfiles repo removed oh-my-tmux and manages~/.config/tmux/tmux.confdirectly via chezmoi now.) - Tracked as a feature request: codekiln/dotfiles#114 — pick the actual key and land it in the managed
tmux.conf. Sources
- Short answer: put a