// http://akelpad.sourceforge.net/forum/viewtopic.php?p=9926#9926
// http://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

//// 按配置的格式复制路径

// 用法:
//   -"复制完整路径"           Call("Scripts::Main", 1, "copyPath.js", `"%f"`)
// 或带模板:
//   -"复制完整路径"           Call("Scripts::Main", 1, "copyPath.js", `"%f" "<path>/<file>.<ext>"`)
//   -"复制文件所在文件夹"     Call("Scripts::Main", 1, "copyPath.js", `"%f" "<path>"`)
//   -"复制文件名"             Call("Scripts::Main", 1, "copyPath.js", `"%f" "<file>.<ext>"`)
//   -"复制文件名（无扩展名）" 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);
}