-
Notifications
You must be signed in to change notification settings - Fork 8
/
foldlines
executable file
·46 lines (38 loc) · 1.14 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
37
38
39
40
41
42
43
44
45
46
#! /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.
#
# Usage:
# foldlines [ -s ] [ -S <sep> ]
#
# Where
# -s Follow each comma with a space
# -S Use a custom separator
#
# TO-DO: options to add leaders/trailers
set self = `basename $0`
set allowed_options = sS:
# shouldn't strip bullet points unless told
## set sed_join_lines = 's/\n[-#+] /,/'
set sep = ","
# process options
eval set argv = \(`getopt -n $self -s csh --options=+$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:
set sep = "$2:q"
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/"
## echo "[$sep] $sed_join_lines"
sed -e 's/^# //' -e ': start' -e N -e "$sed_join_lines" -e 't start'