Skip to content

Instantly share code, notes, and snippets.

@honda0510
Created March 13, 2014 00:32
Show Gist options
  • Save honda0510/9519644 to your computer and use it in GitHub Desktop.
Save honda0510/9519644 to your computer and use it in GitHub Desktop.
WindowsエクスプローラのステータスバーにSVNリポジトリのURLを表示
var wsh_shell = new ActiveXObject('WScript.Shell');
var fso = new ActiveXObject('Scripting.FileSystemObject');
var windows = getWindows();
var temp_path = getTempPath();
var repo_url;
// エクスプローラのステータスバーにリポジトリのURLを表示
for ( var i = 0, n = windows.count, w; i < n; i++ ) {
w = windows(i);
repo_url = getRepoUrl(w.LocationURL);
if (repo_url) {
w.StatusText = repo_url;
}
}
deleteFile(temp_path);
// 開いているエクスプローラをすべて取得
function getWindows() {
var shell_app = new ActiveXObject('Shell.Application');
return shell_app.Windows();
}
// 一時ファイル名をフルパスで取得
function getTempPath() {
return getTempDir() + 'svn.info';
}
// 一時フォルダを取得
function getTempDir() {
var TemporaryFolder = 2;
return fso.GetSpecialFolder(TemporaryFolder) + '\\';
}
// リポジトリのURLを取得
function getRepoUrl(target_dir) {
var target_dir_ = toRepoUrl(target_dir);
var svn_info = getSvnInfo(target_dir_);
var url = svn_info.match(/^URL: .*/m);
return url;
}
// 先頭の「file:///」を削除
function toRepoUrl(url) {
return decodeURI(url.replace(/^file:/, '').replace(/^\/\/\//, ''));
}
// svn infoコマンドの結果を取得
function getSvnInfo(target_dir) {
var command = 'cmd /c svn info "' + target_dir + '" > ' + temp_path;
runCommand(command);
return getText(temp_path);
}
// コマンドラインを実行
function runCommand(command) {
return wsh_shell.Run(command, 0, true);
}
// ファイルの内容を取得
function getText(path) {
var file, content = '';
try {
file = fso.OpenTextFile(path);
content = file.ReadAll();
} catch(e) {
;
} finally {
if (file) {
file.Close();
}
}
return content;
}
// ファイルを削除
function deleteFile(path) {
try {
fso.DeleteFile(temp_path);
} catch(e) {
;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment