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 PS1="\[\e]0;$prefix$current_dir\a$ROOT\e[01;33m\]$SYSNAME:\[\e[0m\]"
66 # Function to set the icon name. Works on the terminal emulators listed.
68 if [ "$TERM" = "hpterm" -o \
70 "$TERM" = "2392A" ]; then
72 echo -n "${ESC}&f-1k${#string}D$string"
73 elif [ "$TERM" = "dtterm" -o \
74 "$TERM" = "vt100" -a "$DTTERM" = "True" ]; then
75 # Note setting icon_name on vt100 overwrites the title bar so skip it
76 echo -n "${ESC}]1;$@\007"
80 # Sets both the title bar and the icon name.
83 icon_name "${SYSNAME##*:}"
86 # Sets title bar to machine name and path. Will include a view name if in a
87 # view and a string to indicate that you are root.
89 if [ $($id -u) -eq 0 ]; then
95 view_name=$(scm pwv -short 2> /dev/null);
97 if [ $? -ne 0 -o -z "$view_name" ]; then
101 if [[ $view_name = *NONE* ]]; then
105 title_bar "$ROOT" "View: $view_name: "
108 icon_name "${SYSNAME##*:}"
111 # Sets prompt on terminals listed.
112 function set_prompt {
113 if [ $($id -u) -eq 0 ]; then
114 if [ "$TERM" = "hpterm" -o \
116 "$TERM" = "2392A" -o \
117 "$TERM" = "dtterm" -o \
118 ! -z "$DTTERM" ]; then
119 ROOT="${RED}Wizard$NORMAL "
120 elif [ "$TERM" = "vt100" -o \
121 "$TERM" = "xterm" -o \
122 "$TERM" = "vt220" ]; then
123 ROOT="${BOLD}${BLINK}Wizard$NORMAL "
129 if [ "$TERM" = "vt100" -o \
130 "$TERM" = "xterm" -o \
131 "$TERM" = "vt220" ]; then
132 PS1="$ROOT$BOLD$SYSNAME:$NORMAL"
140 # Function to override the normal cd command, setting title and prompt.
152 # Functions to override the normal push/popd commands, setting title and prompt.
157 \pushd "$1" > /dev/null
167 \popd "$1" > /dev/null
173 # Function to override rlogin. Note that it fixes up the title and prompt
181 # Function to override rsh. Note that it fixes up the title and prompt
189 # Function to override ssh. Note that it fixes up the title and prompt
198 if [ $ARCHITECTURE = "FreeBSD" ]; then
208 ps $psopts | grep "$str" | grep -v "grep $str" | grep -v "grep -d skip"
213 function start_imap {
214 # Starts an ssh tunnel for IMAP
215 ssh -C -L 143:defaria.com:143 andrew@defaria.com
219 # Displays the command line from the /proc filesystem (if present)
223 if [ $# -ne 1 ]; then
224 error "Usage: cmdline <pid>"
230 if [ ! -d "/proc" ]; then
231 error "This OS has no /proc filesystem"
235 if [ ! -d "/proc/$pid" ]; then
236 error "PID $pid does not exist"
240 if [ ! -f "/proc/$pid/cmdline" ]; then
241 error "PID $pid has no cmdline!"
245 cat /proc/$pid/cmdline | tr -c [:print:] " "
250 if [ $# -gt 0 ]; then
251 ypcat passwd | grep -i $@
253 ypcat passwd | $PAGER
258 if [ $# -gt 0 ]; then
259 ypcat group | grep -i $@