From 96da60ce3cb7dfe1a82f7d706dc07d9f1325b5f4 Mon Sep 17 00:00:00 2001 From: jonathan poelen Date: Sun, 12 Jun 2016 02:43:57 +0200 Subject: [PATCH] fixes #1: build5.sh fails with cursor.js and cpp.js --- 4to5.sh | 30 +++++++++++++++++++++++++ README.md | 23 +++++++++++++------ build.sh | 4 ++-- build5.sh | 56 ---------------------------------------------- commands/cpp.js | 1 - commands/cursor.js | 1 - 6 files changed, 48 insertions(+), 67 deletions(-) create mode 100755 4to5.sh delete mode 100755 build5.sh diff --git a/4to5.sh b/4to5.sh new file mode 100755 index 0000000..767ba7a --- /dev/null +++ b/4to5.sh @@ -0,0 +1,30 @@ +#!/bin/bash + +[ $# -ne 1 ] && echo $0 command-file >&2 && exit 1 + +functions=`sed -E '/^ \* functions:/!d;s/^ \* functions:(.*)/\1/' "$@" | sed ':a;N;s/\n/,/;ta;'` +functions="${functions// /}" + +actions="$(sed -E '/^function action/,/^}/!d; +/^function/d;/^}/d; +/^\{/d; +/return \{|icon: ""/d; +s/if \(["'\''](.*)["'\''].*/{ "function": "\1",/g; +s/category: ""/"category": "Editing"/g; +s/category: /"category": /g; +s/interactive: /"interactive": /g; +s/text: i18n\("(.*)"\)/"name": "\1"/g; +s/text: i18n\('\''(.*)'\''\)/"name": "\1"/g; +s/shortcut: /"shortcut": /g; +s/};/},/g' "$@")" + +echo 'var katescript = { + "author": "Jonathan Poelen ", + "license": "LGPL", + "revision": '$(sed '/revision/{!d;s/ *\* *revision: //;q};d' "$@")', + "kate-version": "5.1", + "functions": ["'${functions//,/\", \"}'"]' + [ ! -z "$actions" ] && echo " ,\"actions\": [${actions:0:-1}]" +echo '};' + +sed '1,/\*\//{d;q};/^function action/,/^}/d;' "$@" diff --git a/README.md b/README.md index e24adbc..2f9dab7 100644 --- a/README.md +++ b/README.md @@ -17,24 +17,33 @@ Install ## KDE 5: -/!\ _ATTENTION_: headers files are incompatible. Use `build5.sh` or see `help:/katepart/dev-scripting.html#dev-scripting-command-line`. - -Copy `libraries/` and `commands/` in the local home folder $XDG_DATA_HOME/katepart5/script/. Therein, the environment variable XDG_DATA_HOME typically expands to either ~/.local or ~/.local/share +```sh +scriptdir="${XDG_DATA_HOME=~/.local/share}/katepart5/script/" +tmpdir="${TMPDIR=/tmp}/katepart-script-$$" +mkdir -p "$tmpdir/commands" "$scriptdir/commands" && +cp -ri libraries/ "$scriptdir" && +for f in commands/* ; do ./4to5.sh "$f" > "$tmpdir/$f" ; done && +mv -i "$tmpdir/commands"/* "$scriptdir/commands" +``` -Or merge commands into one file with `build5.sh`: +Or merge commands into one file: ```sh cd commands -../build5.sh *.js > "$XDG_DATA_HOME"/katepart5/script/commands/katepartscript.kfs5.js +jsfile="${TMPDIR=/tmp}"/katepartscript.kfs4.js +../build.sh *.js > "$jsfile" && \ +../4to5.sh "$jsfile" > "${XDG_DATA_HOME=~/.local/share}"/katepart5/script/commands/katepartscript.kfs5.js ``` ## KDE 4: -Copy the files inside `libraries/` in `$KDEHOME/.kde/share/apps/katepart/script/libraries` and `commands/` in `$KDEHOME/.kde/share/apps/katepart/script/commands` +```sh +cp -ri libraries/ commands/ "${KDEHOME=~}"/.kde/share/apps/katepart/script/ +``` Or merge commands into one file with `build.sh`: ```sh cd commands -../build.sh *.js > "$KDEHOME"/.kde/share/app/katepart/script/commands/katepartscript.kfs4.js +../build.sh *.js > "${KDEHOME=~}"/.kde/share/app/katepart/script/commands/katepartscript.kfs4.js ``` diff --git a/build.sh b/build.sh index 2145b6c..1de3e0e 100755 --- a/build.sh +++ b/build.sh @@ -6,7 +6,7 @@ p=`dirname $0` libs=`sed -E '/^require/!d;/"range.js"|"cursor.js"/d;s/^require\("(.*)"\);?/\1/' "$@" | sort -u` -functions=`sed -E '/^ \* functions:/!d;s/^ \* functions:(.*)/\1/' "$@" | sed :a';/$/N;s/\n/, /;ta'` +functions=`sed -E '/^ \* functions:/!d;s/^ \* functions:(.*)/\1/' "$@" | sed ':a;N;s/\n/, /;ta'` if [ ! -z "$libs" ] ; then cd "$p"/libraries @@ -36,7 +36,7 @@ if [ ! -z "$libs" ] ; then grep -vh '^require' $libs ; cd - > /dev/null ; fi -sed '/^\/\*/d;/^ \*/d;/^require/d;/^function action/,/^}/d;/^function help/,/^}/d' "$@" ; +sed -s '1,/\*\//d;/^require/d;/^function action/,/^}/d;/^function help/,/^}/d' "$@" ; echo 'function help(cmd){' ; sed '/^function help/,/^}/!d;/^function/d;/^}/d;/^{/d' "$@" ; echo '} diff --git a/build5.sh b/build5.sh deleted file mode 100755 index ef38381..0000000 --- a/build5.sh +++ /dev/null @@ -1,56 +0,0 @@ -#!/bin/bash - -[ $# == 0 ] && echo $0 command-file... >&2 && exit 1 - -p=`dirname $0` - -libs=`sed -E '/^require/!d;/"range.js"|"cursor.js"/d;s/^require\("(.*)"\);?/\1/' "$@" | sort -u` - -functions=`sed -E '/^ \* functions:/!d;s/^ \* functions:(.*)/\1/' "$@" | sed :a';/$/N;s/\n/, /;ta'` -functions="${functions// /}" - -if [ ! -z "$libs" ] ; then - cd "$p"/libraries - libs=`{ echo "$libs" ; sed -E '/^require/!d;/"range.js"|"cursor.js"/d;s/^require\("(.*)"\);?/\1/' $libs ; } | sort -u` - [[ $libs=~'forEach\.js' ]] && contains_foreach=1 - [[ $libs=~'position\.js' ]] && contains_position=1 - ( [ ! -z "$contains_foreach" ] || [ ! -z "$contains_position" ] ) && libs=`{ [ ! -z "$contains_foreach" ] && echo 'forEach.js' ; [ ! -z "$contains_position" ] && echo 'position.js' ; grep -vE 'forEach\.js|position\.js' <<< "$libs" ; }` - cd - > /dev/null -fi - -actions="$(sed -E '/^function action/,/^}/!d; -/^function/d;/^}/d; -/^\{/d; -/return \{|icon: ""/d; -s/if \(["'\''](.*)["'\''].*/{ "function": "\1",/g; -s/category: ""/"category": "Editing"/g; -s/category: "(.*)"/"category": "\1"/g; -s/interactive: (.*),/"interactive": "\1",/g; -s/text: i18n\("(.*)"\)/"name": "\1"/g; -s/shortcut: /"shortcut": /g; -s/};/},/g' "$@")" - -typeset -i revision=$(cat "$p"/revision.txt 2> /dev/null) -echo $(( ++revision )) > "$p"/revision.txt - -echo 'var katescript = { - "author": "Jonathan Poelen ", - "license": "LGPL", - "revision": '$revision', - "kate-version": "5.1", - "functions": ["'${functions//,/\", \"}'"]' - [ ! -z "$actions" ] && echo " ,\"actions\": [${actions:0:-1}]" -echo '}; - -require("range.js") - -' ; -if [ ! -z "$libs" ] ; then - cd "$p"/libraries ; - grep -vh '^require' $libs ; - cd - > /dev/null ; -fi -sed '/^\/\*/d;/^ \*/d;/^require/d;/^function action/,/^}/d;/^function help/,/^}/d' "$@" ; -echo 'function help(cmd){' ; -sed '/^function help/,/^}/!d;/^function/d;/^}/d;/^{/d' "$@" ; -echo '}' ; diff --git a/commands/cpp.js b/commands/cpp.js index 115e400..6897f33 100644 --- a/commands/cpp.js +++ b/commands/cpp.js @@ -9,7 +9,6 @@ require("cursor.js") -///* /*var inserted = [ ['ñ', 'noexcept', 'noexcept '], ['ë', 'const_ref', 'const & '], diff --git a/commands/cursor.js b/commands/cursor.js index 891e680..50a68d1 100644 --- a/commands/cursor.js +++ b/commands/cursor.js @@ -14,7 +14,6 @@ function action(cmd) if ("cursor" === cmd) return { category: "Navigation", - interactive: false, text: i18n("Move cursor or create selection"), shortcut: "Ctrl+Alt+M", interactive: true