Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env bash
- insert () {
- echo -e "$2" | pass insert --multiline -f "${1}" > /dev/null
- }
- sanitize () {
- local res=$(echo "$1" | tr -d \'\"\!\(\))
- echo "$res"
- }
- parse_line () {
- IFS=',' read -r -a fields <<< "$1"
- if [ "uuid" != "${fields[0]}" ]; then
- group="$(sanitize "${fields[1]}")"
- title="$(sanitize "${fields[2]}")"
- url="$(sanitize "${fields[3]}")"
- user="$(sanitize "${fields[4]}")"
- password="$(sanitize "${fields[5]}")"
- notes="$(sanitize "${fields[6]}")"
- for (( i = 7; i<=${#fields[@]}; i+=1 )); do
- notes="$notes "$(sanitize "${fields[i]}")""
- done
- notes=$(echo $notes | sed -e 's/^[[:space:]]*//')
- prefix="$group/$title"
- if [ ${#user} -gt 0 ]; then
- insert "$prefix/user" "$user"
- fi
- if [ ${#url} -gt 0 ]; then
- insert "$prefix/url" "$url"
- fi
- if [ ${#password} -gt 0 ]; then
- insert "$prefix/password" "$password"
- fi
- if [ ${#notes} -gt 3 ]; then
- insert "$prefix/notes" "$notes"
- fi
- fi
- }
- while read line
- do
- parse_line "$line"
- done < "${1:-/dev/stdin}"
Add Comment
Please, Sign In to add comment