Skip to content

Commit

Permalink
Merge pull request #39 from jzsfkzm/master
Browse files Browse the repository at this point in the history
A shot at #35
  • Loading branch information
golbin committed Aug 12, 2015
2 parents 4c01f80 + 438187d commit 56e7a77
Show file tree
Hide file tree
Showing 24 changed files with 734 additions and 525 deletions.
33 changes: 33 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,39 @@ the **core.quotepath** option using following command:
$ git config --global core.quotepath false
```

# Key Configuration

We have two key sets _vi_ and _mc_ preconfigured. The default one is _vi_.

##### Using the mc key set

You will need to place a file at `~/.config/git-commander/config.json` with the following content:

```
{
"keySet": "mc"
}
```

##### Redefining keys one by one

You also can redefine keys one by one if you would like. You'll need to extend your `~/.config/git-commander/config.json` file with a key called `keys` and put all your key definitions there. For example if you would like to use the _mc_ key set and make key _x_ quit the application, you'll need to add the following:

```
{
"keySet": "mc",
"keys": {
"common": {
"quit": [
"x"
]
}
}
}
```

You can find [default settings here](https://github.com/golbin/git-commander/tree/master/config/key).

# License

MIT
26 changes: 26 additions & 0 deletions config/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
var _ = require('lodash');

var defaultConfig = {
keySet: 'vi'
};

var config = (function() {
var fs = require('fs');

var retval = defaultConfig;
var userHome = process.env[(process.platform == 'win32') ? 'USERPROFILE' : 'HOME'];
var configFileName = userHome + '/.config/git-commander/config.json';

if (configFileName && fs.existsSync(configFileName)) {
retval = _.extend({}, defaultConfig, JSON.parse(fs.readFileSync(configFileName)));
}

return retval;
}());


var keyConfig = require('./key/' + config.keySet + '.json');

module.exports = {
keys: config.keys ? _.merge({}, keyConfig, config.keys) : keyConfig
};
65 changes: 65 additions & 0 deletions config/key/mc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
{
"common": {
"quit": [
"escape",
"q"
],
"pageUp": [
"pageup"
],
"pageDown": [
"pagedown"
]
},
"main": {
"select": [
"space"
],
"selectAll": [
"enter"
],
"add": [
"a"
],
"reset": [
"r"
],
"commit": [
"c"
],
"log": [
"l"
],
"diff": [
"d"
],
"showBranch": [
"b"
],
"togglePanes": [
"tab"
],
"leftPane": [
"left"
],
"rightPane": [
"right"
]
},
"editor": {
"save": [
"C-s"
]
},
"branch": {
"checkOut": [
"enter"
],
"delete": [
"d"
],
"add": [
"a"
]
}
}
65 changes: 65 additions & 0 deletions config/key/vi.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
{
"common": {
"quit": [
"escape",
"q"
],
"pageUp": [
"C-b"
],
"pageDown": [
"C-f"
]
},
"main": {
"select": [
"space"
],
"selectAll": [
"enter"
],
"add": [
"C-a"
],
"reset": [
"C-r"
],
"commit": [
"C-c"
],
"log": [
"C-l"
],
"diff": [
"C-d"
],
"showBranch": [
"C-b"
],
"togglePanes": [
"tab"
],
"leftPane": [
"left"
],
"rightPane": [
"right"
]
},
"editor": {
"save": [
"C-s"
]
},
"branch": {
"checkOut": [
"enter"
],
"delete": [
"C-d"
],
"add": [
"C-a"
]
}
}
9 changes: 5 additions & 4 deletions controller/branch.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
var _ = require('lodash');

var BranchView = require('../view/branch');
var config = require('../config');

var parent = null,
view = null;
Expand Down Expand Up @@ -36,7 +37,7 @@ var branch = {

view = BranchView(parent.screen);

view.list.key(['enter'], function () {
view.list.key(config.keys.branch.checkOut, function () {
try {
parent.git.checkout(this.selected);
branch.hide(true);
Expand All @@ -46,7 +47,7 @@ var branch = {
}
});

view.list.key(['C-d'], function () {
view.list.key(config.keys.branch.delete, function () {
try {
parent.git.delBranch(this.selected);
branch.show();
Expand All @@ -56,7 +57,7 @@ var branch = {
}
});

view.list.key(['C-a'], function () {
view.list.key(config.keys.branch.add, function () {
view.prompt.input('Input the new branch name', '', function (err, value) {
try {
parent.git.addBranch(value);
Expand All @@ -68,7 +69,7 @@ var branch = {
});
});

view.list.key(['escape'], function () {
view.list.key(config.keys.common.quit, function () {
branch.hide();
});
}
Expand Down
21 changes: 16 additions & 5 deletions controller/diff.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
var DiffView = require('../view/diff');
var config = require('../config');

var parent = null,
view = null;

var diff = {
colorFormat: function (diffText) {
return diffText
.replace(/(^\-\s[\S\s]+?$)/gm, "{red-fg}$1{/red-fg}")
.replace(/(^\+\s[\S\s]+?$)/gm, "{green-fg}$1{/green-fg}")
.replace(/(^@@\s[\S\s]+?@@)/gm, "{cyan-fg}$1{/cyan-fg}");
.replace(/(^\-.*$)/gm, "{red-fg}$1{/red-fg}")
.replace(/(^\+.*$)/gm, "{green-fg}$1{/green-fg}")
.replace(/(^@@.*$)/gm, "{cyan-fg}$1{/cyan-fg}");
},
show: function () {
var diffText = parent.git.diff(
Expand All @@ -34,8 +35,18 @@ var diff = {

view = DiffView(parent.screen);

view.textarea.key(['escape', 'q'], function () {
diff.hide();
view.textarea.key(config.keys.common.quit, function () {
diff.hide();
});

view.textarea.key(config.keys.common.pageUp, function () {
view.textarea.scroll(-view.textarea.height || -1);
redraw();
});

view.textarea.key(config.keys.common.pageDown, function () {
view.textarea.scroll(view.textarea.height || 1);
redraw();
});
}
};
Expand Down
5 changes: 3 additions & 2 deletions controller/editor.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
var EditorView = require('../view/editor');
var config = require('../config');

var parent = null,
view = null;
Expand All @@ -22,15 +23,15 @@ var editor = {

view = EditorView(parent.screen);

view.textarea.key(['C-s'], function () {
view.textarea.key(config.keys.editor.save, function () {
var message = view.textarea.getValue();

parent.git.commit(message);

editor.hide(true);
});

view.textarea.key(['escape'], function () {
view.textarea.key(config.keys.common.quit, function () {
editor.hide();
});
}
Expand Down
18 changes: 15 additions & 3 deletions controller/log.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
var LogView = require('../view/log');
var config = require('../config');

var parent = null,
view = null;
Expand Down Expand Up @@ -88,7 +89,7 @@ var log = {

view = LogView(parent.screen);

view.list.key(['C-r'], function () {
view.list.key(config.keys.main.reset, function () {
var item = logItems[view.list.selected];

view.confirm.ask("Are you sure to reset? (Y/N)\n", function (err, value) {
Expand All @@ -102,13 +103,24 @@ var log = {
});
});

view.list.key(['escape', 'q'], function () {
view.list.key(config.keys.common.quit, function () {
log.hide();
});

view.confirm.key(['escape'], function () {
view.list.key(config.keys.common.pageUp, function () {
view.list.scroll(-view.list.height || -1);
redraw();
});

view.list.key(config.keys.common.pageDown, function () {
view.list.scroll(view.list.height || 1);
redraw();
});

view.confirm.key(config.keys.common.quit, function () {
view.confirm.hide();
});

}
};

Expand Down
Loading

0 comments on commit 56e7a77

Please sign in to comment.