Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Populate titlebar in any term (See related posts)

Populate your titlebar in any term with some useful info such as uname -a, architecture, if you're ROOT or not, etc. In Linux:
#!/bin/bash
HOST_NAME=`hostname -f`
if [ `id -u` = 0 ]; then
OPT=”`uname` (`uname -a | cut -f12 -d’-`) - ROOT USER”
else
OPT=”`uname` (`uname -a | cut -f12 -d’-`)”
fi
REPLACE=”${HOST_NAME} - ${OPT}”
echo -n -e “\033]0; $REPLACE \007echo${REPLACE}”
exit 0

Then run this script, and your termtitle will be something like the following:
Servername (Linux / x86_64).

For Solaris it needs to be done a bit differently:
#!/usr/local/bin/bash
HOST_NAME=`uname -a | cut -f2 -d’-`
OPT=”(`uname -a | cut -f1 -d’-` / `uname -a | cut -f6 -d’ ‘`)”
REPLACE=”${HOST_NAME} - ${OPT}”
echo -n -e “\033]0; $REPLACE \007 “
echo “${REPLACE}”
exit 0

Add/remove things from the OPT= line to customize. To test it, just issue the command on the commandline without the ()'s to see what it'll look like.

You need to create an account or log in to post comments to this site.


Click here to browse all 4881 code snippets

Related Posts