Skip to content

Instantly share code, notes, and snippets.

@mpontillo
Last active March 26, 2017 20:23
Show Gist options
  • Save mpontillo/a678aa464f3137750889578858f2df07 to your computer and use it in GitHub Desktop.
Save mpontillo/a678aa464f3137750889578858f2df07 to your computer and use it in GitHub Desktop.
Lastpass CLI helpers
#!/bin/bash
ARGS=""
function usage() {
echo "Usage:"
echo " $0 [-c|--count] [-h|--help]"
echo ""
echo "Lists the folders currently known to LastPass."
echo "If the [-c|--count] argument is given, also lists a count per folder."
}
while [ $# -gt 0 ]; do
if [ "$1" == "--count" -o "$1" == "-c" ]; then
ARGS="$ARGS -c"
elif [ "$1" == "--help" -o "$1" == "-h" -o "$1" == "-?" ]; then
usage
exit 1
fi
shift
done
lpass ls | grep -o '^.*/' | cut -d/ -f1 | sort | uniq $ARGS
#!/bin/bash
# For debugging the lastpass-cli.
# export LPASS_LOG_LEVEL=8
if ! lpass status; then
echo "Must be logged into lastpass."
echo "First use:"
echo " lpass login [email protected]"
exit 1
fi
function sync_ssh_file() {
if [ -f "$@" ]; then
cat "$@" | lpass edit --sync=no --non-interactive --notes $HOSTNAME/.ssh/"$@"
fi
}
echo "Syncing $HOME/.ssh/* with LastPass folder: $HOSTNAME/.ssh; please wait..."
cd $HOME/.ssh
FILES=$(find . -maxdepth 1 -type f ! -size +45000c | grep -v known_hosts | sed 's/^.\///')
for file in $FILES; do
sync_ssh_file $file
done
lpass sync
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment