Skip to content

Instantly share code, notes, and snippets.

@wlt
Last active December 17, 2015 16:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wlt/5636622 to your computer and use it in GitHub Desktop.
Save wlt/5636622 to your computer and use it in GitHub Desktop.
Vimperator 3.7.1 に、、:sourceコマンドがWindowsのショートカットファイルの参照先ファイルを読み込む機能を追加するパッチ
diff -r 78a478c41da9 common/content/io.js
--- a/common/content/io.js Wed May 22 20:37:00 2013 +0200
+++ b/common/content/io.js Thu May 23 23:10:04 2013 +0900
@@ -19,15 +19,19 @@
plugins.contexts[file.path] = this;
this.NAME = file.leafName.replace(/\..*/, "").replace(/-([a-z])/g, function (m, n1) n1.toUpperCase());
this.PATH = file.path;
+ this.TARGET = file.getTarget();
this.toString = this.toString;
this.__context__ = this;
this.__proto__ = plugins;
// This belongs elsewhere
+ let tmpFollowLinks = file.followLinks;
+ file.followLinks = false;
for (let dir of io.getRuntimeDirectories("plugin")) {
if (dir.contains(file, false))
plugins[this.NAME] = this;
}
+ file.followLinks = tmpFollowLinks;
return this;
}
});
@@ -59,6 +63,7 @@
else
file.initWithPath(expandedPath);
}
+ file.followLinks = true;
let self = XPCNativeWrapper(file);
self.__proto__ = File.prototype;
return self;
@@ -185,7 +190,9 @@
ofstream.close();
}
return true;
- }
+ },
+
+ getTarget: function () this.isSymlink() ? this.target : this.path
}, {
/**
* @property {number} Open for reading only.
@@ -628,10 +635,10 @@
// liberator.echomsg("Sourcing \"" + filename + "\" ...");
let str = file.read();
- let uri = services.get("io").newFileURI(file);
+ let uri = services.get("io").newFileURI(File(file.getTarget()));
// handle pure JavaScript files specially
- if (/\.js$/.test(filename)) {
+ if (/\.js$/.test(file.getTarget())) {
try {
// Workaround for SubscriptLoader caching.
let suffix = '?' + encodeURIComponent(services.get("UUID").generateUUID().toString());
@@ -647,7 +654,7 @@
throw err;
}
}
- else if (/\.css$/.test(filename))
+ else if (/\.css$/.test(file.getTarget()))
storage.styles.registerSheet(uri.spec, false, true);
else {
let heredoc = "";
diff -r 78a478c41da9 common/content/liberator.js
--- a/common/content/liberator.js Wed May 22 20:37:00 2013 +0200
+++ b/common/content/liberator.js Thu May 23 23:10:04 2013 +0900
@@ -653,7 +653,7 @@
liberator.log("Sourcing plugin directory: " + dir.path + "...");
dir.readDirectory(true).forEach(function (file) {
- if (file.isFile() && /\.(js|vimp)$/i.test(file.path) && !(file.path in liberator.pluginFiles)) {
+ if (file.isFile() && /\.(js|vimp)$/i.test(file.getTarget()) && !(file.path in liberator.pluginFiles)) {
try {
io.source(file.path, false);
liberator.pluginFiles[file.path] = true;
Unix-likeなOS上で、シンボリックリンクでgit cloneしたプラギンを参照するのと同じように、Windowsでもショートカットファイルを使えるようになります。
ショートカットフォルダは扱えません。
■ dir.contains()を呼ぶ前にfile.followLinksをfalseにしてる理由
メソッドnsIFile.contains()は、引数に渡されたsIFileインスタンスのプロパティfollowLinksがtrueで、それがショートカットファイルの場合、ショートカットによって参照するファイルがcontainされているのかを検査する。
ここでは、Unix-likeなOS上でシンボリックリンクファイルを読み込んだ時と同じ挙動にしたく、pluginフォルダにショートカットファイルが入っていればtrueを返して欲しいので、これは望まない動作である。
引数に与えるnsIFileインスタンスのfollowLinksの値を一時的にfalseにすることでこれを回避している。
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment