Hey, @angoll!
Thanks for heavy lifting. I was looking for such integration for quite some time. There was no time to create it by myself from scratch.
However, I changed a few things and now it suits me better. I did not create pull request because I am not sure my functionality is in accordance of your workflow.
My KeePass database is big and contains hundreds of entries. Thus, I cannot afford list all entries. Instead, I change it to use "locate" command instead of "ls" for keepassxc-cli. Also, added some bells and whistles:
fixed issue with spaces in entry names
filtered out Recycle bin entries
removed leading slash for display clarity
replaced slashes with arrows to show folder names more clearly
Here's how it looks for me now:
Here's modified script:
query="{query}"
IFS=$'\n'
export PATH='/usr/local/bin/:/usr/bin'
if [[ -z ${database} ]] || [[ -z ${keychain} ]];
then
echo "{\"items\": [{\"title\":\"Not configured, please run: kpassinit\"}]}";
else
keys=( $(security find-generic-password -a $(id -un) -c 'kpas' -C 'kpas' -s "AlfredWorkflow" -w "${keychain}" |\
keepassxc-cli locate -q "$database" "$query" | grep -Ev "\/Recycle Bin\/") )
if [ $? -eq 0 ]; then
echo -n '{"items": ['
first=
for entry in ${keys[@]}; do
if [ $first ] ; then echo -n ","; fi
title=${entry/\//}
title=${title//\// ➜ }
echo -n "{\"uid\":\"${entry}\",\"title\":\"${title}\",\"arg\":\"${entry}\",\"autocomplete\":\"${entry}\",\"icon\":{\"type\":\"png\",\"path\":\"${PWD}/icon.png\"}}";
first=false
done
echo ']}'
else
echo -n "{\"items\": [{\"title\":\"Error listing database, please check config\"}]}"
fi
fi
And there are still two issues:
keepassxc-cli was not on PATH and I created symlink to /usr/local/bin folder for it to be visible
workflow fails if I enter nothing for time out period or search result is empty. Will try to deal with this later