2 ###############################################################################
4 # File: $RCSfile: functions,v $
5 # Revision: $Revision: 1.10 $
6 # Description: Common bash functions
7 # Author: Andrew@DeFaria.com
8 # Created: Thu Jun 6 08:31:57 PDT 1996
9 # Modified: $Date: 2006/07/30 16:12:35 $
12 # (c) Copyright 2000-2005, Andrew@DeFaria.com, all rights reserved.
14 ###############################################################################
18 # Function to set the title bar. Works on the terminal emulators listed.
22 if [ "${PWD#$HOME*}" != "$PWD" ]; then
23 current_dir="~${PWD#$HOME*}"
24 elif [ "$PWD" = "$HOME" ]; then
31 current_dir="${current_dir#/view/$view_name*}"
32 current_dir="${current_dir#/sview/$view_name*}"
34 # Add CVS/Root if there is one
35 if [ -f "CVS/Root" ]; then
36 current_dir="$current_dir ($(cat CVS/Root))"
39 if [ "$TERM" = "hpterm" -o \
41 "$TERM" = "2392A" ]; then
42 string=$(echo "${SYSNAME##*:}:$@")
43 echo -n "${ESC}&f0k${#string}D$string"
44 elif [ "$TERM" = "dtterm" -o \
45 "$TERM" = "vt221" ]; then
46 string=$(echo "${SYSNAME##*:}:$@")
47 echo -n "${ESC}]2;$string\007"
48 elif [ "$TERM" = "cygwin" -o "$TERM" = "vt100" ]; then
49 PS1="\[\e]0;$prefix$current_dir\a\e[01;33m\]$SYSNAME:\[\e[0m\]"
53 # Function to set the icon name. Works on the terminal emulators listed.
55 if [ "$TERM" = "hpterm" -o \
57 "$TERM" = "2392A" ]; then
59 echo -n "${ESC}&f-1k${#string}D$string"
60 elif [ "$TERM" = "dtterm" -o \
61 "$TERM" = "vt100" -a "$DTTERM" = "True" ]; then
62 # Note setting icon_name on vt100 overrights the title bar so skip it
63 echo -n "${ESC}]1;$@\007"
67 # Sets both the title bar and the icon name.
70 icon_name "${SYSNAME##*:}"
73 # Sets title bar to machine name and path. Will include a view name if in a
74 # view and a string to indicate that you are root.
76 uid=$(id | cut -f2 -d= | cut -f1 -d\()
77 if [ $uid -eq 0 ]; then
83 view_name=$(ct pwv -short 2> /dev/null | tr -d
\r);
89 if [[ $view_name = *NONE* ]]; then
93 title_bar "${ROOT}View: $view_name: "
95 icon_name "${SYSNAME##*:}"
98 # Sets prompt on terminals listed.
100 uid=$(id | cut -f2 -d= | cut -f1 -d\()
101 if [ $uid -eq 0 ]; then
102 if [ "$TERM" = "hpterm" -o \
104 "$TERM" = "2392A" -o \
105 "$TERM" = "dtterm" -o \
106 ! -z "$DTTERM" ]; then
107 ROOT="${RED}Wizard$NORMAL "
108 elif [ "$TERM" = "vt100" -o \
109 "$TERM" = "vt220" ]; then
110 ROOT="${BOLD}${BLINK}Wizard$NORMAL "
115 if [ "$TERM" = "vt100" -o \
116 "$TERM" = "vt220" ]; then
117 PS1="$ROOT$BOLD$SYSNAME:$NORMAL"
124 # Function to override the normal cd command, setting title and prompt.
138 # Functions to override the normal push/popd commands, setting title and prompt.
159 # Function to override rlogin. Note that it fixes up the title and prompt
167 # Function to override rsh. Note that it fixes up the title and prompt
175 # Function to override ssh. Note that it fixes up the title and prompt
184 if [ $ARCH = "FreeBSD" ]; then
194 ps $psopts | grep "$str" | grep -v "grep $str" | grep -v "grep -d skip"
199 function start_imap {
200 # Starts an ssh tunnel for IMAP
201 ssh -C -L 143:defaria.com:143 andrew@defaria.com
205 # Displays the command line from the /proc filesystem (if present)
209 if [ $# -ne 1 ]; then
210 error "Usage: cmdline <pid>"
216 if [ ! -d "/proc" ]; then
217 error "This OS has no /proc filesystem"
221 if [ ! -d "/proc/$pid" ]; then
222 error "PID $pid does not exist"
226 if [ ! -f "/proc/$pid/cmdline" ]; then
227 error "PID $pid has no cmdline!"
231 cat /proc/$pid/cmdline | tr -c [:print:] " "
236 if [ $# -eq 0 ]; then
237 ypcat passwd | $PAGER
239 if [ $# -eq 1 ]; then
241 ypcat passwd | grep -i $str