aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Tom Willemse2013-05-30 02:19:17 +0200
committerGravatar Tom Willemse2013-05-30 02:19:17 +0200
commitdc842516b0388548442f93aa31d529a02ed2b76c (patch)
treebd09f8cacc4edb650b75cdd97d4e1609810d1a0a
parent8f1fd300b3023074776791794f451af77d6059e2 (diff)
downloadcdispass-dc842516b0388548442f93aa31d529a02ed2b76c.tar.gz
cdispass-dc842516b0388548442f93aa31d529a02ed2b76c.zip
Add auto-completion for labels
-rw-r--r--cdispass.js37
1 files changed, 36 insertions, 1 deletions
diff --git a/cdispass.js b/cdispass.js
index c7efc7e..62e8ee9 100644
--- a/cdispass.js
+++ b/cdispass.js
@@ -53,8 +53,43 @@ function dispass(label, password)
yield co_return(data);
}
+function dispass_complete(input, pos, conservative)
+{
+ if (pos == 0 && conservative)
+ yield co_return(undefined);
+
+ let str = input.substring(0, pos);
+
+ var data = "", error = "", ret = [];
+ var result = yield shell_command(
+ dispass_executable + " list --script",
+ $fds = [{ output: async_binary_string_writer("") },
+ { input: async_binary_reader(
+ function (s) data += s || "" ) },
+ { input: async_binary_reader(
+ function (s) error += s || "") }]);
+
+ if (result != 0 || error != "")
+ throw new Error("result: " + result + ", error: " + error);
+ else if (data != "") {
+ data.split('\n').forEach(function (row) {
+ let match = /(^.{50})/.exec(row);
+ if (match && (str == "" || match[1].contains(str)))
+ ret.push(match[1].trim());
+ });
+
+ let c = { count: ret.length,
+ get_string: function (i) ret[i],
+ get_description: function (i) "",
+ get_input_state: function (i) [ret[i]] };
+ yield co_return(c);
+ }
+}
+
function dispass_interactive(I) {
- let label = yield I.minibuffer.read($prompt="label:");
+ let label = yield I.minibuffer.read($prompt="label:",
+ $auto_complete=true,
+ $completer=dispass_complete);
I.minibuffer.input_element.type = "password";
let password = yield I.minibuffer.read(