- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- set Window title using a script (gnome-terminal/Re...
Operating System - Linux
1753427
Members
4779
Online
108793
Solutions
Forums
Categories
Company
Local Language
юдл
back
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
юдл
back
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Blogs
Information
Community
Resources
Community Language
Language
Forums
Blogs
Go to solution
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-07-2006 01:19 AM
тАО11-07-2006 01:19 AM
Hi folks,
I have been using a script for about 14 years on HP-UX to set window titles.
Now I switched to Linux. gnome-terminal sets TERM to xterm, so I'm trying to use my script to set the window (tab) title. But bash seems not to know the "print" command (see script below).
What do I use instead of the "print" command/builtin?
Helpful answers will be rewarded with points of course.
Thanks, Christian
#! /bin/sh
#
# Set the title bar and perhaps the icon for a window
# Usage: title Your Title Here
# title -i Icon Only
# title -w Window Only
function Main
{
# Decide on the type of terminal window they are using
# so we can emit the correct escape sequences.
case $TERM in
xterm*) window_type=x;;
hp*|26*|23*) window_type=hp;;
dtterm) window_type=dt;;
*) print -u2 "$0: What kind of TERM is $TERM\?"
return 1;;
esac
# Call the function to set both the title and icon or just the
# icon, depending on if they used the -i flag.
case "$1" in
-i) shift; set_icon $window_type "$@";;
-w) shift; set_title $window_type "$@";;
*) set_title $window_type "$@";
set_icon $window_type "$@";;
vi -c 1 /home/cdeutsch/bin/title------------------------
[cdeutsch@hesed tmp]$ wcl ~/bin/title
bash: wcl: command not found
[cdeutsch@hesed tmp]$ wc -l ~/bin/title
67 /home/cdeutsch/bin/title
[cdeutsch@hesed tmp]$ cat ~/bin/title
#! /bin/sh
#
# Set the title bar and perhaps the icon for a window
# Usage: title Your Title Here
# title -i Icon Only
# title -w Window Only
function Main
{
# Decide on the type of terminal window they are using
# so we can emit the correct escape sequences.
case $TERM in
xterm*) window_type=x;;
hp*|26*|23*) window_type=hp;;
dtterm) window_type=dt;;
*) print -u2 "$0: What kind of TERM is $TERM\?"
return 1;;
esac
# Call the function to set both the title and icon or just the
# icon, depending on if they used the -i flag.
case "$1" in
-i) shift; set_icon $window_type "$@";;
-w) shift; set_title $window_type "$@";;
*) set_title $window_type "$@";
set_icon $window_type "$@";;
esac
return 0
}
function set_title # set title bar only
{
case $1 in
x) shift; print '\033]0;'"${*}"'\c' # title bar only
# In xterm, '\033]0;'"${*}"'\033\c' sets icon AND title bar
;;
dt) shift; print '\033]0;'"${*}" # title bar only
;;
hp) shift; title="$@"
print '\033&f0k'${#title}D"$title"\\c
;;
esac
}
function set_icon # set icon label only
{
case $1 in
x) shift; print '\033]1;'"${*}"'\033\c'
;;
dt) shift; print '\033]1;'"${*}"
;;
hp) shift; title="${*}"
print '\033&f-1k'${#title}D"$title"\\c
;;
esac
}
# If there were no arguments, print a usage synopsis
if [ $# = 0 ]
then print -u2 "Usage: ${0##*/} Your Title Here"
print -u2 "or: ${0##*/} -i Icon Title Only"
print -u2 "or: ${0##*/} -w Window Title Only"
exit 1
else
Main "$@"
exit $?
fi
I have been using a script for about 14 years on HP-UX to set window titles.
Now I switched to Linux. gnome-terminal sets TERM to xterm, so I'm trying to use my script to set the window (tab) title. But bash seems not to know the "print" command (see script below).
What do I use instead of the "print" command/builtin?
Helpful answers will be rewarded with points of course.
Thanks, Christian
#! /bin/sh
#
# Set the title bar and perhaps the icon for a window
# Usage: title Your Title Here
# title -i Icon Only
# title -w Window Only
function Main
{
# Decide on the type of terminal window they are using
# so we can emit the correct escape sequences.
case $TERM in
xterm*) window_type=x;;
hp*|26*|23*) window_type=hp;;
dtterm) window_type=dt;;
*) print -u2 "$0: What kind of TERM is $TERM\?"
return 1;;
esac
# Call the function to set both the title and icon or just the
# icon, depending on if they used the -i flag.
case "$1" in
-i) shift; set_icon $window_type "$@";;
-w) shift; set_title $window_type "$@";;
*) set_title $window_type "$@";
set_icon $window_type "$@";;
vi -c 1 /home/cdeutsch/bin/title------------------------
[cdeutsch@hesed tmp]$ wcl ~/bin/title
bash: wcl: command not found
[cdeutsch@hesed tmp]$ wc -l ~/bin/title
67 /home/cdeutsch/bin/title
[cdeutsch@hesed tmp]$ cat ~/bin/title
#! /bin/sh
#
# Set the title bar and perhaps the icon for a window
# Usage: title Your Title Here
# title -i Icon Only
# title -w Window Only
function Main
{
# Decide on the type of terminal window they are using
# so we can emit the correct escape sequences.
case $TERM in
xterm*) window_type=x;;
hp*|26*|23*) window_type=hp;;
dtterm) window_type=dt;;
*) print -u2 "$0: What kind of TERM is $TERM\?"
return 1;;
esac
# Call the function to set both the title and icon or just the
# icon, depending on if they used the -i flag.
case "$1" in
-i) shift; set_icon $window_type "$@";;
-w) shift; set_title $window_type "$@";;
*) set_title $window_type "$@";
set_icon $window_type "$@";;
esac
return 0
}
function set_title # set title bar only
{
case $1 in
x) shift; print '\033]0;'"${*}"'\c' # title bar only
# In xterm, '\033]0;'"${*}"'\033\c' sets icon AND title bar
;;
dt) shift; print '\033]0;'"${*}" # title bar only
;;
hp) shift; title="$@"
print '\033&f0k'${#title}D"$title"\\c
;;
esac
}
function set_icon # set icon label only
{
case $1 in
x) shift; print '\033]1;'"${*}"'\033\c'
;;
dt) shift; print '\033]1;'"${*}"
;;
hp) shift; title="${*}"
print '\033&f-1k'${#title}D"$title"\\c
;;
esac
}
# If there were no arguments, print a usage synopsis
if [ $# = 0 ]
then print -u2 "Usage: ${0##*/} Your Title Here"
print -u2 "or: ${0##*/} -i Icon Title Only"
print -u2 "or: ${0##*/} -w Window Title Only"
exit 1
else
Main "$@"
exit $?
fi
Yeshua loves you!
Solved! Go to Solution.
2 REPLIES 2
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-10-2006 03:35 AM
тАО11-10-2006 03:35 AM
Solution
Use echo -e instead of print to work with bash.
The bash echo command can use either "\c" or -n to suppress a newline.
You need to use >&2 instead of -u2 to send echo to stderr.
Your xterm escape sequence should end the title string with "\007".
You can set just the window title in gnome-terminal with "\033]2;$*\007"
$ diff -u title.orig title
--- title.orig 2006-11-09 14:24:56.000000000 -0700
+++ title 2006-11-10 09:17:30.000000000 -0700
@@ -13,7 +13,7 @@
xterm*) window_type=x;;
hp*|26*|23*) window_type=hp;;
dtterm) window_type=dt;;
-*) print -u2 "$0: What kind of TERM is $TERM\?"
+*) echo "$0: What kind of TERM is $TERM\?" >&2
return 1;;
esac
@@ -31,13 +31,13 @@
function set_title # set title bar only
{
case $1 in
-x) shift; print '\033]0;'"${*}"'\c' # title bar only
+x) shift; echo -e '\033]2;'"${*}"'\007\c' # title bar only
# In xterm, '\033]0;'"${*}"'\033\c' sets icon AND title bar
;;
-dt) shift; print '\033]0;'"${*}" # title bar only
+dt) shift; echo -e '\033]0;'"${*}" # title bar only
;;
hp) shift; title="$@"
-print '\033&f0k'${#title}D"$title"\\c
+echo -e '\033&f0k'${#title}D"$title"\\c
;;
esac
}
@@ -45,21 +45,21 @@
function set_icon # set icon label only
{
case $1 in
-x) shift; print '\033]1;'"${*}"'\033\c'
+x) shift; echo -e '\033]1;'"${*}"'\007\c'
;;
-dt) shift; print '\033]1;'"${*}"
+dt) shift; echo -e '\033]1;'"${*}"
;;
hp) shift; title="${*}"
-print '\033&f-1k'${#title}D"$title"\\c
+echo -e '\033&f-1k'${#title}D"$title"\\c
;;
esac
}
# If there were no arguments, print a usage synopsis
if [ $# = 0 ]
-then print -u2 "Usage: ${0##*/} Your Title Here"
-print -u2 "or: ${0##*/} -i Icon Title Only"
-print -u2 "or: ${0##*/} -w Window Title Only"
+then echo "Usage: ${0##*/} Your Title Here" >&2
+echo "or: ${0##*/} -i Icon Title Only" >&2
+echo "or: ${0##*/} -w Window Title Only" >&2
exit 1
else
Main "$@"
The bash echo command can use either "\c" or -n to suppress a newline.
You need to use >&2 instead of -u2 to send echo to stderr.
Your xterm escape sequence should end the title string with "\007".
You can set just the window title in gnome-terminal with "\033]2;$*\007"
$ diff -u title.orig title
--- title.orig 2006-11-09 14:24:56.000000000 -0700
+++ title 2006-11-10 09:17:30.000000000 -0700
@@ -13,7 +13,7 @@
xterm*) window_type=x;;
hp*|26*|23*) window_type=hp;;
dtterm) window_type=dt;;
-*) print -u2 "$0: What kind of TERM is $TERM\?"
+*) echo "$0: What kind of TERM is $TERM\?" >&2
return 1;;
esac
@@ -31,13 +31,13 @@
function set_title # set title bar only
{
case $1 in
-x) shift; print '\033]0;'"${*}"'\c' # title bar only
+x) shift; echo -e '\033]2;'"${*}"'\007\c' # title bar only
# In xterm, '\033]0;'"${*}"'\033\c' sets icon AND title bar
;;
-dt) shift; print '\033]0;'"${*}" # title bar only
+dt) shift; echo -e '\033]0;'"${*}" # title bar only
;;
hp) shift; title="$@"
-print '\033&f0k'${#title}D"$title"\\c
+echo -e '\033&f0k'${#title}D"$title"\\c
;;
esac
}
@@ -45,21 +45,21 @@
function set_icon # set icon label only
{
case $1 in
-x) shift; print '\033]1;'"${*}"'\033\c'
+x) shift; echo -e '\033]1;'"${*}"'\007\c'
;;
-dt) shift; print '\033]1;'"${*}"
+dt) shift; echo -e '\033]1;'"${*}"
;;
hp) shift; title="${*}"
-print '\033&f-1k'${#title}D"$title"\\c
+echo -e '\033&f-1k'${#title}D"$title"\\c
;;
esac
}
# If there were no arguments, print a usage synopsis
if [ $# = 0 ]
-then print -u2 "Usage: ${0##*/} Your Title Here"
-print -u2 "or: ${0##*/} -i Icon Title Only"
-print -u2 "or: ${0##*/} -w Window Title Only"
+then echo "Usage: ${0##*/} Your Title Here" >&2
+echo "or: ${0##*/} -i Icon Title Only" >&2
+echo "or: ${0##*/} -w Window Title Only" >&2
exit 1
else
Main "$@"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-13-2006 12:36 AM
тАО11-13-2006 12:36 AM
Re: set Window title using a script (gnome-terminal/RedHat AS4)
Perfect! Thank you Mike!
Yeshua loves you!
The opinions expressed above are the personal opinions of the authors, not of Hewlett Packard Enterprise. By using this site, you accept the Terms of Use and Rules of Participation.
News and Events
Support
© Copyright 2024 Hewlett Packard Enterprise Development LP