Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 8 additions & 29 deletions command-signatures/json/pass.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
{
Expand Down Expand Up @@ -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",
Expand All @@ -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",
Expand All @@ -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": [
{
Expand Down Expand Up @@ -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"
}
},
{
Expand All @@ -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": [
{
Expand All @@ -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"
}
},
{
Expand Down
2 changes: 2 additions & 0 deletions command-signatures/src/generators/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ mod node;
mod npm;
mod nx;
mod pacman;
mod pass;
mod phpunit_watcher;
mod pip;
mod powershell;
Expand Down Expand Up @@ -74,6 +75,7 @@ pub fn dynamic_command_signature_data() -> HashMap<String, DynamicCompletionData
npm::yarn_generators(),
nx::generator(),
pacman::generator(),
pass::generator(),
phpunit_watcher::generator(),
pip::generator(),
pip::pip3_generator(),
Expand Down
63 changes: 63 additions & 0 deletions command-signatures/src/generators/pass.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
use warp_completion_metadata::{
CommandBuilder, CommandSignatureGenerators, Generator, GeneratorResults,
GeneratorResultsCollector, Suggestion,
};

pub fn generator() -> 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()
}
Loading