source: trunk/packs/dotfiles/add.csh @ 8540

Revision 8540, 8.6 KB checked in by cfields, 28 years ago (diff)
Cut sed invocations in half. Change sed delimiter from - to ; as there are lockers with mountpoints containing -. If there is a ; now we will lose horribly, but it will be well deserved.
Line 
1#!/dev/null
2#
3# $Id: add.csh,v 1.29 1996-06-07 18:48:15 cfields Exp $
4#
5# add <addargs> <-a attachargs> <lockername> <lockername> ...
6#
7#       -v      verbose
8#       -v0     verbose w/o debugging
9#       -d      debugging
10#       -n      specify new attach behavior
11#       -f      add/move lockers to the front of the path
12#       -r      remove lockers from path
13#       -p      print path environment filtered
14#       -w      give warning for adds with no bindirs
15#       -e      perform operations for the .environment file (changing
16#                 $athena_path, $athena_manpath instead of $PATH,
17#                 etc.)
18#       -a      pass further options to attach
19#
20
21# alias add 'set add_opts = (\!:*); source $initdir/add'
22
23set add_vars=( add_vars add_usage add_verbose add_front add_warn add_env \
24               add_opts add_attach add_dirs add_bin add_bindir \
25               add_man add_mandir add_print add_path add_manpath \
26               add_new add_oldverbose add_remove add_debug \
27               add_arg add_newpath add_newmanpath add_i )
28
29set add_usage = "Usage: add [-v] [-v0] [-d] [-n] [-f] [-r] [-p] [-w] [-e] [-a attachflags]              [lockername] [lockername] ..."
30
31#
32# Parse options
33#
34
35if ( $#add_opts == 0 ) set add_print
36
37if ( $?add_flags ) then
38  set add_opts = ( $add_flags $add_opts )
39endif
40
41while ( $#add_opts > 0 )
42  set add_arg = $add_opts[1]
43
44  switch ( $add_arg )
45
46    case -v:
47      set add_verbose
48      set add_oldverbose
49      breaksw
50
51    case -v0:
52      set add_verbose
53      breaksw
54
55    case -d:
56      set add_debug
57      breaksw
58
59    case -n:
60      set add_new
61      breaksw
62
63    case -f:
64      set add_front
65      breaksw
66
67    case -r:
68      set add_remove
69      breaksw
70
71    case -p:
72      set add_print
73      breaksw
74
75    case -w:
76      set add_warn
77      breaksw
78
79    case -e:
80      set add_env
81      breaksw
82
83    case -a:
84      shift add_opts
85      if ( $#add_opts ) then
86        set add_attach = "$add_opts"
87        set add_opts=
88      else
89        echo "add: options required after -a"
90        echo "$add_usage"
91        goto finish
92      endif
93      breaksw
94
95    default:
96      if ( "$add_opts[1]" =~ -* ) then
97        echo "add: unrecognized option: $add_opts[1]"
98        echo "$add_usage"
99        goto finish
100      endif
101
102      if ( $#add_opts ) then
103        set add_attach = "$add_opts"
104        set add_opts=
105      endif
106  endsw
107  shift add_opts
108
109end
110
111if ( $?add_oldverbose && ! $?add_new ) set add_debug
112
113#
114# Try to make our environment sane.
115#
116
117if ( ! $?ATHENA_SYS ) then
118  setenv ATHENA_SYS `machtype -S`
119  if ( $ATHENA_SYS == "" ) then
120    setenv ATHENA_SYS `fs sysname | awk -F\' '{ print $2 }'`
121  endif
122  if ( $ATHENA_SYS == "" ) setenv ATHENA_SYS "@sys"
123endif
124
125set add_bindir = arch/$ATHENA_SYS/bin
126set add_mandir = arch/$ATHENA_SYS/man
127
128if ( ! $?bindir ) then
129  set bindir = `machtype`bin
130  if ( $bindir == "bin" ) set bindir = $add_bindir
131endif
132
133#
134# Print the filtered path and exit.
135#
136
137if ( $?add_print ) then
138  echo $path | sed -e "s-/mit/\([^/]*\)/$add_bindir-{add \1}-g" \
139             | sed -e "s-/mit/\([^/]*\)/$bindir-{add \1}-g"
140  goto finish
141endif
142
143#
144# Call attach. Once for a normal add, twice for a verbose to get
145# interesting output from attach.
146#
147
148if ( $?add_new ) then
149
150#
151# New, sane behavior for cases with no authentication and
152# fascist lockers, and more reliable output.
153#
154
155  if ( $?add_verbose ) then
156    attach $add_attach
157    set add_dirs = `attach -h -p $add_attach`
158  else
159    set add_dirs = `attach -p $add_attach`
160  endif
161else
162
163#
164# Old behavior.
165#
166
167  if ( $?add_verbose ) then
168    attach -n -h $add_attach
169  endif
170  set add_dirs = `attach -p $add_attach`
171endif
172
173#
174# For the non-environment add, generate a prototype for the new path.
175#
176if ( ! $?add_env ) then
177  set add_newpath = $PATH
178  set add_newmanpath = $MANPATH
179endif
180
181#
182# Loop through all of the lockers attach told us about.
183#
184
185set add_path
186set add_manpath
187
188foreach add_i ($add_dirs)
189  unset add_bin
190  unset add_man
191
192#
193# Find the bin directory
194#
195
196  if ( -d $add_i/$add_bindir ) then
197    set add_bin = $add_i/$add_bindir
198  endif
199
200  if ( ! $?add_bin ) then
201    if ( -d $add_i/$bindir ) then
202      set add_bin = $add_i/$bindir
203    endif
204  endif
205
206#
207# Find the man directory
208# Don't use arch/man unless you actually have architecture
209# dependent man pages in your locker.
210#
211
212  if ( -d $add_i/$add_mandir ) then
213    set add_man = $add_i/$add_mandir
214  endif
215
216  if ( ! $?add_man ) then
217    if ( -d $add_i/man ) then
218      set add_man = $add_i/man
219    endif
220  endif
221
222#
223# If we need to remove path elements, do it here. Includes removing
224# elements for the purposes of moving them elsewhere.
225#
226  if ( ! $?add_env && ( $?add_front || $?add_remove ) ) then
227    if ( $?add_bin ) then
228      if ( "$add_newpath" =~ *"$add_bin"* ) then
229        if ( "$add_newpath" =~ "$add_bin"* ) then
230          set add_newpath = `echo $add_newpath | sed -e "s;${add_bin}:;;g"`
231        else
232          set add_newpath = `echo $add_newpath | sed -e "s;:${add_bin};;g"`
233        endif
234        if ( $?add_debug ) echo $add_bin removed from \$PATH
235      endif
236    endif
237    if ( $?add_man ) then
238      if ( "$add_newmanpath" =~ *"$add_man"* ) then
239        if ( "$add_newmanpath" =~ "$add_man"* ) then
240          set add_newmanpath = `echo $add_newmanpath | sed -e "s;${add_man}:;;g"`
241        else
242          set add_newmanpath = `echo $add_newmanpath | sed -e "s;:${add_man};;g"`
243        endif
244        if ( $?add_debug ) echo $add_man removed from \$MANPATH
245      endif
246    endif
247  endif
248
249  if ( ! $?add_remove ) then
250#
251# Add the bin and man directories, as appropriate, to the head or
252# tail of the path, to PATH and MANPATH or athena_path and athena_manpath.
253#
254
255    if ( $?add_bin || $?add_man ) then
256      switch ( $?add_env$?add_front )
257
258        case 00:
259          if ( $?add_bin ) then
260            if ( "$add_newpath" !~ *"$add_bin"* ) then
261              if ( $?add_debug ) echo $add_bin added to end of \$PATH
262              set add_path = ${add_path}:$add_bin
263            endif
264          endif
265
266          if ( $?add_man ) then
267            if ( "$add_newmanpath" !~ *"$add_man"* ) then
268              if ( $?add_debug ) echo $add_man added to end of \$MANPATH
269              set add_manpath = ${add_manpath}:$add_man
270            endif
271          endif
272          breaksw
273
274        case 01:
275          if ( $?add_bin ) then
276            if ( "$add_newpath" !~ *"$add_bin"* ) then
277              if ( $?add_debug ) echo $add_bin added to front of \$PATH
278              set add_path = ${add_bin}:$add_path
279            endif
280          endif
281
282          if ( $?add_man ) then
283            if ( "$add_newmanpath" !~ *"$add_man"* ) then
284              if ( $?add_debug ) echo $add_man added to front of \$MANPATH
285              set add_manpath = ${add_man}:$add_manpath
286            endif
287          endif
288          breaksw
289
290        case 10:
291          if ( $?add_bin ) then
292            if ( "$athena_path" !~ *"$add_bin"* ) then
293              if ( $?add_debug ) echo $add_bin added to end of \$athena_path
294              set athena_path = ($athena_path $add_bin)
295            endif
296          endif
297
298          if ( $?add_man ) then
299            if ( "$athena_manpath" !~ *"$add_man"* ) then
300              if ( $?add_debug ) echo $add_man added to end of \$athena_manpath
301              set athena_manpath = ${athena_manpath}:$add_man
302            endif
303            if ( "$MANPATH" !~ *"$add_man"* ) then
304              if ( $?add_debug ) echo $add_man added to end of \$MANPATH
305              setenv MANPATH ${MANPATH}:$add_man
306            endif
307          endif
308          breaksw
309
310        case 11:
311          if ( $?add_bin ) then
312            if ( "$athena_path" !~ *"$add_bin"* ) then
313              if ( $?add_debug ) echo $add_bin added to front of \$athena_path
314              set athena_path = ($add_bin $athena_path)
315            endif
316          endif
317
318          if ( $?add_man ) then
319            if ( "$athena_manpath" !~ *"$add_man"* ) then
320              if ( $?add_debug ) echo $add_man added to front of \$athena_manpath
321              set athena_manpath = ${add_man}:$athena_manpath
322            endif
323            if ( "$MANPATH" !~ *"$add_man"* ) then
324              if ( $?add_debug ) echo $add_man added to front of \$MANPATH
325              setenv MANPATH ${add_man}:$MANPATH
326            endif
327          endif
328          breaksw
329      endsw
330    endif
331
332    if ( ! $?add_bin && $?add_warn ) then
333      echo add: warning: $add_i has no binary directory
334    endif
335  endif
336end
337
338
339if ( ! $?add_env ) then
340  if ( $?add_path ) then
341    if ( $?add_front ) then
342      setenv PATH ${add_path}${add_newpath}
343    else
344      setenv PATH ${add_newpath}${add_path}
345    endif
346  endif
347
348  if ( $?add_manpath ) then
349    if ( $?add_front ) then
350      setenv MANPATH ${add_manpath}${add_newmanpath}
351    else
352      setenv MANPATH ${add_newmanpath}${add_manpath}
353    endif
354  endif
355endif
356
357finish:
358
359#
360# We were never here.
361#
362
363foreach add_i ( $add_vars )
364  unset $add_i
365end
Note: See TracBrowser for help on using the repository browser.