1

New to bash scripting and looking to tidy my screen. I have a number of terminal windows running separate process but all with the same window title. Using the following i can change the title.. all well and good:

PS1='\[\e]0;TEST TITLE HERE: \w\a\]${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$'

If i place this inside a script, it has no effect:

#! /bin/bash
PS1='\[\e]0;TEST TITLE HERE: \w\a\]${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$'

What element of scripting have i failed to appreciate that prevents me from doing what I'm trying to do?

many thanks

Paul Eden
  • 169

1 Answers1

6

Now the OP has a lot of things going on in his PS1, below I have removed the major portion of it, to create as simple text as possible - with a solution to the actual problem.

Using a bash FUNCTION you can get the same effect
as from using a script (source script.sh).
$ man bash, then type in /^FUNCTIONS, for info on bash functions.

Example,
place this in .bash_aliases

function setps1 {
PS1="\[\e]0;$1 \a\]$ "
}

Then every bash has the setps1 function available... so
$ type -a setps1 will print

setps1 is a function
setps1 () 
{ 
    PS1="\[\e]0;$1 \a\]$ "
}

and
$ setps1 "Working in \\w"
... will indeed set the window title to "Working in <cwd>"
i.e. Working in Projects while you're cd'd into ...anything/Projects/,
following along as you move about
.

Hannu
  • 6,605
  • 1
  • 28
  • 45