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\)"
29 if [ "${PWD#$HOME*}" != "$PWD" ]; then
30 current_dir="~${PWD#$HOME*}"
31 elif [ "$PWD" = "$HOME" ]; then
38 current_dir="${current_dir#/view/$view_name*}"
39 current_dir="${current_dir#/sview/$view_name*}"
41 # Add CVS/Root if there is one
42 if [ -f "CVS/Root" ]; then
43 current_dir="$current_dir ($(cat CVS/Root | tr -d $CR))"
46 # Add GIT info if available
48 current_dir="$current_dir [git: $(git branch | sed -n -e 's/^\* \(.*\)/\1/p')]"
51 if [ "$TERM" = "hpterm" -o \
53 "$TERM" = "2392A" ]; then
54 string=$(echo "${SYSNAME##*:}:$@")
55 echo -n "${ESC}&f0k${#string}D$string"
56 elif [ "$TERM" = "dtterm" -o \
57 "$TERM" = "vt221" ]; then
58 string=$(echo "${SYSNAME##*:}:$@")
59 echo -n "${ESC}]2;$string\007"
60 elif [ "$TERM" = "cygwin" -o \
61 "$TERM" = "vt100" -o \
62 "$TERM" = "xterm" -o \
63 "$TERM" = "xtermc" -o \
64 "$TERM" = "xterm-256color" ]; then
65 PS1="\[\e]0;$prefix$current_dir\007\]$ROOT\[$B_YELLOW\]$SYSNAME:\[$B_WHITE\]"
69 # Function to set the icon name. Works on the terminal emulators listed.
71 if [ "$TERM" = "hpterm" -o \
73 "$TERM" = "2392A" ]; then
75 echo -n "${ESC}&f-1k${#string}D$string"
76 elif [ "$TERM" = "dtterm" -o \
77 "$TERM" = "vt100" -a "$DTTERM" = "True" ]; then
78 # Note setting icon_name on vt100 overwrites the title bar so skip it
79 echo -n "${ESC}]1;$@\007"
83 # Sets both the title bar and the icon name.
86 icon_name "${SYSNAME##*:}"
89 # Sets title bar to machine name and path. Will include a view name if in a
90 # view and a string to indicate that you are root.
92 if [ $($id -u) -eq 0 ]; then
98 view_name=$(scm pwv -short 2> /dev/null);
100 if [ $? -ne 0 -o -z "$view_name" ]; then
104 if [[ $view_name = *NONE* ]]; then
108 title_bar "${root}View: $view_name: "
111 icon_name "${SYSNAME##*:}"
114 # Sets prompt on terminals listed.
115 function set_prompt {
116 if [ $($id -u) -eq 0 ]; then
117 if [ "$TERM" = "hpterm" -o \
119 "$TERM" = "2392A" -o \
120 "$TERM" = "dtterm" -o \
121 "$TERM" = "vt100" -o \
122 "$TERM" = "xterm" -o \
123 "$TERM" = "xtermc" -o \
124 "$TERM" = "xterm-256color" -o \
125 "$TERM" = "vt220" ]; then
126 ROOT="\[${ROOT_COLOR}\]Wizard\[$NORMAL\] "
134 if [ "$TERM" = "vt100" -o \
135 "$TERM" = "xterm" -o \
136 "$TERM" = "xtermc" -o \
137 "$TERM" = "xterm-256color" -o \
138 "$TERM" = "vt220" ]; then
139 PS1="$ROOT\[$B_YELLOW\]$SYSNAME:\[$B_WHITE\]"
147 # Function to override the normal cd command, setting title and prompt.
159 # Functions to override the normal push/popd commands, setting title and prompt.
164 \pushd "$1" > /dev/null
174 \popd "$1" > /dev/null
180 # Function to override rlogin. Note that it fixes up the title and prompt
188 # Function to override rsh. Note that it fixes up the title and prompt
196 # Function to override ssh. Note that it fixes up the title and prompt
204 function processRunning {
205 if [ $ARCHITECTURE = "FreeBSD" ]; then
211 if [ $1 != '' ]; then
212 return $(ps $psopts | grep "$1" | grep -v "grep $1" | grep -v "grep -d skip" | wc -l)
217 if [ $ARCHITECTURE = "FreeBSD" ]; then
227 ps $psopts | grep "$str" | grep -v "grep $str" | grep -v "grep -d skip"
232 function start_imap {
233 # Starts an ssh tunnel for IMAP
234 ssh -C -L 143:defaria.com:143 andrew@defaria.com
238 # Displays the command line from the /proc filesystem (if present)
242 if [ $# -ne 1 ]; then
243 error "Usage: cmdline <pid>"
249 if [ ! -d "/proc" ]; then
250 error "This OS has no /proc filesystem"
254 if [ ! -d "/proc/$pid" ]; then
255 error "PID $pid does not exist"
259 if [ ! -f "/proc/$pid/cmdline" ]; then
260 error "PID $pid has no cmdline!"
264 cat /proc/$pid/cmdline | tr -c [:print:] " "
269 processRunning ypbind; ypbind=$?
270 processRunning winbind; winbind=$?
272 if [ $# -gt 0 ]; then
273 if [ $ypbind -gt 0 ]; then
274 ypcat passwd | grep -i $@
275 elif [ $winbind -gt 0 ]; then
276 for user in $(wbinfo -u | grep -i $@); do
277 wbinfo --user-info $user
281 if [ $ypbind -gt 0 ]; then
282 ypcat passwd | $PAGER
283 elif [ $wbind -gt 0 ]; then
284 for user in $(wbinfo -u); do
285 wbinfo --user-info $user
292 processRunning ypbind; ypbind=$?
293 processRunning winbind; winbind=$?
295 if [ $# -gt 0 ]; then
296 if [ $ypbind -gt 0 ]; then
297 ypcat group | grep -i $@
298 elif [ $winbind -gt 0 ]; then
299 for group in $(wbinfo -g | grep -i $@); do
300 wbinfo --group-info $group
304 if [ $ypbind -gt 0 ]; then
306 elif [ $winbind -gt 0 ]; then
307 for group in $(wbinfo -g); do
308 wbinfo --group-info $group