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 # Add GIT info if available
43 current_dir="$current_dir [git: $(git branch | sed -n -e 's/^\* \(.*\)/\1/p')]"
46 if [ "$TERM" = "hpterm" -o \
48 "$TERM" = "2392A" ]; then
49 string=$(echo "${SYSNAME##*:}:$@")
50 echo -n "${ESC}&f0k${#string}D$string"
51 elif [ "$TERM" = "dtterm" -o \
52 "$TERM" = "vt221" ]; then
53 string=$(echo "${SYSNAME##*:}:$@")
54 echo -n "${ESC}]2;$string\007"
55 elif [ "$TERM" = "cygwin" -o "$TERM" = "vt100" -o "$TERM" = "xterm" ]; then
56 PS1="\[\e]0;$prefix$current_dir\a\e[01;33m\]$SYSNAME:\[\e[0m\]"
60 # Function to set the icon name. Works on the terminal emulators listed.
62 if [ "$TERM" = "hpterm" -o \
64 "$TERM" = "2392A" ]; then
66 echo -n "${ESC}&f-1k${#string}D$string"
67 elif [ "$TERM" = "dtterm" -o \
68 "$TERM" = "vt100" -a "$DTTERM" = "True" ]; then
69 # Note setting icon_name on vt100 overwrites the title bar so skip it
70 echo -n "${ESC}]1;$@\007"
74 # Sets both the title bar and the icon name.
77 icon_name "${SYSNAME##*:}"
80 # Sets title bar to machine name and path. Will include a view name if in a
81 # view and a string to indicate that you are root.
83 if [ $($id -u) -eq 0 ]; then
89 view_name=$(scm pwv -short 2> /dev/null);
91 if [ $? -ne 0 -o -z "$view_name" ]; then
95 if [[ $view_name = *NONE* ]]; then
99 title_bar "${ROOT}View: $view_name: "
102 icon_name "${SYSNAME##*:}"
105 # Sets prompt on terminals listed.
106 function set_prompt {
107 if [ $($id -u) -eq 0 ]; then
108 if [ "$TERM" = "hpterm" -o \
110 "$TERM" = "2392A" -o \
111 "$TERM" = "dtterm" -o \
112 ! -z "$DTTERM" ]; then
113 ROOT="${RED}Wizard$NORMAL "
114 elif [ "$TERM" = "vt100" -o \
115 "$TERM" = "xterm" -o \
116 "$TERM" = "vt220" ]; then
117 ROOT="${BOLD}${BLINK}Wizard$NORMAL "
123 if [ "$TERM" = "vt100" -o \
124 "$TERM" = "xterm" -o \
125 "$TERM" = "vt220" ]; then
126 PS1="$ROOT$BOLD$SYSNAME:$NORMAL"
134 # Function to override the normal cd command, setting title and prompt.
146 # Functions to override the normal push/popd commands, setting title and prompt.
151 \pushd "$1" > /dev/null
161 \popd "$1" > /dev/null
167 # Function to override rlogin. Note that it fixes up the title and prompt
175 # Function to override rsh. Note that it fixes up the title and prompt
183 # Function to override ssh. Note that it fixes up the title and prompt
192 if [ $ARCHITECTURE = "FreeBSD" ]; then
202 ps $psopts | grep "$str" | grep -v "grep $str" | grep -v "grep -d skip"
207 function start_imap {
208 # Starts an ssh tunnel for IMAP
209 ssh -C -L 143:defaria.com:143 andrew@defaria.com
213 # Displays the command line from the /proc filesystem (if present)
217 if [ $# -ne 1 ]; then
218 error "Usage: cmdline <pid>"
224 if [ ! -d "/proc" ]; then
225 error "This OS has no /proc filesystem"
229 if [ ! -d "/proc/$pid" ]; then
230 error "PID $pid does not exist"
234 if [ ! -f "/proc/$pid/cmdline" ]; then
235 error "PID $pid has no cmdline!"
239 cat /proc/$pid/cmdline | tr -c [:print:] " "
244 if [ $# -gt 0 ]; then
245 ypcat passwd | grep -i $@
247 ypcat passwd | $PAGER
252 if [ $# -gt 0 ]; then
253 ypcat group | grep -i $@