program tip

Tmux의 창 제목

radiobox 2020. 10. 23. 07:44
반응형

Tmux의 창 제목


내 로컬 컴퓨터에는 3 개의 node.js 인스턴스가 동시에 실행됩니다. 각각은 "서버"라는 tmux 창에 자체 창을 가지고 있습니다. 문제는 어떤 노드가 어떤 창에서 실행되고 있는지 파악하기가 쉽지 않다는 것입니다. 로그가 비슷하기 때문입니다.

내가 필요한 것은 모든 창에 대한 제목입니다. 내가 얻은대로, tmux 자체에는 기능이 없습니다. 창에 대한 제목이 아니라 창에 대한 제목 만 있습니다. 모든 node.js 인스턴스의 모든 창에서 별도의 tmux 세션을 시작하는 것은 과잉처럼 보입니다.

그렇다면 명령을 실행하고 출력을 지정된 상태 표시 줄로 래핑하는 작은 프로그램이 있습니까?

미리 감사드립니다


tmux창별 제목을 지원하지만 이러한 제목을 표시 할 창별 위치를 제공하지 않습니다.

ESC ]2;… ESC 이스케이프 시퀀스를 사용하여 분할 창의 제목을 설정할 수 있습니다 \(예 : tmux 맨 페이지 이름 및 제목 섹션 참조 ). 다음과 같이 쉘에서이를 수행 할 수 있습니다.

printf '\033]2;%s\033\\' 'title goes here'

각 창의 제목은 기본적으로 시스템의 호스트 이름입니다. 기본적으로 활성 창 제목이 오른쪽에 표시됩니다 TMUX의 상태 표시 줄 (세션 변수의 기본 전역 값 status-right이다 "#22T" %H:%M %d-%b-%y,하는 쇼 창의 제목, 시간 및 날짜의 22 자).

따라서 활성 창의 제목을 볼 수있는 경우 (즉, 비활성 창의 제목을보기 위해 창을 전환하려는 경우) 기본 기능을 사용할 수 있습니다. 각 창에 대한 기본 명령을 시작하기 전에 적절한 제목 설정 이스케이프 시퀀스를 보내십시오.


일부 창별 정보를 표시하기 위해 전용 회선이 반드시 필요한 경우 중첩 된 tmux 세션은 처음 생각하는 것만 큼 많은 (불필요한) "과잉"이 아닐 수 있습니다.

일반적으로 특정 터미널에 위반 상태 라인을 제공하려면 원래 터미널과 새 터미널 (하나 더 적은 라인이있는 터미널) 사이에있는 완전한 터미널 (재) 에뮬레이터가 필요합니다. 이러한 (재) 에뮬레이션은 내부 터미널로 전송 된 제어 시퀀스를 변환하고 원래 터미널로 변환하는 데 필요합니다. 예를 들어 외부 터미널 맨 아래에 상태 표시 줄을 유지하려면 다음 명령을 사용하십시오.

마지막 줄로 이동합니다.

내부 터미널로 보내야합니다.

다음 줄로 이동합니다.

번역되어 외부 터미널로 전송 될 때. 마찬가지로 내부 터미널로 전송되는 LF는

커서가 마지막 줄 옆에있는 경우이 줄과 그 위에있는 모든 줄을 한 줄 위로 스크롤하여 마지막 줄에서 명확한 줄을 제공합니다 (마지막 줄의 상태 줄 보호). 그렇지 않으면 LF를 보냅니다.

외부 터미널에서.

tmuxscreen 과 같은 프로그램 은 이러한 터미널 재 에뮬레이터입니다. 물론 터미널 에뮬레이터를 둘러싼 많은 다른 기능이 있지만 안정적인 상태 표시 줄 을 제공하려면 터미널 에뮬레이션 코드의 큰 덩어리가 필요합니다 .


그러나 한 가벼운 솔루션이 있습니다.

  1. 프로그램 ( Node.js 인스턴스)이 실행중인 창과 제한된 터미널 상호 작용 (예 : 커서 위치 없음)이 있고
  2. 프로그램이 실행되는 동안 창 크기를 조정하지 않습니다.

많은 터미널 에뮬레이터와 마찬가지로 tmux 는 창에서 "스크롤 영역 설정"터미널 제어 명령을 지원합니다. 이 명령을 사용하여 스크롤 영역을 터미널의 위쪽 (또는 아래쪽) N-1 줄로 제한하고 일종의 인스턴스 식별 텍스트를 스크롤하지 않는 줄에 쓸 수 있습니다.

