2 ###############################################################################
4 # File: $RCSfile: functions,v $
5 # Revision: $Revision: 1.20 $
6 # Description: Common bash functions
7 # Author: Andrew@DeFaria.com
8 # Created: Thu Jun 6 08:31:57 PDT 1996
9 # Modified: $Date: 2013/03/26 20:38:23 $
12 # (c) Copyright 2000-2005, Andrew@DeFaria.com, all rights reserved.
14 ###############################################################################
20 # Function to set the title bar. Works on the terminal emulators listed.
24 if [ "${PWD#$HOME*}" != "$PWD" ]; then
25 current_dir="~${PWD#$HOME*}"
26 elif [ "$PWD" = "$HOME" ]; then
33 current_dir="${current_dir#/view/$view_name*}"
34 current_dir="${current_dir#/sview/$view_name*}"
36 # Add CVS/Root if there is one
37 if [ -f "CVS/Root" ]; then
38 current_dir="$current_dir ($(cat CVS/Root | tr -d $CR))"
41 if [ "$TERM" = "hpterm" -o \
43 "$TERM" = "2392A" ]; then
44 string=$(echo "${SYSNAME##*:}:$@")
45 echo -n "${ESC}&f0k${#string}D$string"
46 elif [ "$TERM" = "dtterm" -o \
47 "$TERM" = "vt221" ]; then
48 string=$(echo "${SYSNAME##*:}:$@")
49 echo -n "${ESC}]2;$string\007"
50 elif [ "$TERM" = "cygwin" -o "$TERM" = "vt100" -o "$TERM" = "xterm" ]; then
51 PS1="\[\e]0;$prefix$current_dir\a\e[01;33m\]$SYSNAME:\[\e[0m\]"
55 # Function to set the icon name. Works on the terminal emulators listed.
57 if [ "$TERM" = "hpterm" -o \
59 "$TERM" = "2392A" ]; then
61 echo -n "${ESC}&f-1k${#string}D$string"
62 elif [ "$TERM" = "dtterm" -o \
63 "$TERM" = "vt100" -a "$DTTERM" = "True" ]; then
64 # Note setting icon_name on vt100 overwrites the title bar so skip it
65 echo -n "${ESC}]1;$@\007"
69 # Sets both the title bar and the icon name.
72 icon_name "${SYSNAME##*:}"
75 # Sets title bar to machine name and path. Will include a view name if in a
76 # view and a string to indicate that you are root.
78 if [ $($id -u) -eq 0 ]; then
84 view_name=$(scm pwv -short 2> /dev/null);
86 if [ $? -ne 0 -o -z "$view_name" ]; then
90 if [[ $view_name = *NONE* ]]; then
94 title_bar "${ROOT}View: $view_name: "
97 icon_name "${SYSNAME##*:}"
100 # Sets prompt on terminals listed.
101 function set_prompt {
102 if [ $($id -u) -eq 0 ]; then
103 if [ "$TERM" = "hpterm" -o \
105 "$TERM" = "2392A" -o \
106 "$TERM" = "dtterm" -o \
107 ! -z "$DTTERM" ]; then
108 ROOT="${RED}Wizard$NORMAL "
109 elif [ "$TERM" = "vt100" -o \
110 "$TERM" = "xterm" -o \
111 "$TERM" = "vt220" ]; then
112 ROOT="${BOLD}${BLINK}Wizard$NORMAL "
118 if [ "$TERM" = "vt100" -o \
119 "$TERM" = "xterm" -o \
120 "$TERM" = "vt220" ]; then
121 PS1="$ROOT$BOLD$SYSNAME:$NORMAL"
129 # Function to override the normal cd command, setting title and prompt.
141 # Functions to override the normal push/popd commands, setting title and prompt.
146 \pushd "$1" > /dev/null
156 \popd "$1" > /dev/null
162 # Function to override rlogin. Note that it fixes up the title and prompt
170 # Function to override rsh. Note that it fixes up the title and prompt
178 # Function to override ssh. Note that it fixes up the title and prompt
187 if [ $ARCH = "FreeBSD" ]; then
197 ps $psopts | grep "$str" | grep -v "grep $str" | grep -v "grep -d skip"
202 function start_imap {
203 # Starts an ssh tunnel for IMAP
204 ssh -C -L 143:defaria.com:143 andrew@defaria.com
208 # Displays the command line from the /proc filesystem (if present)
212 if [ $# -ne 1 ]; then
213 error "Usage: cmdline <pid>"
219 if [ ! -d "/proc" ]; then
220 error "This OS has no /proc filesystem"
224 if [ ! -d "/proc/$pid" ]; then
225 error "PID $pid does not exist"
229 if [ ! -f "/proc/$pid/cmdline" ]; then
230 error "PID $pid has no cmdline!"
234 cat /proc/$pid/cmdline | tr -c [:print:] " "
239 if [ $# -gt 0 ]; then
240 ypcat passwd | grep -i $@
242 ypcat passwd | $PAGER
247 if [ $# -gt 0 ]; then
248 ypcat group | grep -i $@