-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathcopyPath.js
44 lines (40 loc) · 1.53 KB
/
copyPath.js
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
// https://akelpad.sourceforge.net/forum/viewtopic.php?p=9926#p9926
// https://infocatcher.ucoz.net/js/akelpad_scripts/copyPath.js
// https://github.com/Infocatcher/AkelPad_scripts/blob/master/copyPath.js
// (c) Infocatcher 2010, 2014
// Version: 0.1.0.1 - 2014-07-30
// Author: Infocatcher
//// Copy path to file in configurable format
// Usage:
// -"Copy path to file" Call("Scripts::Main", 1, "copyPath.js", `"%f"`)
// Or with template:
// -"Copy path to file" Call("Scripts::Main", 1, "copyPath.js", `"%f" "<path>/<file>.<ext>"`)
// -"Copy path to file directory" Call("Scripts::Main", 1, "copyPath.js", `"%f" "<path>"`)
// -"Copy file name" Call("Scripts::Main", 1, "copyPath.js", `"%f" "<file>.<ext>"`)
// -"Copy file name without extension" Call("Scripts::Main", 1, "copyPath.js", `"%f" "<file>"`)
var argsCount = WScript.Arguments.length;
var arg = argsCount
? WScript.Arguments(0)
: AkelPad.GetEditFile(0);
if(arg) {
if(argsCount > 1) {
var path = arg, sep = "", file = "", dot ="", ext = "";
if(/([\\/])?([^\\/]*)$/.test(path)) {
sep = RegExp.$1;
file = RegExp.$2;
path = path.substring(0, path.length - RegExp.lastMatch.length);
if(/\.([^.]+)$/.test(file)) {
dot = ".";
ext = RegExp.$1;
file = file.substring(0, file.length - RegExp.lastMatch.length);
}
}
arg = WScript.Arguments(1)
.replace("<path>", path)
.replace("/", sep)
.replace("<file>", file)
.replace(".", dot)
.replace("<ext>", ext);
}
AkelPad.SetClipboardText(arg);
}