I removed the tabs right before the sed call. The end of the lines were not removed when there was a comment afterwards: the last sed substitution is for that. Finally I was assuming the keys would be defined at most once per file but "ghacks" makes jokes with several definitions of a same "_user.js.parrot" key: I now just keep one of the definitions.

Here is the fixed script:
#!/bin/sh
if [ -z "$1" ]
then
    printf "Usage: $0 prefs1.js ...
"
    exit
fi
printf '# key'
TMP=`mktemp -dt all_prefs.XXXXXX`
trap "rm -r $TMP 2>/dev/null" 0
keys=$TMP/$(seq -s " $TMP/" $#)
values=$TMP/$(seq -s ".val $TMP/" $#).val
mkfifo $TMP/keys $keys $values
# List, in alphabetic order, all keys in at least one input file
grep '^ *user_pref *( *"' "$@" | cut -d \" -f 2 | sort -u | tee $keys > $TMP/keys &
for k in $keys
do
    printf "\t$1"
    # List the value in "$1" associated to every key or "undef"
grep '^ *user_pref *( *"' "$1" | cut -d \" -f 2- | tr -d "$(printf \\t)" | sed -e 's/" *, */'"$(printf \\t)"/ -e 's/ *) *; *$//' -e 's, *) *; *//.*$,,' | sort -ut "$(printf \\t)" -k 1,1 | join -t "$(printf \\t)" -a 1 -e undef -o 2.2 $k - > $k.val &
    shift
done
printf '
'
paste $TMP/keys $values
Its output when given the four user.js files that https://github.com/jm42/compare-user.js considers is attached.

That's very nice of you but perhaps it would be better to refactor it so that it is self explanatory (comments etc).

I added two comments. The script is like 20 lines long. There is not much to refactor.

We could probably make an interface (a form) with default and recommended values and a column in which the user can enter values (or pick from existing). Then a simple 'Submit' button would be able to generate the user.js.

That would be a separate project that could take at input the output of this script (maybe to fill up a database). I will not write any PHP. I can write Shell command lines or AWK programs that process the table the above script outputs.

Reply via email to