Initial commit.
This commit is contained in:
commit
2dda2e227d
52 changed files with 2704 additions and 0 deletions
76
bits/readline/readline
Executable file
76
bits/readline/readline
Executable file
|
|
@ -0,0 +1,76 @@
|
|||
#!/bin/bash
|
||||
|
||||
shopt -s extglob
|
||||
|
||||
exec {FD}<readline.ini
|
||||
|
||||
#key2value() {
|
||||
# # SECTION=
|
||||
# KEY="$1"
|
||||
#
|
||||
# if [[ "${VALUE:0:1}" =~ [\"\'] ]]; then
|
||||
# printf "%s" "${VALUE:1:-1}"
|
||||
# else
|
||||
# printf "%s" "$VALUE"
|
||||
# fi
|
||||
#}
|
||||
|
||||
while :; do
|
||||
LINE=""
|
||||
while :; do
|
||||
# The 'read' will remove leading whitespace from the line.
|
||||
read -r -u $FD REPLY || break 2
|
||||
|
||||
# Handle line continuations.
|
||||
if [[ "${REPLY: -1:1}" == "\\" ]]; then
|
||||
LINE+="${REPLY:0:-1}"
|
||||
continue
|
||||
else
|
||||
LINE+="$REPLY"
|
||||
break
|
||||
fi
|
||||
done
|
||||
|
||||
# Ignore the line if it's a comment.
|
||||
# FIXME: Make it so the comments can be # or ; or both.
|
||||
[[ "$LINE" =~ ^[[:blank:]]*([#\;].*)*$ ]] && continue
|
||||
|
||||
# Remove trailing whitespace from key part.
|
||||
LINE="${LINE/+([[:blank:]])=/=}"
|
||||
|
||||
# Remove leading whitespace from value part.
|
||||
LINE="${LINE/=+([[:blank:]])/=}"
|
||||
|
||||
# Extract the key and the value
|
||||
KEY="${LINE%%=*}"
|
||||
VALUE="${LINE#*=}"
|
||||
|
||||
# If the value starts with a " or ' it must end with same.
|
||||
if [[ "${VALUE:0:1}" =~ [\"\'] ]]; then
|
||||
if [[ "${VALUE:0:1}" != "${VALUE: -1:1}" ]]; then
|
||||
echo "Unmatched quotes - ignoring line."
|
||||
continue
|
||||
fi
|
||||
fi
|
||||
|
||||
|
||||
|
||||
|
||||
printf "<%s> = <%s>\n" "$KEY" "$VALUE"
|
||||
|
||||
unset FOO
|
||||
declare -A FOO
|
||||
FOO["$KEY"]=$VALUE
|
||||
printf "%s\n" "$(key2value "$KEY")"
|
||||
|
||||
# printf "%q\n" "$VALUE"
|
||||
# declare -p FOO
|
||||
echo
|
||||
done
|
||||
|
||||
|
||||
|
||||
|
||||
# FOO="test1 = test2 = test3"
|
||||
# KEY="${FOO%%=*}"
|
||||
# VALUE="${FOO#*=}"
|
||||
18
bits/readline/readline.ini
Normal file
18
bits/readline/readline.ini
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
# test
|
||||
; test
|
||||
# test
|
||||
; test
|
||||
foo = This is a line with \
|
||||
a backslash \
|
||||
# foo
|
||||
\
|
||||
|
||||
#bar = This is a line without a backslash
|
||||
|
||||
#baz = " This is a = \
|
||||
# line in \
|
||||
#quotes "
|
||||
|
||||
foo = 'Test \' $BASH_SOURCE'
|
||||
bar = "Test 2 ' \""
|
||||
#foof = This is $BASH_SOURCE line without quotes
|
||||
Loading…
Add table
Add a link
Reference in a new issue