3 # This defines some general, useful functions.
5 # test whether we've been here before or not.
7 function_sentinel &>/dev/null
9 # there was no error, so we can skip the inits.
10 if [ ! -z "$SHELL_DEBUG" ]; then
11 echo skipping functions.sh because already defined.
16 if [ -z "$skip_all" ]; then
17 if [ ! -z "$SHELL_DEBUG" ]; then
18 echo function definitions begin...
21 # a handy little method that can be used for date strings. it was getting
22 # really tiresome how many different ways the script did the date formatting.
23 function date_stringer() {
24 date +"%Y_%m_%e_%H%M_%S" | tr -d '/\n/'
27 # makes a directory of the name specified and then tries to change the
28 # current directory to that directory.
30 if [ ! -d "$1" ]; then mkdir -p "$1"; fi
34 # locates a process given a search pattern to match in the process list.
36 PID_DUMP="$(mktemp "$TMP/zz_pidlist.XXXXXX")"
37 appropriate_pattern='s/^[-a-zA-Z_0-9][-a-zA-Z_0-9]* *\([0-9][0-9]*\).*$/\1/p'
38 # pattern to use for peeling off the process numbers.
40 # flags to pass to ps if any special ones are needed.
41 if [ "$OS" = "Windows_NT" ]; then
42 # on win32, there is some weirdness to support msys.
43 appropriate_pattern='s/^[ ]*\([0-9][0-9]*\).*$/\1/p'
46 /bin/ps $extra_flags wuax >$PID_DUMP
47 # remove the first line of the file, search for the pattern the
48 # user wants to find, and just pluck the process ids out of the
50 PIDS_SOUGHT=$(cat $PID_DUMP \
53 | sed -n -e "$appropriate_pattern")
54 if [ ! -z "$PIDS_SOUGHT" ]; then echo "$PIDS_SOUGHT"; fi
58 # finds all processes matching the pattern specified and shows their full
59 # process listing (whereas psfind just lists process ids).
62 if [ ! -z "$p" ]; then
64 echo "Processes containing \"$1\"..."
66 if [ -n "$IS_DARWIN" ]; then
69 # only print the header the first time.
70 if [ -z "$fuzil_sentinel" ]; then
73 ps $i -w -u | sed -e '1d'
78 # cases besides darwin OS (for macs).
80 if [ "$OS" = "Windows_NT" ]; then
81 # special case for windows.
85 ps $extra_flags | grep "^ *$curr"
88 # normal OSes can handle a nice simple query.
95 # an unfortunately similarly named function to the above 'ps' as in process
96 # methods, but this 'ps' stands for postscript. this takes a postscript file
97 # and converts it into pcl3 printer language and then ships it to the printer.
98 # this mostly makes sense for an environment where one's default printer is
99 # pcl. if the input postscript causes ghostscript to bomb out, there has been
100 # some good success running ps2ps on the input file and using the cleaned
101 # postscript file for printing.
102 function ps2pcl2lpr() {
104 gs -sDEVICE=pcl3 -sOutputFile=- -sPAPERSIZE=letter "$i" | lpr -l
108 function fix_alsa() {
109 sudo /etc/init.d/alsasound restart
112 # switches from a /X/path form to an X:/ form.
113 function msys_to_dos_path() {
114 # we always remove dos slashes in favor of forward slashes.
115 echo "$1" | sed -e 's/\\/\//g' | sed -e 's/\/\([a-zA-Z]\)\/\(.*\)/\1:\/\2/'
118 # switches from an X:/ form to an /X/path form.
119 function dos_to_msys_path() {
120 # we always remove dos slashes in favor of forward slashes.
121 echo "$1" | sed -e 's/\\/\//g' | sed -e 's/\([a-zA-Z]\):\/\(.*\)/\/\1\/\2/'
124 # su function: makes su perform a login.
125 # for some OSes, this transfers the X authority information to the new login.
127 # decide if we think this is debian or ubuntu or a variant.
128 DEBIAN_LIKE=$(if [ ! -z "$(grep -i debian /etc/issue)" \
129 -o ! -z "$(grep -i ubuntu /etc/issue)" ]; then echo 1; else echo 0; fi)
131 if [ $DEBIAN_LIKE -eq 1 ]; then
132 # debian currently requires the full version which imports X authority
133 # information for su.
135 # get the x authority info for our current user.
136 source $FEISTY_MEOW_SCRIPTS/x_win/get_x_auth.sh
138 if [ -z "$X_auth_info" ]; then
139 # if there's no authentication info to pass along, we just do a normal su.
142 # under X, we update the new login's authority info with the previous
144 (unset XAUTHORITY; /bin/su -l $* -c "$X_auth_info ; export DISPLAY=$DISPLAY ; bash")
147 # non-debian supposedly doesn't need the extra overhead any more.
148 # or at least suse doesn't, which is the other one we've tested on.
152 # relabel the console after returning.
153 bash $FEISTY_MEOW_SCRIPTS/tty/label_terminal_with_infos.sh
156 # sudo function wraps the normal sudo by ensuring we replace the terminal
157 # label if they're doing an su with the sudo.
159 local first_command="$1"
161 if [ "$first_command" == "su" ]; then
162 # yep, they were doing an su, but they're back now.
163 bash $FEISTY_MEOW_SCRIPTS/tty/label_terminal_with_infos.sh
167 # buntar is a long needed uncompressing macro that feeds into tar -x.
168 # it takes a list of bz2 file names and extracts their contents into
169 # sequentially numbered directories.
174 pushd buntar_$index &>/dev/null
176 # if the filename has no directory component, we will assume it used to
177 # be above our unzipping directory here.
178 if [ "$(basename $file)" = $file ]; then
181 bunzip2 -d -c $file | tar -xf -
183 index=$(expr $index + 1)
187 # trashes the .#blah files that cvs and svn leave behind when finding conflicts.
188 # this kind of assumes you've already checked them for any salient facts.
189 function clean_cvs_junk() {
191 find $i -follow -type f -iname ".#*" -exec perl $FEISTY_MEOW_SCRIPTS/files/safedel.pl {} ";"
195 # recreates all the generated files that the feisty meow scripts use.
196 function regenerate() {
197 bash $FEISTY_MEOW_SCRIPTS/core/bootstrap_shells.sh
199 local wheres_nechung=$(which nechung 2>/dev/null)
200 if [ -z "$wheres_nechung" ]; then
201 echo "The nechung oracle program cannot be found. You may want to consider"
202 echo "rebuilding the feisty meow applications with this command:"
203 echo " bash $FEISTY_MEOW_DIR/scripts/generator/bootstrap_build.sh"
209 function function_sentinel() { return 0; }
211 if [ ! -z "$SHELL_DEBUG" ]; then echo function definitions end....; fi