forked from unixnut/scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
foldlines
executable file
·36 lines (28 loc) · 1 KB
/
foldlines
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#! /bin/csh -f
# foldlines (C shell script) -- folds several lines into a comma-separated list
# (any whitespace preceeding the lines is stripped)
# (the first line is blanked if it starts with a hash and a space)
# TO-DO: options to add leaders/trailers
set self = `basename $0`
set allowed_options = sS:l:t:
# shouldn't strip bullet points unless told
## set sed_join_lines = 's/\n[-#+] /,/'
set sep = ""
# process options
set argv = (`getopt -n $self -s csh +$allowed_options $*:q`)
if ($status != 0) exit 1 # getopt would have already reported the error
while (x$1:q != x--)
switch ($1)
case -s:
set sep = " "
breaksw
case -S:
eval "set sep = $2" # argument was quoted by getopt
shift # get rid of the option
breaksw
endsw
shift # get rid of the option (or its arg if the inner shift already got rid it)
end
shift # get rid of the "--"
set sed_join_lines = "s/\n[ ]*/,$sep/"
sed -e 's/^# //' -e ': start' -e N -e "$sed_join_lines" -e 't start'