Search code examples
bashcygwin

Using git-prompt.sh PROMPT_COMMAND to change Cygwin Title Bar


In order to better customise my Cygwin command prompt and terminal window I was following this git-prompt guide: https://web.archive.org/web/20160304014517/http://ithaca.arpinum.org/2013/01/02/git-prompt.html

Everything in the guide works except the last tip located under the 'One Last Thing' heading where it offers the following line to change both your PS1 and set your terminals title-bar:

PROMPT_COMMAND='__git_ps1 "\u \W" "\\\$ " " [%s $(get_sha)] "; set_titlebar "$USER@${HOSTNAME%%.*} $(get_dir)"'

However when I add this line to my .bashrc get the following error:

-bash: set_titlebar: command not found

I have searched everywhere for a solution to why this is happening but have hit a dead end. I'm using mintty 1.2-beta1 (x86_64-pc-cygwin), have my terminal set to xterm, and using the git-prompt.sh script.


Solution

  • set_titlebar is not a Bash builtin but a custom function by the author of the article.

    At the top of the linked guide the author refer to a previous post:

    Many people have written or adapted complex scripts to get information from git, munge that data and then put it into their shell’s prompt. (I’ve done it myself.) However, […]

    This links to the script where set_titlebar is defined:

    function set_titlebar {
        case $TERM in
            *xterm*|ansi|rxvt)
                printf "\033]0;%s\007" "$*"
                ;;
        esac
    }
    

    You will need to include that function, one similar or write your own.