1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2025-12-22 22:57:58 +01:00

many bug fixes, :cd and :pwd commands, ~ mapping

This commit is contained in:
Martin Stubenschrott
2007-11-20 00:40:40 +00:00
parent da34b3dc81
commit 678a5657fd
6 changed files with 118 additions and 29 deletions

4
NEWS
View File

@@ -8,6 +8,10 @@
read up the new help for the f, F and ; commands for details read up the new help for the f, F and ; commands for details
removed the following hint options: 'hintchars' 'maxhints' removed the following hint options: 'hintchars' 'maxhints'
added the following hint options: 'hinttimeout' added the following hint options: 'hinttimeout'
* new ~ mapping to open the home directory
* :open tries to open a relative filename now, if you do a :open foo.html
or :open ../hello.txt;
* new :cd and :pwd commands
* new :dialog command to open various firefox dialogs * new :dialog command to open various firefox dialogs
* new a and A mappings to deal with bookmarks * new a and A mappings to deal with bookmarks
* added ]n and ]p to navigate to the next/previous document based on * added ]n and ]p to navigate to the next/previous document based on

View File

@@ -734,6 +734,34 @@ vimperator.Commands = function () //{{{
completer: function (filter) { return [0, vimperator.bookmarks.get(filter)]; } completer: function (filter) { return [0, vimperator.bookmarks.get(filter)]; }
} }
)); ));
commandManager.add(new vimperator.Command(["cd", "chd[ir]"],
function (args)
{
if (!args || vimperator.io.setCurrentDirectory(args))
vimperator.echo(vimperator.io.getCurrentDirectory());
},
{
usage: ["cd [-|path]"],
shortHelp: "Change the current directory",
help: "<code class='command'>:cd -</code> changes to the last directory.",
completer: function (filter) { return vimperator.completion.file(filter, true); }
}
));
commandManager.add(new vimperator.Command(["pwd"],
function (args)
{
if (args)
vimperator.echoerr("E488: Trailing characters");
else
vimperator.echo(vimperator.io.getCurrentDirectory());
},
{
usage: ["cd [-|path]"],
shortHelp: "Change the current directory",
help: "<code class='command'>:cd -</code> changes to the last directory.",
completer: function (filter) { return vimperator.completion.file(filter, true); }
}
));
commandManager.add(new vimperator.Command(["com[mand]"], commandManager.add(new vimperator.Command(["com[mand]"],
function (args) function (args)
{ {
@@ -1477,10 +1505,9 @@ vimperator.Commands = function () //{{{
help: "Multiple URLs can be separated with \", \". Note that the space after the comma is required.<br/>" + help: "Multiple URLs can be separated with \", \". Note that the space after the comma is required.<br/>" +
"Each token is analyzed and in this order:<br/>" + "Each token is analyzed and in this order:<br/>" +
"<ol>" + "<ol>" +
"<li>Transformed to a relative URL of the current location if it starts with . or .. or ...;<br/>" + "<li>Opened as a local file if it is an existing relative or absolute filename. " +
"... is special and moves up the directory hierarchy as far as possible." + "<ul><li><code class=\"command\">:open /etc/fstab</code> shows the file system table.</li>" +
"<ul><li><code class=\"command\">:open ...</code> with current location <code>\"http://www.example.com/dir1/dir2/file.html\"</code> opens <code>\"http://www.example.com\"</code></li>" + "<li><code class=\"command\">:open ../other/foo.html</code> in your home directory opens <code>\"/home/other/foo.html\"</code></li></ul></li>" +
"<li><code class=\"command\">:open ./foo.html</code> with current location <code>\"http://www.example.com/dir1/dir2/file.html\"</code> opens <code>\"http://www.example.com/dir1/dir2/foo.html\"</code></li></ul></li>" +
"<li>Opened with the specified search engine if the token looks like a search string " + "<li>Opened with the specified search engine if the token looks like a search string " +
"and the first word is the name of a search engine (<code class=\"command\">:open wikipedia linus torvalds</code> " + "and the first word is the name of a search engine (<code class=\"command\">:open wikipedia linus torvalds</code> " +
"opens the wikipedia entry for linus torvalds). The short name of a search engine is automatically guessed from its name. " + "opens the wikipedia entry for linus torvalds). The short name of a search engine is automatically guessed from its name. " +

View File

@@ -190,12 +190,12 @@ vimperator.Completion = function () //{{{
{ {
if (cpt[i] == "s") if (cpt[i] == "s")
completions = completions.concat(this.search(filter)[1]); completions = completions.concat(this.search(filter)[1]);
else if (cpt[i] == "f")
completions = completions.concat(this.file(filter, false)[1]);
else if (cpt[i] == "b") else if (cpt[i] == "b")
completions = completions.concat(vimperator.bookmarks.get(filter)); completions = completions.concat(vimperator.bookmarks.get(filter));
else if (cpt[i] == "h") else if (cpt[i] == "h")
completions = completions.concat(vimperator.history.get(filter)); completions = completions.concat(vimperator.history.get(filter));
else if (cpt[i] == "f")
completions = completions.concat(this.file(filter, false)[1]);
} }
return [start, completions]; return [start, completions];
@@ -237,7 +237,7 @@ vimperator.Completion = function () //{{{
{ {
files = vimperator.io.readDirectory(dir); files = vimperator.io.readDirectory(dir);
mapped = files.map(function (file) { mapped = files.map(function (file) {
return [[short ? file.leafName : dir + file.leafName], file.isDirectory() ? "Directory" : "File"]; return [[short ? file.leafName : (dir + file.leafName)], file.isDirectory() ? "Directory" : "File"];
}); });
} }
catch (e) catch (e)
@@ -245,7 +245,10 @@ vimperator.Completion = function () //{{{
return []; return [];
} }
return [short ? dir.length : 0, buildLongestStartingSubstring(mapped, compl)]; if (short)
return [dir.length, buildLongestStartingSubstring(mapped, compl)];
else
return [0, buildLongestStartingSubstring(mapped, filter)];
}, },
help: function (filter) help: function (filter)

View File

@@ -37,6 +37,7 @@ vimperator.IO = function ()//{{{
.getService(Components.interfaces.nsIEnvironment); .getService(Components.interfaces.nsIEnvironment);
const WINDOWS = navigator.platform == "Win32"; const WINDOWS = navigator.platform == "Win32";
var cwd = null, oldcwd = null;
/////////////////////////////////////////////////////////////////////////////}}} /////////////////////////////////////////////////////////////////////////////}}}
////////////////////// PUBLIC SECTION ////////////////////////////////////////// ////////////////////// PUBLIC SECTION //////////////////////////////////////////
@@ -92,6 +93,41 @@ vimperator.IO = function ()//{{{
return path; return path;
}, },
getCurrentDirectory: function ()
{
var dirs = [cwd, "$PWD", "~"];
for (var i = 0; i < dirs.length; i++)
{
if (!dirs[i])
continue;
if (this.getFile(dirs[i]).exists())
return this.expandPath(dirs[i]);
}
},
setCurrentDirectory: function (newdir)
{
if (!newdir)
newdir = "~";
if (newdir == "-")
{
[cwd, oldcwd] = [oldcwd, cwd];
}
else
{
newdir = this.expandPath(newdir);
if (!this.getFile(newdir).isDirectory())
{
vimperator.echoerr("E344: Can't find directory \"" + newdir + "\" in path");
return this.getCurrentDirectory();
}
[cwd, oldcwd] = [newdir, cwd];
}
return this.getCurrentDirectory();
},
getPluginDir: function () getPluginDir: function ()
{ {
var pluginDir; var pluginDir;
@@ -122,6 +158,7 @@ vimperator.IO = function ()//{{{
return null; return null;
}, },
// return a nsILocalFile for path where you can call isDirectory(), etc. on // return a nsILocalFile for path where you can call isDirectory(), etc. on
// caller must check with .exists() if the returned file really exists // caller must check with .exists() if the returned file really exists
// also expands relative paths // also expands relative paths
@@ -130,10 +167,12 @@ vimperator.IO = function ()//{{{
var file = Components.classes["@mozilla.org/file/local;1"]. var file = Components.classes["@mozilla.org/file/local;1"].
createInstance(Components.interfaces.nsILocalFile); createInstance(Components.interfaces.nsILocalFile);
// convert relative to absolute pathnames // convert relative to absolute pathname
path = this.expandPath(path); path = this.expandPath(path);
if (!/^([a-zA-Z]+:|\/)/.test(path)) // starts not with either /, C: or file: if (!/^(file:|[a-zA-Z]:|\/)/.test(path)) // starts not with either /, C: or file:
path = this.expandPath("~") + (WINDOWS ? "\\" : "/") + path; // TODO: for now homedir, later relative to current dir? path = this.getCurrentDirectory() + (WINDOWS ? "\\" : "/") + path; // TODO: for now homedir, later relative to current dir?
else
path = path.replace(/^file:/, "");
file.initWithPath(path); file.initWithPath(path);
return file; return file;