출력을 생성하는 프로그램 (예 : Node.js 인스턴스)이 스크롤링이 특정 영역으로 제한되었음을 알지 못 하기 때문에 제한 (커서 이동 명령 허용, 크기 조정 없음)이 필요합니다 . 출력 생성 프로그램이 커서를 스크롤 영역 밖으로 이동하면 출력이 깨질 수 있습니다. 마찬가지로, 터미널 에뮬레이터는 터미널의 크기가 조정될 때 스크롤 영역을 자동으로 재설정 할 것입니다 (따라서 "비 스크롤 라인"은 아마도 스크롤링을 끝낼 것입니다).

tput적절한 제어 시퀀스를 생성하고 스크롤하지 않는 줄에 쓰고 커서를 스크롤 영역으로 이동 한 후 프로그램을 실행하는 데 사용하는 스크립트를 작성했습니다 .

#!/bin/sh

# usage: no_scroll_line top|bottom 'non-scrolling line content' command to run with args
#
#     Set up a non-scrolling line at the top (or the bottom) of the
#     terminal, write the given text into it, then (in the scrolling
#     region) run the given command with its arguments. When the
#     command has finished, pause with a prompt and reset the
#     scrolling region.

get_size() {
    set -- $(stty size)
    LINES=$1
    COLUMNS=$2
}
set_nonscrolling_line() {
    get_size
    case "$1" in
        t|to|top)
            non_scroll_line=0
            first_scrolling_line=1
            scroll_region="1 $(($LINES - 1))"
            ;;
        b|bo|bot|bott|botto|bottom)
            first_scrolling_line=0
            scroll_region="0 $(($LINES - 2))"
            non_scroll_line="$(($LINES - 1))"
            ;;
        *)
            echo 'error: first argument must be "top" or "bottom"'
            exit 1
            ;;
    esac
    clear
    tput csr $scroll_region
    tput cup "$non_scroll_line" 0
    printf %s "$2"
    tput cup "$first_scrolling_line" 0
}
reset_scrolling() {
    get_size
    clear
    tput csr 0 $(($LINES - 1))
}

# Set up the scrolling region and write into the non-scrolling line
set_nonscrolling_line "$1" "$2"
shift 2

# Run something that writes into the scolling region
"$@"
ec=$?

# Reset the scrolling region
printf %s 'Press ENTER to reset scrolling (will clear screen)'
read a_line
reset_scrolling

exit "$ec"

다음과 같이 사용할 수 있습니다.

tmux split-window '/path/to/no_scroll_line bottom "Node instance foo" node foo.js'
tmux split-window '/path/to/no_scroll_line bottom "Node instance bar" node bar.js'
tmux split-window '/path/to/no_scroll_line bottom "Node instance quux" node quux.js'

The script should also work outside of tmux as long as the terminal supports and publishes its csr and cup terminfo capabilities.


This functionality has been added to tmux git in this commit. It is not in version 2.2, but it looks like it will be in 2.3.

To enable it:

tmux set -g pane-border-status top

or if you prefer:

tmux set -g pane-border-status bottom

To set a custom text as your pane border status line you can make use of pane-border-format, e.g. like so:

tmux set -g pane-border-format "#{pane_index} #{pane_current_command}"

I'm working on the pane status bar for tmux - ticket. My development branch can be found here on github: https://github.com/jonathanslenders/tmux

Right now, this already adds a working rename-pane "title" command. There are still some bugs, and the API will improve. The idea is to create a status bar per pane, which can have some formatting, like the session status bar. Like the rest of tmux, everything should become scriptable, and customizable. When finished and stable, it will probably be included in the official tmux.


I am using tmux version 2.3, I think border style is not supported in previous versions. this is what worked for me:

For each pane set the title:

printf '\033]2;My Pane Title\033\\'

Then:

tmux set -g pane-border-format "#{pane_index} #T"

Since tmux 2.6 you can do:

$ tmux select-pane -t {pane} -T {title}

# Examples:
$ tmux select-pane -T title1          # Change title of current pane
$ tmux select-pane -t 1 -T title2     # Change title of pane 1 in current window
$ tmux select-pane -t 2.1 -T title3   # Change title of pane 1 in window 2

You can see title per pane in a status bar with:

$ tmux set pane-border-status bottom      # For current window
$ tmux set -g pane-border-status bottom   # For all windows

Disable status bar with:

$ tmux set pane-border-status off       # For current window
$ tmux set -g pane-border-status off    # For all windows

A gif is worth a thousand words. (source)

tmux-xpanes is a tmux-based terminal divider, which supports displaying title for each pane through the newly added -t option.


Yes there is such a command: tmux. Give your session a name and it will be displayed in an inner status bar:

TMUX=0 tmux new-session -s my-new-session

This is not helpful in the short-term, but there is a feature request for per-pane titles in tmux: http://sourceforge.net/tracker/?func=detail&aid=3495916&group_id=200378&atid=973265#

In the meantime, as others mentioned, nesting tmux works decently.

참고URL : https://stackoverflow.com/questions/9747952/pane-title-in-tmux

반응형