diff --git a/command-signatures/json/pass.json b/command-signatures/json/pass.json index 5e1bc4d0..03c95542 100644 --- a/command-signatures/json/pass.json +++ b/command-signatures/json/pass.json @@ -4,10 +4,7 @@ "args": { "name": "pass-name", "description": "The password you want to show", - "generators": { - "script": "function(){return\"grep -r -l '' $HOME/.password-store --exclude-dir=.git\"}", - "postProcess": "_NuFrRa_s=>s.split(`\n`).map(o=>({name:o.split(\".password-store/\").pop().replace(\".gpg\",\"\"),icon:\"\\u{1F510}\"}))" - } + "generatorName": "entries" }, "options": [ { @@ -102,10 +99,7 @@ { "name": "old-path", "description": "The old password name or directory", - "generators": { - "script": "function(){return\"grep -r -l '' $HOME/.password-store --exclude-dir=.git\"}", - "postProcess": "_NuFrRa_s=>s.split(`\n`).map(o=>({name:o.split(\".password-store/\").pop().replace(\".gpg\",\"\"),icon:\"\\u{1F510}\"}))" - } + "generatorName": "entries" }, { "name": "new-path", @@ -129,10 +123,7 @@ { "name": "old-path", "description": "The old password name or directory", - "generators": { - "script": "function(){return\"grep -r -l '' $HOME/.password-store --exclude-dir=.git\"}", - "postProcess": "_NuFrRa_s=>s.split(`\n`).map(o=>({name:o.split(\".password-store/\").pop().replace(\".gpg\",\"\"),icon:\"\\u{1F510}\"}))" - } + "generatorName": "entries" }, { "name": "new-path", @@ -155,10 +146,7 @@ "args": { "name": "pass-name", "description": "The password name", - "generators": { - "script": "function(){return\"grep -r -l '' $HOME/.password-store --exclude-dir=.git\"}", - "postProcess": "_NuFrRa_s=>s.split(`\n`).map(o=>({name:o.split(\".password-store/\").pop().replace(\".gpg\",\"\"),icon:\"\\u{1F510}\"}))" - } + "generatorName": "entries" }, "options": [ { @@ -229,13 +217,10 @@ ], "description": "List names of passwords inside the tree at subfolder by using the tree", "args": { - "name": "password sub-directory", + "name": "subfolder", "description": "The password sub directory you want to list", "isOptional": true, - "generators": { - "script": "function(){return\"ls -dR1a $HOME/.password-store/*/\"}", - "postProcess": "_NuFrRa_s=>s.split(`\n`).map(o=>({name:o.split(\".password-store/\").pop(),icon:\"\\u{1F4C1}\"}))" - } + "generatorName": "entry_dirs" } }, { @@ -252,10 +237,7 @@ "args": { "name": "pass-name", "description": "The password you want to show", - "generators": { - "script": "function(){return\"grep -r -l '' $HOME/.password-store --exclude-dir=.git\"}", - "postProcess": "_NuFrRa_s=>s.split(`\n`).map(o=>({name:o.split(\".password-store/\").pop().replace(\".gpg\",\"\"),icon:\"\\u{1F510}\"}))" - } + "generatorName": "entries" }, "options": [ { @@ -280,10 +262,7 @@ "args": { "name": "pass-name", "description": "The password you want to edit", - "generators": { - "script": "function(){return\"grep -r -l '' $HOME/.password-store --exclude-dir=.git\"}", - "postProcess": "_NuFrRa_s=>s.split(`\n`).map(o=>({name:o.split(\".password-store/\").pop().replace(\".gpg\",\"\"),icon:\"\\u{1F510}\"}))" - } + "generatorName": "entries" } }, { diff --git a/command-signatures/src/generators/mod.rs b/command-signatures/src/generators/mod.rs index b6100244..5c1b9eb6 100644 --- a/command-signatures/src/generators/mod.rs +++ b/command-signatures/src/generators/mod.rs @@ -35,6 +35,7 @@ mod node; mod npm; mod nx; mod pacman; +mod pass; mod phpunit_watcher; mod pip; mod powershell; @@ -74,6 +75,7 @@ pub fn dynamic_command_signature_data() -> HashMap CommandSignatureGenerators { + CommandSignatureGenerators::new("pass") + .add_generator( + "entries", + Generator::script( + CommandBuilder::single_command( + "sh -c 'p=\"${PASSWORD_STORE_DIR:-$HOME/.password-store}\"; echo \"$p\"; find \"$p\" -name .git -prune -o -name \"*.gpg\" -print 2>/dev/null'", + ), + parse_entries, + ), + ) + .add_generator( + "entry_dirs", + Generator::script( + CommandBuilder::single_command( + "sh -c 'p=\"${PASSWORD_STORE_DIR:-$HOME/.password-store}\"; echo \"$p\"; find \"$p\" -mindepth 1 -name .git -prune -o -type d -print 2>/dev/null'", + ), + parse_entry_dirs, + ), + ) +} + +/// Parses the output of the entries generator command. +/// The first line is the password store prefix; subsequent lines are full paths to `.gpg` files. +fn parse_entries(output: &str) -> GeneratorResults { + let mut lines = output.trim().lines(); + let prefix = match lines.next() { + Some(p) => p, + None => return GeneratorResults::default(), + }; + let prefix_with_slash = format!("{prefix}/"); + lines + .filter(|line| !line.is_empty()) + .filter_map(|line| { + line.strip_prefix(&prefix_with_slash) + .and_then(|entry| entry.strip_suffix(".gpg")) + .map(|entry| Suggestion::with_description(entry, "Password entry")) + }) + .collect_unordered_results() +} + +/// Parses the output of the entry_dirs generator command. +/// The first line is the password store prefix; subsequent lines are full paths to directories. +fn parse_entry_dirs(output: &str) -> GeneratorResults { + let mut lines = output.trim().lines(); + let prefix = match lines.next() { + Some(p) => p, + None => return GeneratorResults::default(), + }; + let prefix_with_slash = format!("{prefix}/"); + lines + .filter(|line| !line.is_empty()) + .filter_map(|line| { + line.strip_prefix(&prefix_with_slash) + .map(|dir| Suggestion::with_description(dir, "Directory")) + }) + .collect_unordered_results() +}