├── LICENSE
├── README.md
├── zsh-tmux-auto-title.gif
└── zsh-tmux-auto-title.plugin.zsh
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2020 Michael Benford
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # zsh-tmux-auto-title
2 |
3 | ZSH plugin for tmux that automatically sets the title of windows/panes as the current foreground command.
4 |
5 | 
6 |
7 | ## Installation
8 |
9 | ### Manual
10 |
11 | ```
12 | git clone --depth=1 https://github.com/mbenford/zsh-tmux-auto-title ~/zsh-tmux-auto-title
13 | echo "source ~/zsh-tmux-auto-title/zsh-tmux-auto-title.plugin.zsh" >>! ~/.zshrc
14 | ```
15 |
16 | ### Oh My Zsh:
17 |
18 | ```
19 | git clone --depth=1 https://github.com/mbenford/zsh-tmux-auto-title "${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/plugins/zsh-tmux-auto-title"
20 |
21 | ```
22 |
23 | Add `zsh-tmux-auto-title` to `plugins` in `.zshrc`.
24 |
25 | ## Usage
26 |
27 | This plugin automatically issues escape sequences to set the title of the window/pane as the current running command. By default the whole command line is used, but you can make it shorter if you want. You can also set what the title looks like when no command is running. See [configuration](#configuration) for more details.
28 |
29 | ### Panes
30 |
31 | By default tmux displays pane titles on the left side of the status line. If you are employing a custom status line, make sure `#T` (or `pane_title`) is used somewhere. You can also use `pane-border-status` and `pane-border-style` to display the titles of all panes at once. See [tmux manual](https://www.man7.org/linux/man-pages/man1/tmux.1.html) for more information.
32 |
33 | ### Windows
34 |
35 | Tmux won't allow programs to rename windows unless `allow-rename` is `on`. So make sure to add `set -g allow-rename on` to your `.tmux.conf` file if you want to rename windows.
36 |
37 | If you are using Oh My Zsh you should also set `DISABLE_AUTO_TITLE=true` in your `.zshrc` file so it won't conflict with this plugin.
38 |
39 | ## Configuration
40 |
41 |
42 | | Variable | Description |
43 | |-|-|
44 | | `ZSH_TMUX_AUTO_TITLE_TARGET` | Sets whether the `window` title or the `pane` title should be changed. Defaults to `pane`. |
45 | | `ZSH_TMUX_AUTO_TITLE_SHORT` | Displays only the command name, instead of the full command line. Defaults to `false`. |
46 | | `ZSH_TMUX_AUTO_TITLE_SHORT_EXCLUDE` | Regular expression that defines what commands should never be shortened. Defaults to `""`. |
47 | | `ZSH_TMUX_AUTO_TITLE_EXPAND_ALIASES` | Determines whether aliases should be expanded or kept as is. Defaults to `true`. |
48 | | `ZSH_TMUX_AUTO_TITLE_IDLE_TEXT` | Text to be used when no command is running. It can be either a plain string or one of the following variables:
`%pwd`: current directory;
`%shell`: current shell;
`%last`: last command, prefixed by an exclamation mark.
Defaults to `%shell`. |
49 | | `ZSH_TMUX_AUTO_TITLE_IDLE_DELAY` | Delay, in seconds, before the idle text is displayed. Defaults to `1`. |
50 | | `ZSH_TMUX_AUTO_TITLE_PREFIX` | A prefix added to the title, Defaults to `""`. |
51 |
52 |
--------------------------------------------------------------------------------
/zsh-tmux-auto-title.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mbenford/zsh-tmux-auto-title/8b09715ed1cc25079355978a081a34365ef0bcec/zsh-tmux-auto-title.gif
--------------------------------------------------------------------------------
/zsh-tmux-auto-title.plugin.zsh:
--------------------------------------------------------------------------------
1 | # zsh-tmux-auto-title plugin
2 | # version: 1.0.0
3 | # https://github.com/mbenford/zsh-tmux-auto-title
4 |
5 | ! (( $+commands[tmux] )) && { >&2 echo "zsh-tmux-auto-title: tmux not found. Please install tmux before using this plugin."; return 1 }
6 |
7 | : ${ZSH_TMUX_AUTO_TITLE_TARGET:=pane}
8 | : ${ZSH_TMUX_AUTO_TITLE_SHORT:=false}
9 | : ${ZSH_TMUX_AUTO_TITLE_SHORT_EXCLUDE:=}
10 | : ${ZSH_TMUX_AUTO_TITLE_EXPAND_ALIASES:=true}
11 | : ${ZSH_TMUX_AUTO_TITLE_IDLE_TEXT:=%shell}
12 | : ${ZSH_TMUX_AUTO_TITLE_IDLE_DELAY:=1}
13 | : ${ZSH_TMUX_AUTO_TITLE_PREFIX:=}
14 |
15 | typeset -g ZSH_TMUX_AUTO_TITLE_LAST
16 |
17 | _zsh_tmux_auto_title_set_title() {
18 | case $ZSH_TMUX_AUTO_TITLE_TARGET in
19 | window) printf "\ek$1\e\\" ;;
20 | pane) printf "\e]2;$1\e\\" ;;
21 | esac
22 | }
23 |
24 | _zsh_tmux_auto_title_preexec() {
25 | setopt extended_glob
26 |
27 | local cmd=${1[(wr)^(*=*|sudo|ssh|mosh|-*)]:gs/%/%%}
28 | local line="${2:gs/%/%%}"
29 |
30 | [[ -z "$cmd" ]] && return
31 |
32 | if [[ "$ZSH_TMUX_AUTO_TITLE_EXPAND_ALIASES" = "true" ]]; then
33 | local cmd_type=$(whence -w $cmd | awk '{print $2}')
34 | [[ "$cmd_type" = "alias" ]] && cmd=$(whence $cmd)
35 | fi
36 |
37 | local title=$ZSH_TMUX_AUTO_TITLE_PREFIX$line
38 | [[ "$ZSH_TMUX_AUTO_TITLE_SHORT" = "true" ]] &&
39 | ! [[ "$cmd" =~ "$ZSH_TMUX_AUTO_TITLE_SHORT_EXCLUDE" ]] && title=$cmd
40 |
41 | ZSH_TMUX_AUTO_TITLE_LAST=$title
42 | _zsh_tmux_auto_title_set_title $title
43 | }
44 |
45 | _zsh_tmux_auto_title_precmd() {
46 | local title=$ZSH_TMUX_AUTO_TITLE_IDLE_TEXT
47 |
48 | case $title in
49 | %pwd) title=$(print -P %~) ;;
50 | %shell) title=$(echo -n ${0:s/-//}) ;;
51 | %last) title="!$ZSH_TMUX_AUTO_TITLE_LAST" ;;
52 | esac
53 | title=$ZSH_TMUX_AUTO_TITLE_PREFIX$title
54 | if [[ "$ZSH_TMUX_AUTO_TITLE_IDLE_DELAY" = "0" ]]; then
55 | _zsh_tmux_auto_title_set_title $title
56 | else
57 | sched +$ZSH_TMUX_AUTO_TITLE_IDLE_DELAY _zsh_tmux_auto_title_set_title "$title"
58 | fi
59 | }
60 |
61 | autoload -U add-zsh-hook
62 | add-zsh-hook preexec _zsh_tmux_auto_title_preexec
63 | add-zsh-hook precmd _zsh_tmux_auto_title_precmd
64 |
--------------------------------------------------------------------------------