-
Notifications
You must be signed in to change notification settings - Fork 0
/
ARB_External.PowerPro
100 lines (80 loc) · 3.54 KB
/
ARB_External.PowerPro
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
;
; ARB v4.0 External Edition
; Written by Alex Peters, 13/6/2005
;
; Allows execution of aliases with parameter passing. Also accepts PowerPro
; commands, programs, folders, documents and Internet resources for execution.
;
; Usage: .ARB()
;
; * In the box that appears, enter the location of a program, folder,
; document or Internet resource and it will be opened.
; * Enter a PowerPro command and it will be executed.
; * Enter an alias, optionally following it with parameters, and it will be
; executed.
; * Potential matches for aliases and past entries will appear in a popup
; underneath the text field. Pressing Tab will alternate through these
; choices.
;
; All feedback is encouraged on the PowerPro discussion list:
; * http://groups.yahoo.com/group/power-pro
; ____________________________________________________________________________
;
; The EXT_PREFIX constant holds the file path prefix that qualifies any script
; within {scriptFolder} as an external ARB alias. A name prefix (e.g. 'ARB_'),
; folder prefix (e.g. 'ARB_Aliases\') or both may be specified. Setting to '-'
; or something your scripts don't start with will disable external aliases.
;
; * The prefix does not form part of the typed alias.
; * Only scripts with the extension '.PowerPro' will be detected.
; * Please ensure that any directories specified already exist before
; executing ARB.
;
local EXT_PREFIX = ?"ARB_Aliases\"
;
; The HISTORY_PATH constant holds the desired location to read/write command
; history entries. Setting to 'NUL' will disable command history.
;
local HISTORY_PATH = pProFolder ++ ?"Data\ARB_History.txt"
; ____________________________________________________________________________
local LF = esc(?"\n", ?"\")
static history, lastEntered
; Scan for external aliases.
local aliases
local aliasPrefix = scriptFolder ++ ?"\" ++ EXT_PREFIX
local scriptFiles = File.listFiles(aliasPrefix ++ ?"*.PowerPro", 1)
for (local i = line(scriptFiles, 0); i > 0; i = i - 1)
aliases = aliases ++ File.name(remove(line(scriptFiles, i), length(aliasPrefix))) ++ LF
endFor
; Load history from disk if not already in memory.
if (history == "" && validPath(HISTORY_PATH))
history = File.readAll(HISTORY_PATH)
; Present the ARB dialogue with the auto-completion vector.
local autoComplete = Vec.createFromLines(aliases ++ history, 1)
local cmd = inputDefault(lastEntered, ?"ARB v4.0", ?"file =autoComplete")
autoComplete = Vec.destroy(autoComplete)
if (not(pProFlag(0)))
quit
lastEntered = cmd
if (cmd == "")
quit
; Is the first word of the command line an alias?
if (index(LF ++ aliases, LF ++ word(cmd, 1) ++ LF)) do
local alias = word(cmd, 1)
; Escape the parameter string into a bracketed evaluatable expression.
local params = remove(cmd, index(cmd, alias) + length(alias))
params = replaceChars(params, ?"\", ?"\\")
params = replaceChars(params, ?'"', ?"\X22")
params = ?'(esc(?"' ++ params ++ ?'", ?"\"))'
cmd = ?"." ++ EXT_PREFIX ++ alias ++ params
else
; It's not an alias if we enter this block. Add the entered information to the
; history (if not a file, which can be easily auto-completed) and run it.
if (not(index(LF ++ history, LF ++ cmd ++ LF)) && not(validPath(cmd))) do
history = history ++ cmd ++ LF
File.writeAll(HISTORY_PATH, cmd ++ LF, ?"a")
EndIf
endIf
; Queue the command to be executed under PowerPro's ownership (and not ARB's).
; This prevents bad commands from throwing an ARB script error.
Event.createMS(1, 1, cmd)