Skip to content

Commit 97f943a

Browse files
committed
Merge branch 'master' of github.com:lhunath/scripts
2 parents 160fd3a + d4fb0f9 commit 97f943a

File tree

2 files changed

+45
-1
lines changed

2 files changed

+45
-1
lines changed

bashlib/bashlib

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -542,6 +542,50 @@ iterate() (
542542
fi
543543
) # _____________________________________________________________________
544544

545+
546+
547+
# _______________________________________________________________________
548+
# |__ csvline ____________________________________________________________|
549+
#
550+
# csvline [-d delimiter] [-D line-delimiter]
551+
#
552+
# Parse a CSV record from standard input, storing the fields in the CSVLINE array.
553+
#
554+
# By default, a single line of input is read and parsed into comma-delimited fields.
555+
# Fields can optionally contain double-quoted data, including field delimiters.
556+
#
557+
# A different field delimiter can be specified using -d. You can use -D
558+
# to change the definition of a "record" (eg. to support NULL-delimited records).
559+
#
560+
csvline() {
561+
CSVLINE=()
562+
local line field quoted=0 delimiter=, lineDelimiter=$'\n' c
563+
local OPTIND=1 arg
564+
while getopts :d: arg; do
565+
case $arg in
566+
d) delimiter=$OPTARG ;;
567+
esac
568+
done
569+
570+
IFS= read -d "$lineDelimiter" -r line || return
571+
while IFS= read -rn1 c; do
572+
case $c in
573+
\")
574+
(( quoted = !quoted ))
575+
continue ;;
576+
$delimiter)
577+
if (( ! quoted )); then
578+
CSVLINE+=( "$field" ) field=
579+
continue
580+
fi ;;
581+
esac
582+
field+=$c
583+
done <<< "$line"
584+
[[ $field ]] && CSVLINE+=( "$field" ) ||:
585+
} # _____________________________________________________________________
586+
587+
588+
545589
# ______________________________________________________________________
546590
# |__ Logging ___________________________________________________________|
547591
#

git-diff-plist renamed to git-plist-clean-filter

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ try:
88
sys.stdout.flush()
99
except IOError:
1010
pass
11-
' | PlistBuddy -c Print -
11+
'

0 commit comments

Comments
 (0)