-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Angoll
authored and
Angoll
committed
Oct 24, 2020
1 parent
d4ce47d
commit 5e66b39
Showing
6 changed files
with
111 additions
and
23 deletions.
There are no files selected for viewing
File renamed without changes.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,26 @@ | ||
export PATH='/usr/local/bin/:/usr/bin' | ||
|
||
echo $(security find-generic-password -a $(id -un) -c 'kaiw' -C 'kaiw' -s "KPass_AlfredWorkflow" -w $keychain) |\ | ||
keepassxc-cli show -q -a Password "$database" "$1"; | ||
keePassKeyFile="" | ||
if [[ ! -z ${keyfile} ]]; then | ||
keePassKeyFile="--key-file \"${keyfile}\"" | ||
fi | ||
|
||
function get_keys() { | ||
security find-generic-password -a $(id -un) -c 'kpas' -C 'kpas' -s "${keychainItem}" -w "${keychain}" |\ | ||
keepassxc-cli show -q ${keePassKeyFile} -a Password "$database" "$1" | ||
} | ||
|
||
function get_errorInfo { | ||
exec 3<&1 | ||
security find-generic-password -a $(id -un) -c 'kpas' -C 'kpas' -s "${keychainItem}" -w "${keychain}" 2>&3 |\ | ||
keepassxc-cli ls -R ${keePassKeyFile} -f "$database" 2>&3 | grep -Ev '(/|\[empty\]?)$' | ||
exec 3>&- | ||
} | ||
|
||
|
||
data=$(get_keys $1) | ||
if [ $? -ne 0 ]; then | ||
echo $(get_errorInfo) | ||
else | ||
echo $data | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,49 @@ | ||
query="{query}" | ||
|
||
export PATH='/usr/local/bin/:/usr/bin' | ||
|
||
if [[ -z ${database} ]] || [[ -z ${keychain} ]]; | ||
then | ||
|
||
echo "{\"items\": [{\"title\":\"Not configured, please run: kpassinit\"}]}"; | ||
useKeePassKeyFile="" | ||
if [[ ! -z ${keePassKeyFile} ]]; then | ||
useKeePassKeyFile="--key-file \"${keePassKeyFile}\"" | ||
fi | ||
|
||
function get_keys(){ | ||
local keys | ||
keys=$(security find-generic-password -a $(id -un) -c 'kpas' -C 'kpas' -s "AlfredWorkflow" -w "${keychain}" |\ | ||
keepassxc-cli locate -q "$database" "{query}" | grep -Ev '(/|\[empty\]?)$') | ||
echo "${keys}" | ||
|
||
function get_keys() { | ||
security find-generic-password -a $(id -un) -c 'kpas' -C 'kpas' -s "${keychainItem}" -w "${keychain}" |\ | ||
keepassxc-cli ls -R -q ${useKeePassKeyFile} -f "$database" | grep -Ev '(/|\[empty\]?)$' | ||
} | ||
|
||
function get_errorInfo { | ||
exec 3<&1 | ||
security find-generic-password -a $(id -un) -c 'kpas' -C 'kpas' -s "${keychainItem}" -w "${keychain}" 2>&3 |\ | ||
keepassxc-cli ls -R ${useKeePassKeyFile} -f "$database" 2>&3 | grep -Ev '(/|\[empty\]?)$' | ||
exec 3>&- | ||
} | ||
|
||
keys=$(get_keys) | ||
function build_entry() { | ||
local entry=$1 | ||
#local title=${entry##*/} | ||
local title=${entry} | ||
jq -n --arg entry ${entry} --arg title ${title} --arg iconPath "${PWD}/icon.png" '{"uid": $entry, "title": $title, "subtitle": $entry , "arg": $entry, "autocomplete": $entry, "icon": {"type":"png", "path": $iconPath}}' | ||
} | ||
|
||
if [[ -z ${database} ]] || [[ -z ${keychain} ]]; | ||
then | ||
echo "{\"items\": [{\"title\":\"Not configured, please run: kpassinit\"}]}"; | ||
exit | ||
fi | ||
|
||
keys=($(get_keys)) | ||
if [ $? -ne 0 ]; then | ||
echo -n "{\"items\": [{\"title\":\"Error listing database, please check config\"}]}"; | ||
info=$(get_errorInfo | sed 's/"/\\"/g') | ||
info=${info//$'\n'/} | ||
echo "{\"items\": [{\"title\":\"Error listing database, please check config: Error: ${info}\"}]}"; | ||
exit | ||
fi | ||
|
||
echo "${keys}" | while read entry | ||
do | ||
jq -n --arg uid "${entry}" --arg title "${entry##*/}" --arg subtitle "${entry}" '{"uid": $uid, "title": $title, "subtitle": $subtitle }' | ||
OIFS=$IFS | ||
IFS=$'\n' | ||
keys=($(get_keys)) | ||
for entry in ${keys[@]}; do | ||
build_entry ${entry} | ||
done | jq -c -s '{"items": .}' | ||
IFS=$OIFS |