Created
December 10, 2022 21:29
-
-
Save Fire-Dragon-DoL/9c350359ce5f37ef95b64fa1d8623225 to your computer and use it in GitHub Desktop.
List all entries with attachments in LastPass
This file contains hidden or 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
#!/usr/bin/env bash | |
## | |
## Usage: lpass-att-list.sh | |
## | |
## | |
usage() { echo "Usage: $0 [-l <email>] [-i <id>]" 1>&2; exit 1; } | |
while getopts ":i:o:hl:" o; do | |
case "${o}" in | |
i) | |
id=${OPTARG} | |
;; | |
l) | |
email=${OPTARG} | |
;; | |
h) | |
usage | |
;; | |
*) | |
usage | |
;; | |
esac | |
done | |
shift $((OPTIND-1)) | |
command -v lpass >/dev/null 2>&1 || { echo >&2 "I require lpass but it's not installed. Aborting."; exit 1; } | |
if ! lpass status; then | |
if [ -z ${email} ]; then | |
echo "No login data found, Please login with -l or use lpass login before." | |
exit 1; | |
fi | |
lpass login ${email} | |
fi | |
if [ -z ${id} ]; then | |
ids=$(lpass ls | sed -n "s/^.*id:\s*\([0-9]*\).*$/\1/p") | |
else | |
ids=${id} | |
fi | |
for id in ${ids}; do | |
show=$(lpass show ${id}) | |
itemname=$(lpass show --name ${id}) | |
attcount=$(echo "${show}" | grep -c "att-") | |
path=$(lpass show --format="%/as%/ag%an" ${id} | uniq | tail -1) | |
path=${path//\\//} | |
if [ ${attcount} -gt 0 ]; then | |
echo "${path}/${itemname}" | |
fi | |
until [ ${attcount} -lt 1 ]; do | |
att=`lpass show ${id} | grep att- | sed "${attcount}q;d" | tr -d :` | |
attid=$(echo ${att} | awk '{print $1}') | |
attname=$(echo ${att} | awk '{print $2}') | |
if [[ -z ${attname} ]]; then | |
attname=${path#*/} | |
fi | |
printf "\t%s [id: %s]\n" "$attname" "${attid}" | |
let attcount-=1 | |
done | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Requires lpass