View File

@@ -504,6 +504,13 @@ vimperator.Mappings = function () //{{{
flags: vimperator.Mappings.flags.COUNT flags: vimperator.Mappings.flags.COUNT
} }
)); ));
addDefaultMap(new vimperator.Map([vimperator.modes.NORMAL], ["~"],
function () { vimperator.open("~"); },
{
shortHelp: "Open home directory",
help: "You can also use the hints to create the probably fastest file browser on earth."
}
));
addDefaultMap(new vimperator.Map([vimperator.modes.NORMAL], ["gh"], addDefaultMap(new vimperator.Map([vimperator.modes.NORMAL], ["gh"],
BrowserHome, BrowserHome,
{ {

View File

@@ -104,28 +104,37 @@ vimperator.util = { //{{{
// strip each 'URL' - makes things simpler later on // strip each 'URL' - makes things simpler later on
urls[url] = urls[url].replace(/^\s+/, "").replace(/\s+$/, ""); urls[url] = urls[url].replace(/^\s+/, "").replace(/\s+$/, "");
// FIXME: not really that good (doesn't handle .. in the middle) // first check if it is an existing local file
// check for ./ and ../ (or even .../) to go to a file in the upper directory var file = vimperator.io.getFile(urls[url]);
if (matches = urls[url].match(/^(?:\.$|\.\/(\S*))/)) if (file.exists())
{ {
var tail = matches[1] || ""; urls[url] = file.path;
urls[url] = newURL.replace(/(.+\/)[^\/]*/, "$1" + tail); // NOTE: escape / in character sets so as not to break Vim syntax highlighting
continue;
}
else if (matches = urls[url].match(/^(?:\.\.$|\.\.\/(\S*))/))
{
var tail = matches[1] || "";
urls[url] = newURL.replace(/(.+\/)[^\/]*/, "$1../" + tail);
continue;
}
else if (matches = urls[url].match(/^(?:\.\.\.$|\.\.\.\/(\S*))/))
{
var location = window.content.document.location;
var tail = matches[1] || "";
urls[url] = location.protocol + "//" + location.host + "/" + tail;
continue; continue;
} }
// Disabled for now, use gu and GU or O and change the last part
// // FIXME: not really that good (doesn't handle .. in the middle)
// // check for ./ and ../ (or even .../) to go to a file in the upper directory
// if (matches = urls[url].match(/^(?:\.$|\.\/(\S*))/))
// {
// var tail = matches[1] || "";
// urls[url] = newURL.replace(/(.+\/)[^\/]*/, "$1" + tail); // NOTE: escape / in character sets so as not to break Vim syntax highlighting
// continue;
// }
// else if (matches = urls[url].match(/^(?:\.\.$|\.\.\/(\S*))/))
// {
// var tail = matches[1] || "";
// urls[url] = newURL.replace(/(.+\/)[^\/]*/, "$1../" + tail);
// continue;
// }
// else if (matches = urls[url].match(/^(?:\.\.\.$|\.\.\.\/(\S*))/))
// {
// var location = window.content.document.location;
// var tail = matches[1] || "";
// urls[url] = location.protocol + "//" + location.host + "/" + tail;
// continue;
// }
// if the string doesn't look like a valid URL (i.e. contains a space // if the string doesn't look like a valid URL (i.e. contains a space
// or does not contain any of: .:/) try opening it with a search engine // or does not contain any of: .:/) try opening it with a search engine
// or keyword bookmark // or keyword bookmark