8000 cosmetic update · coderofsalvation/powscript@c710383 · GitHub
[go: up one dir, main page]

Skip to content

Commit c710383

Browse files
cosmetic update
1 parent 50f36ef commit c710383

File tree

6 files changed

+43
-17
lines changed

6 files changed

+43
-17
lines changed

README.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ Put this line in your `.inputrc`:
4949

5050
Then hitting ctrl-p in your console will enter powscript mode:
5151

52-
hit ctrl-c to exit powscript, type 'edit' launch editor, and 'help' for help
52+
hit ctrl-c to exit powscript, type 'edit' to launch editor, and 'help' for help
5353
> each(line)
5454
> echo line=$line
5555
> run()
@@ -59,6 +59,14 @@ Then hitting ctrl-p in your console will enter powscript mode:
5959
line=2,foo2,bar2,flop2
6060
>
6161

62+
## Live expansion inside editor
63+
64+
> HINT: use live expansion inside vim.
65+
> Put the lines below in .vimrc and hit 'p>' in normal/visual mode to expand powscript
66+
67+
vmap p> :!PIPE=1 powscript --compile<CR>
68+
nmap p> ggVG:!PIPE=1 powscript --compile<CR>
69+
6270
## Wiki
6371

6472
* [Syntax reference](https://github.com/coderofsalvation/powscript/wiki/Reference)

lang/bash/.transpile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ transpile_if(){
8585
code="${code//< /-lt }"
8686
code="${code//<= /-le }"
8787
code="${code//!= /-ne }"
88-
[[ "$code" =~ (if[ ]) && "$firstvar" =~ ^([\"\$]) ]] && code="${code/if /if [[ }"
88+
[[ "$code" =~ (if[ ]) && "$firstvar" =~ ^([\"\$-]) ]] && code="${code/if /if [[ }"
8989
code="${code/match /=~ }"
9090
[[ "$code" =~ "[[" ]] && code="$code ]]"
9191
code="$code; then"

lang/bash/.util

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@ footer["async"]="
55
"
66

77
footer["tmpfile"]="
8-
touch $tmpfile.flop
98
# cleanup tmp files
10-
for f in /tmp/\$(basename \$0).tmp.$(whoami)*; do rm \$f; done
9+
if ls /tmp/\$(basename \$0).tmp.$(whoami)* &>/dev/null; then
10+
for f in /tmp/\$(basename \$0).tmp.$(whoami)*; do rm \$f; done
11+
fi
12+
"
13+
footer["zero_exit"]="exit 0
1114
"

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "powscript",
3-
"version": "1.0.21",
3+
"version": "1.0.22",
44
"description": "bash dialect transpiler in bash: painless shellscript / indentbased / coffeescript for shellscript / bash for hipsters",
55
"main": "powscript",
66
"directories": {

powscript

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,12 @@ footer["async"]="
2020
"
2121

2222
footer["tmpfile"]="
23-
touch $tmpfile.flop
2423
# cleanup tmp files
25-
for f in /tmp/\$(basename \$0).tmp.$(whoami)*; do rm \$f; done
24+
if ls /tmp/\$(basename \$0).tmp.$(whoami)* &>/dev/null; then
25+
for f in /tmp/\$(basename \$0).tmp.$(whoami)*; do rm \$f; done
26+
fi
27+
"
28+
footer["zero_exit"]="exit 0
2629
"
2730
indent_current=0
2831
indent_last=0
@@ -111,7 +114,7 @@ transpile_if(){
111114
code="${code//< /-lt }"
112115
code="${code//<= /-le }"
113116
code="${code//!= /-ne }"
114-
[[ "$code" =~ (if[ ]) && "$firstvar" =~ ^([\"\$]) ]] && code="${code/if /if [[ }"
117+
[[ "$code" =~ (if[ ]) && "$firstvar" =~ ^([\"\$-]) ]] && code="${code/if /if [[ }"
115118
code="${code/match /=~ }"
116119
[[ "$code" =~ "[[" ]] && code="$code ]]"
117120
code="$code; then"
@@ -313,6 +316,8 @@ empty "$1" && {
313316
powscript --compile <file.powscript>
314317
powscript --interactive
315318
powscript --evaluate <powscript string>
319+
echo <powscript string> | PIPE=1 powscript --compile
320+
echo <powscript string> | PIPE=1 powscript --evaluate
316321
';
317322
}
318323

@@ -384,9 +389,13 @@ transpile_functions(){
384389
}
385390

386391
compile(){
387-
local dir="$(dirname "$1")"; local file="$(basename "$1")"; cd "$dir" &>/dev/null
388-
{ cat_requires "$file" ; echo -e "#\n# application code\n#\n"; cat "$file"; } > $tmpfile
389-
echo -e "$settings"
392+
if [[ -n $PIPE ]]; then
393+
cat - > $tmpfile
394+
else
395+
local dir="$(dirname "$1")"; local file="$(basename "$1")"; cd "$dir" &>/dev/null
396+
{ cat_requires "$file" ; echo -e "#\n# application code\n#\n"; cat "$file"; } > $tmpfile
397+
fi
398+
echo -e "#!/bin/bash\n$settings"
390399
#transpile_functions "$tmpfile"
391400
transpile_sugar "$tmpfile" | grep -v "^#" > $tmpfile.code
392401
transpile_functions $tmpfile.code
@@ -406,7 +415,7 @@ process(){
406415
}
407416

408417
evaluate(){
409-
echo -e "$*" > $tmpfile
418+
[[ -n $PIPE ]] && cat - > $tmpfile || echo -e "$*" > $tmpfile
410419
evalstr_cache="$evalstr_cache\n$*"
411420
[[ -n $DEBUG ]] && echo "$(transpile_sugar $tmpfile)"
412421
eval "$(transpile_sugar $tmpfile)"

src/powscript.bash

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ empty "$1" && {
2121
powscript --compile <file.powscript>
2222
powscript --interactive
2323
powscript --evaluate <powscript string>
24+
echo <powscript string> | PIPE=1 powscript --compile
25+
echo <powscript string> | PIPE=1 powscript --evaluate
2426
';
2527
}
2628

@@ -92,9 +94,13 @@ transpile_functions(){
9294
}
9395

9496
compile(){
95-
local dir="$(dirname "$1")"; local file="$(basename "$1")"; cd "$dir" &>/dev/null
96-
{ cat_requires "$file" ; echo -e "#\n# application code\n#\n"; cat "$file"; } > $tmpfile
97-
echo -e "$settings"
97+
if [[ -n $PIPE ]]; then
98+
cat - > $tmpfile
99+
else
100+
local dir="$(dirname "$1")"; local file="$(basename "$1")"; cd "$dir" &>/dev/null
101+
{ cat_requires "$file" ; echo -e "#\n# application code\n#\n"; cat "$file"; } > $tmpfile
102+
fi
103+
echo -e "#!/bin/bash\n$settings"
98104
#transpile_functions "$tmpfile"
99105
transpile_sugar "$tmpfile" | grep -v "^#" > $tmpfile.code
100106
transpile_functions $tmpfile.code
@@ -114,7 +120,7 @@ process(){
114120
}
115121

116122
evaluate(){
117-
echo -e "$*" > $tmpfile
123+
[[ -n $PIPE ]] && cat - > $tmpfile || echo -e "$*" > $tmpfile
118124
evalstr_cache="$evalstr_cache\n$*"
119125
[[ -n $DEBUG ]] && echo "$(transpile_sugar $tmpfile)"
120126
eval "$(transpile_sugar $tmpfile)"
@@ -202,7 +208,7 @@ help(){
202208
}
203209

204210
console(){
205-
[[ ! $1 == "1" ]] && echo "hit ctrl-c to exit powscript, type 'edit' launch editor, and 'help' for help"
211+
[[ ! $1 == "1" ]] && echo "hit ctrl-c to exit powscript, type 'edit' to launch editor, and 'help' for help"
206212
trap 'console 1' 0 1 2 3 13 15 # EXIT HUP INT QUIT PIPE TERM SIGTERM SIGHUP
207213
while IFS="" read -r -e -d $'\n' -p "> " line; do
208214
"$1" "$line"

0 commit comments

Comments
 (0)
0