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 ROOT="${NORMAL}\($ROOT\)"
30 if [ "${PWD#$HOME*}" != "$PWD" ]; then
31 current_dir="~${PWD#$HOME*}"
32 elif [ "$PWD" = "$HOME" ]; then
39 current_dir="${current_dir#/view/$view_name*}"
40 current_dir="${current_dir#/sview/$view_name*}"
42 # Add CVS/Root if there is one
43 if [ -f "CVS/Root" ]; then
44 current_dir="$current_dir ($(cat CVS/Root | tr -d $CR))"
47 # Add GIT info if available
49 current_dir="$current_dir [git: $(git branch | sed -n -e 's/^\* \(.*\)/\1/p')]"
52 if [ "$TERM" = "hpterm" -o \
54 "$TERM" = "2392A" ]; then
55 string=$(echo "${SYSNAME##*:}:$@")
56 echo -n "${ESC}&f0k${#string}D$string"
57 elif [ "$TERM" = "dtterm" -o \
58 "$TERM" = "vt221" ]; then
59 string=$(echo "${SYSNAME##*:}:$@")
60 echo -n "${ESC}]2;$string\007"
61 elif [ "$TERM" = "cygwin" -o "$TERM" = "vt100" -o "$TERM" = "xterm" ]; then
62 # Here's where we set the prompt with root
63 PS1="\[\e]0;$prefix$current_dir\a$AQUA\]$ROOT\[$YELLOW\]$SYSNAME:\[$NORMAL\]"
67 # Function to set the icon name. Works on the terminal emulators listed.
69 if [ "$TERM" = "hpterm" -o \
71 "$TERM" = "2392A" ]; then
73 echo -n "${ESC}&f-1k${#string}D$string"
74 elif [ "$TERM" = "dtterm" -o \
75 "$TERM" = "vt100" -a "$DTTERM" = "True" ]; then
76 # Note setting icon_name on vt100 overwrites the title bar so skip it
77 echo -n "${ESC}]1;$@\007"
81 # Sets both the title bar and the icon name.
84 icon_name "${SYSNAME##*:}"
87 # Sets title bar to machine name and path. Will include a view name if in a
88 # view and a string to indicate that you are root.
90 if [ $($id -u) -eq 0 ]; then
96 view_name=$(scm pwv -short 2> /dev/null);
98 if [ $? -ne 0 -o -z "$view_name" ]; then
102 if [[ $view_name = *NONE* ]]; then
106 title_bar "$ROOT" "View: $view_name: "
109 icon_name "${SYSNAME##*:}"
112 # Sets prompt on terminals listed.
113 function set_prompt {
114 if [ $($id -u) -eq 0 ]; then
115 if [ "$TERM" = "hpterm" -o \
117 "$TERM" = "2392A" -o \
118 "$TERM" = "dtterm" -o \
119 ! -z "$DTTERM" ]; then
120 ROOT="${RED}Wizard$NORMAL "
121 elif [ "$TERM" = "vt100" -o \
122 "$TERM" = "xterm" -o \
123 "$TERM" = "vt220" ]; then
124 ROOT="${BOLD}${BLINK}Wizard$NORMAL "
130 if [ "$TERM" = "vt100" -o \
131 "$TERM" = "xterm" -o \
132 "$TERM" = "vt220" ]; then
133 PS1="$ROOT$BOLD$SYSNAME:$NORMAL"
141 # Function to override the normal cd command, setting title and prompt.
153 # Functions to override the normal push/popd commands, setting title and prompt.
158 \pushd "$1" > /dev/null
168 \popd "$1" > /dev/null
174 # Function to override rlogin. Note that it fixes up the title and prompt
182 # Function to override rsh. Note that it fixes up the title and prompt
190 # Function to override ssh. Note that it fixes up the title and prompt
199 if [ $ARCHITECTURE = "FreeBSD" ]; then
209 ps $psopts | grep "$str" | grep -v "grep $str" | grep -v "grep -d skip"
214 function start_imap {
215 # Starts an ssh tunnel for IMAP
216 ssh -C -L 143:defaria.com:143 andrew@defaria.com
220 # Displays the command line from the /proc filesystem (if present)
224 if [ $# -ne 1 ]; then
225 error "Usage: cmdline <pid>"
231 if [ ! -d "/proc" ]; then
232 error "This OS has no /proc filesystem"
236 if [ ! -d "/proc/$pid" ]; then
237 error "PID $pid does not exist"
241 if [ ! -f "/proc/$pid/cmdline" ]; then
242 error "PID $pid has no cmdline!"
246 cat /proc/$pid/cmdline | tr -c [:print:] " "
251 if [ $# -gt 0 ]; then
252 ypcat passwd | grep -i $@
254 ypcat passwd | $PAGER
259 if [ $# -gt 0 ]; then
260 ypcat group | grep -i $@