본문 바로가기

Macintosh

터미널 탭의 제목을 "command (pid)" 로 변경하기.

만드느라 힘들었다.




~/.bash_profile

#terminal tab title setting

case "$TERM" in

xterm*|rxvt*)

    # This tells bash: before showing the prompt, run this

    PROMPT_COMMAND='echo -ne "\033]0;bash ($$)\007"'

    # Edit the title if a command is running:

    # http://www.davidpashley.com/articles/xterm-titles-with-bash.html

    show_command_in_title_bar()

    {

        case "$BASH_COMMAND" in

            *\033]0*)

                # The command is trying to set the title bar as well;

                # this is most likely the execution of $PROMPT_COMMAND.

                # In any case nested escapes confuse the terminal, so don't

                # output them.

                ;;

    fg*)

app=`jobs %+ | awk '{print $3$4}'`

case "$app" in

    sudo*)

app=${app:4}

    ;;

    *)

app=`jobs %+ | awk '{print $3}'`

    ;;

esac

app=`basename $app`

p=`jobs -p %+`

settitle "▶ $app ($p)"

;;

    sudo*)

app=`basename ${BASH_COMMAND:4}`

settitle

let p=`jobs -p`+3

settitle "▶ $app ($p)"

;;

            *)

app=`basename $BASH_COMMAND`

settitle

let p=`jobs -p`+3

settitle "▶ $app ($p)"

                ;;

        esac

    }

    # The DEBUG signal simply announces the last-run command

    trap show_command_in_title_bar DEBUG

    ;;

*)

    ;;

esac


/usr/bin/settitle

#!/usr/bin/env bash

printf "\e]1;$1\a"