Skip to content

Commit

Permalink
Rename name to entry
Browse files Browse the repository at this point in the history
  • Loading branch information
sschmid committed May 16, 2024
1 parent 7b28074 commit 67ff7c6
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 43 deletions.
26 changes: 13 additions & 13 deletions src/plugins/keepassxc/plugin.bash
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ ${password}
EOF
}

PW_NAME=""
PW_ENTRY=""
declare -ig PW_FZF=0

pw::init() { _keepassxc-cli db-create -p "${PW_KEYCHAIN}"; }
Expand All @@ -32,18 +32,18 @@ pw::add() {

pw::edit() {
pw::select_entry_with_prompt edit "$@"
_addOrEdit 1 "${PW_NAME}"
_addOrEdit 1 "${PW_ENTRY}"
}

_addOrEdit() {
local -i edit=$1; shift
local name account
name="$1" account="${2:-}"
pw::prompt_password "${name}"
local entry account
entry="$1" account="${2:-}"
pw::prompt_password "${entry}"

if ((edit))
then _keepassxc-cli_with_db_password_and_entry_password "${PW_PASSWORD}" edit -qp "${PW_KEYCHAIN}" "${name}"
else _keepassxc-cli_with_db_password_and_entry_password "${PW_PASSWORD}" add -qp "${PW_KEYCHAIN}" -u "${account}" "${name}"
then _keepassxc-cli_with_db_password_and_entry_password "${PW_PASSWORD}" edit -qp "${PW_KEYCHAIN}" "${entry}"
else _keepassxc-cli_with_db_password_and_entry_password "${PW_PASSWORD}" add -qp "${PW_KEYCHAIN}" -u "${account}" "${entry}"
fi
}

Expand All @@ -54,7 +54,7 @@ pw::get() {
else pw::select_entry_with_prompt copy "$@"
fi
local password
password="$(_keepassxc-cli_with_db_password show -qsa Password "${PW_KEYCHAIN}" "${PW_NAME}")"
password="$(_keepassxc-cli_with_db_password show -qsa Password "${PW_KEYCHAIN}" "${PW_ENTRY}")"
if ((print)); then
echo "${password}"
else
Expand All @@ -66,10 +66,10 @@ pw::rm() {
local -i remove=1
pw::select_entry_with_prompt remove "$@"
if ((PW_FZF)); then
read -rp "Do you really want to remove ${PW_NAME} from ${PW_KEYCHAIN}? (y / n): "
read -rp "Do you really want to remove ${PW_ENTRY} from ${PW_KEYCHAIN}? (y / n): "
[[ "${REPLY}" == "y" ]] || remove=0
fi
((!remove)) || _keepassxc-cli_with_db_password rm -q "${PW_KEYCHAIN}" "${PW_NAME}"
((!remove)) || _keepassxc-cli_with_db_password rm -q "${PW_KEYCHAIN}" "${PW_ENTRY}"
}

pw::list() {
Expand All @@ -82,12 +82,12 @@ pw::select_entry_with_prompt() {
_set_password
local fzf_prompt="$1"; shift
if (($#)); then
PW_NAME="$1"
PW_ENTRY="$1"
PW_FZF=0
else
PW_NAME="$(pw::list | fzf --prompt="${fzf_prompt}> " --layout=reverse --info=hidden \
PW_ENTRY="$(pw::list | fzf --prompt="${fzf_prompt}> " --layout=reverse --info=hidden \
--preview="\"${PW_KEEPASSXC}\" show -q \"${PW_KEYCHAIN}\" {} <<< \"${PW_KEEPASSXC_PASSWORD}\"")"
[[ -n "${PW_NAME}" ]] || exit 1
[[ -n "${PW_ENTRY}" ]] || exit 1
# shellcheck disable=SC2034
PW_FZF=1
fi
Expand Down
30 changes: 15 additions & 15 deletions src/plugins/macos_keychain/plugin.bash
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
PW_NAME=""
PW_ENTRY=""
PW_ACCOUNT=""
declare -ig PW_FZF=0

Expand All @@ -13,18 +13,18 @@ pw::add() {

pw::edit() {
pw::select_entry_with_prompt edit "$@"
_addOrEdit 1 "${PW_NAME}" "${PW_ACCOUNT}"
_addOrEdit 1 "${PW_ENTRY}" "${PW_ACCOUNT}"
}

_addOrEdit() {
local -i edit=$1; shift
local name account
name="$1" account="${2:-}"
pw::prompt_password "${name}"
local entry account
entry="$1" account="${2:-}"
pw::prompt_password "${entry}"

if ((edit))
then security add-generic-password -U -a "${account}" -s "${name}" -w "${PW_PASSWORD}" "${PW_KEYCHAIN}"
else security add-generic-password -a "${account}" -s "${name}" -w "${PW_PASSWORD}" "${PW_KEYCHAIN}"
then security add-generic-password -U -a "${account}" -s "${entry}" -w "${PW_PASSWORD}" "${PW_KEYCHAIN}"
else security add-generic-password -a "${account}" -s "${entry}" -w "${PW_PASSWORD}" "${PW_KEYCHAIN}"
fi
}

Expand All @@ -35,7 +35,7 @@ pw::get() {
else pw::select_entry_with_prompt copy "$@"
fi
local password
password="$(security find-generic-password ${PW_ACCOUNT:+-a "${PW_ACCOUNT}"} -s "${PW_NAME}" -w "${PW_KEYCHAIN}")"
password="$(security find-generic-password ${PW_ACCOUNT:+-a "${PW_ACCOUNT}"} -s "${PW_ENTRY}" -w "${PW_KEYCHAIN}")"
if ((print)); then
echo "${password}"
else
Expand All @@ -47,10 +47,10 @@ pw::rm() {
local -i remove=1
pw::select_entry_with_prompt remove "$@"
if ((PW_FZF)); then
read -rp "Do you really want to remove ${PW_NAME:+"'${PW_NAME}' "}${PW_ACCOUNT:+"'${PW_ACCOUNT}' "}from ${PW_KEYCHAIN}? (y / n): "
read -rp "Do you really want to remove ${PW_ENTRY:+"'${PW_ENTRY}' "}${PW_ACCOUNT:+"'${PW_ACCOUNT}' "}from ${PW_KEYCHAIN}? (y / n): "
[[ "${REPLY}" == "y" ]] || remove=0
fi
((!remove)) || security delete-generic-password -a "${PW_ACCOUNT}" -s "${PW_NAME}" "${PW_KEYCHAIN}" > /dev/null
((!remove)) || security delete-generic-password -a "${PW_ACCOUNT}" -s "${PW_ENTRY}" "${PW_KEYCHAIN}" > /dev/null
}

pw::list() {
Expand All @@ -71,16 +71,16 @@ pw::list() {
pw::select_entry_with_prompt() {
local fzf_prompt="$1"; shift
if (($#)); then
PW_NAME="$1"
PW_ENTRY="$1"
PW_ACCOUNT="${2:-}"
PW_FZF=0
else
local name account
while IFS=$'\t' read -r name account; do
PW_NAME="$(echo "${name}" | xargs)"
local entry account
while IFS=$'\t' read -r entry account; do
PW_ENTRY="$(echo "${entry}" | xargs)"
PW_ACCOUNT="$(echo "${account}" | xargs)"
done < <(pw::list | fzf --prompt="${fzf_prompt}> " --layout=reverse --info=hidden)
[[ -n "${PW_NAME}" && -n "${PW_ACCOUNT}" ]] || exit 1
[[ -n "${PW_ENTRY}" && -n "${PW_ACCOUNT}" ]] || exit 1
# shellcheck disable=SC2034
PW_FZF=1
fi
Expand Down
24 changes: 12 additions & 12 deletions src/plugins/sample/plugin.bash
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# This sample resambles the behavior of the default plugin.
# Change the behavior to match your needs.

PW_NAME=""
PW_ENTRY=""
declare -ig PW_FZF=0

_log() { echo "[Sample Plugin] $*"; }
Expand All @@ -27,20 +27,20 @@ pw::add() {

pw::edit() {
pw::select_entry_with_prompt edit "$@"
_addOrEdit 1 "${PW_NAME}"
_addOrEdit 1 "${PW_ENTRY}"
}

_addOrEdit() {
local -i edit=$1; shift
local name account
name="$1" account="${2:-}"
pw::prompt_password "${name}"
local entry account
entry="$1" account="${2:-}"
pw::prompt_password "${entry}"

if ((edit))
# TOBEIMPLEMENTED
then _log "Editing entry '${PW_NAME}' with account '${account}' in keychain '${PW_KEYCHAIN}'"
then _log "Editing entry '${entry}' with account '${account}' in keychain '${PW_KEYCHAIN}'"
# TOBEIMPLEMENTED
else _log "Adding entry '${PW_NAME}' with account '${account}' to keychain '${PW_KEYCHAIN}'"
else _log "Adding entry '${entry}' with account '${account}' to keychain '${PW_KEYCHAIN}'"
fi
}

Expand All @@ -66,12 +66,12 @@ pw::rm() {
local -i remove=1
pw::select_entry_with_prompt remove "$@"
if ((PW_FZF)); then
read -rp "Do you really want to remove ${PW_NAME} from ${PW_KEYCHAIN}? (y / n): "
read -rp "Do you really want to remove ${PW_ENTRY} from ${PW_KEYCHAIN}? (y / n): "
[[ "${REPLY}" == "y" ]] || remove=0
fi

# TOBEIMPLEMENTED
((!remove)) || _log "Removing entry '${PW_NAME}' from keychain '${PW_KEYCHAIN}'"
((!remove)) || _log "Removing entry '${PW_ENTRY}' from keychain '${PW_KEYCHAIN}'"
}

pw::list() {
Expand All @@ -82,14 +82,14 @@ pw::list() {
pw::select_entry_with_prompt() {
local fzf_prompt="$1"; shift
if (($#)); then
PW_NAME="$1"
PW_ENTRY="$1"
PW_FZF=0
else

# TOBEIMPLEMENTED
PW_NAME="$(pw::list | fzf --prompt="${fzf_prompt}> " --layout=reverse --info=hidden)"
PW_ENTRY="$(pw::list | fzf --prompt="${fzf_prompt}> " --layout=reverse --info=hidden)"

[[ -n "${PW_NAME}" ]] || exit 1
[[ -n "${PW_ENTRY}" ]] || exit 1
# shellcheck disable=SC2034
PW_FZF=1
fi
Expand Down
6 changes: 3 additions & 3 deletions src/pw
Original file line number Diff line number Diff line change
Expand Up @@ -153,10 +153,10 @@ pw::plugins() {

PW_PASSWORD=""
pw::prompt_password() {
local name="$1" retype
read -rsp "Enter password for ${name}: " PW_PASSWORD; echo
local entry="$1" retype
read -rsp "Enter password for ${entry}: " PW_PASSWORD; echo
if [[ -n "${PW_PASSWORD}" ]]; then
read -rsp "Retype password for ${name}: " retype; echo
read -rsp "Retype password for ${entry}: " retype; echo
if [[ "${retype}" != "${PW_PASSWORD}" ]]; then
echo "Error: the entered passwords do not match."
exit 1
Expand Down

0 comments on commit 67ff7c6

Please sign in to comment.