--- /dev/null
+#!/bin/sh -e
+# passman -- simple password manager
+# Copyright (C) 2013-2015 Sergey Matveev (stargrave@stargrave.org)
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+DB=~/.passmandb
+
+generator()
+{
+ dd if=/dev/urandom bs=16 count=1 2>/dev/null | base64 | tr '+/' '-_' | tr -d =
+}
+
+cliper()
+{
+ xclip -in -selection $1
+}
+
+case "$1" in
+gen)
+ generator
+ ;;
+add)
+ dst="$2"
+ passwd="$3"
+ [ -n "$dst" ]
+ [ -n "$passwd" ] || passwd=$(generator)
+ echo Adding password for $dst
+ mkdir -p $DB/$dst
+ echo "$passwd" > $DB/$dst/passwd
+ ;;
+*)
+ cd $DB
+ result=$(find . -type d -path "*$1*" | while read ent; do
+ [ -e "$ent/passwd" ] || continue
+ echo "$ent" | sed 's#^\./##'
+ done)
+ if [ $(echo "$result" | wc -l) -ne 1 ]; then
+ echo "$result"
+ exit
+ fi
+ echo $result
+ if [ -e "$result"/data ]; then
+ echo -n "Associated data: "
+ cat "$result"/data
+ fi
+ perl -ne 'chop and print' "$result"/passwd | cliper clipboard
+ echo $(basename "$result") | perl -ne 'chop and print' | cliper primary
+ sleep 10
+ echo -n | cliper clipboard
+ ;;
+esac