Change Terminal Title


 
Thread Tools Search this Thread
Operating Systems Solaris Change Terminal Title
# 8  
Old 11-20-2005
Dude, it's UNIX... you can do whatever you want. Here's some functions that should work in ksh or bash. Notice that if you put this in your .bashrc or .kshrc file using vi, you would create the "^[" by pressing control-V and then the Escape key. ^G is created by control-V and then control-G. All other characters are verbatim, and are the property of their owners.

wt changes the window title on the fly. Use it like: wt anything you want
it changes the window title and the icon title. Usage: it anything you want
defwt is my default window title, it shows you how to put a shell function in the window title.
cls is clear screen. Xterms are like vt100's, so it will work.

These functions work for many other vt100 emulators, I have found.

This is for Sun's echo command, which takes a \c to tell you not to send a carriage return at the end. For Linux you have to use its version. I think echo is deprecated and you want to use printf, but I'm not in front of Linux right now to check if it has printf also.

Code:
# X title stuff
        wt ()
        {
                echo "^[]2;${@}^G\c"
        }
        it ()
        {
                echo "^[]0;${@}^G\c"
        }
        defwt ()
        {
                echo "^[]2;$(whoami) @ $(hostname)^G"
        }
        cls ()
        {
          # works only for vt100's and the like
               echo "^[[;H^[[2J"
        }

In Real Life, I have yet another function that dynamically modifies my window title to show me my current directory, but that will cost you extra.

Oh, ok... this works on bash but my older version worked on ksh. You would have to figure out how to get it to work with ksh. Better to switch to bash, IMHO. Smilie

Code:
PROMPT_COMMAND=pc
titlebar="$myhostname ::: $myname   "
tprompt="[$myname@$myhostname]"
        if [ "$TERM" != "void" -a "$TERM" != "dumb" ] ; then
                bold=`tput bold`
                normal=`tput rmso`
                PROMPT_COMMAND=pc
                #PS1="\!\\[$bold\\]\`promptlen\`\\[$normal\\]\\$ "
        fi
function pc
        {
                pc_wd=`pwd`
                if [ \( "$TERM" = "vt100" \) -o \( "$TERM" = "xterm" \) ] ; then
                        wt "$titlebar << `pwd` >>" > `tty`
                fi
                # go to a 2-line prompt if >38 chars in path...
                case "$pc_wd" in
                /)
                        pc_path="/" ; pc_suffix="\\$ "
                ;;
                $HOME)
                        pc_path="~" ; pc_suffix="\\$ "
                ;;
                ??????????????????????????????????????*)
                        pc_path=$pc_wd ; pc_suffix="\n\\$ "
                ;;
                *)
                        pc_path=$pc_wd ; pc_suffix="\\$ "
                ;;
                esac
                PS1="\!\\[$bold\\]${tprompt}${pc_path}\\[$normal\\]${pc_suffix}"
                return
        }

...bold and normal do not work under Linux here. This is from my Sun, sorry. I have a version that works on Linux and Solaris but it's at work and I'm not.
-Mike

Last edited by mschwage; 11-20-2005 at 02:54 AM.. Reason: Drat, forgot arguments
# 9  
Old 11-21-2005
Thanks for those additional options mschwage. Might have to incorporate some of those ideas.

For now, I'm using the ksh shell and was actually able to configure a PS1 command to get colors in my prompt and dynamically set the title bar based on working directory location.

Thanks again for all the help.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Post Here to Contact Site Administrators and Moderators

Change title of a thread after it is created

hi, how do we change the title of a thread after it is created? Thanks (5 Replies)
Discussion started by: milhan
5 Replies

2. UNIX for Dummies Questions & Answers

Change putty title name

Hello all, I have a not so unix question for you guys(or maybe it is). I use PUTTY to login to serverA (my putty title shows as serverA.domainname.com) Now from ServerA i do ssh user@ServerB (i have ssh public private key setup)... now my question is when i do ssh and logon to... (20 Replies)
Discussion started by: abdul.irfan2
20 Replies

3. UNIX for Dummies Questions & Answers

Setting the current directory path to terminal title

In ubuntu, I want to update the title of the terminal window with the current directory path. Any ideas how this can be achieved? ---------- Post updated at 02:22 PM ---------- Previous update was at 02:08 PM ---------- Done it ---------- Post updated at 02:30 PM ---------- Previous update... (2 Replies)
Discussion started by: kristinu
2 Replies

4. Shell Programming and Scripting

How to change the title bar of the terminal screen

Hi, How to change the value after the symbol '@' ? $ i.e. @mac1 I want to change it to @prod2 Also need to change the same in the title bar on the top when we open a new terminal. (3 Replies)
Discussion started by: milink
3 Replies

5. Shell Programming and Scripting

Directory name in terminal title

I would like to have the directory I am currently in being shown in the title when I open a terminal window in Fedora (selecting "Open in terminal" or using the Terminal from the panel). Any way that I can do this? Basically whenever I do "cd", the title should update I have created this... (1 Reply)
Discussion started by: kristinu
1 Replies

6. AIX

How to change cronjob title?

Once I type "mail" command, I got to see the mail like below: > 1 daemon Thu Aug 12 17:31 31/938 "Output from cron job " My question is, how to do change the default title "Output from cron job " to be more customized title? Thanks. (4 Replies)
Discussion started by: ngaisteve1
4 Replies

7. UNIX Desktop Questions & Answers

Terminal title bar tweak discrepancy problem in Cygwin/X

Code for the tweak (not my fave 'running process' but the more popular 'working directory') : case "$TERM" in xterm*|rxvt*|rxvt-unicode*) PROMPT_COMMAND='echo -e "\033]0;$TERM: ${PWD}\007"' ;; *) ;; esac Where it works: rxvt (the one I run 'rootless' outside of ... (0 Replies)
Discussion started by: SilversleevesX
0 Replies

8. UNIX for Advanced & Expert Users

Change title of aixterm window online

Is there any way to change title of aixterm window online? Also is it possible to freeze first/last few lines online? (1 Reply)
Discussion started by: Soham
1 Replies

9. UNIX for Advanced & Expert Users

Change putty title window?

Is it possible to change the putty window title from a Unix command line? (12 Replies)
Discussion started by: akbar
12 Replies

10. UNIX for Dummies Questions & Answers

Change Console Title

Hello. I am trying to figure out how to change the title of my console window. I don't need it to dynamically change with my current directory. I just want to be able to change the name of it, so when I minimize the window I can see which windows are for what purpose. I've tried using the... (8 Replies)
Discussion started by: medmonson
8 Replies
Login or Register to Ask a Question