cem-utils

Random utilities
git clone git://git.ckyln.com/~cem/cem-utils.git
Log | Files | Refs | README

commit 696b5e63a512c0972c8e18c67a76bd886c5f38b0
parent 0c2b9fb6418f8f1e8281f77219d6f78c759b9a0a
Author: Cem Keylan <cem@ckyln.com>
Date:   Tue, 10 Mar 2020 19:55:40 +0300

move pm to its own repository

Diffstat:
MREADME.md | 70++++++----------------------------------------------------------------
Dpm/Makefile | 10----------
Dpm/contrib/Makefile | 10----------
Dpm/contrib/README | 5-----
Dpm/contrib/pm-add-dmenu | 11-----------
Dpm/contrib/pm-ask | 13-------------
Dpm/contrib/pm-copy | 4----
Dpm/contrib/pm-copy-dmenu | 10----------
Dpm/contrib/pm-git | 4----
Dpm/contrib/pm-tree | 5-----
Dpm/pm | 35-----------------------------------
11 files changed, 6 insertions(+), 171 deletions(-)

diff --git a/README.md b/README.md @@ -32,17 +32,18 @@ small list of programs: * nap * nap-hooks * dwm-notify-send -* pm nap --- -Literally Leah's zzz[1] with only suspend feature. +Literally Leah's [zzz] with only suspend feature. It is compatible with zzz so it can read zzz.d Why don't I add hybernation stuff? Because my computer cannot hybernate. +[zzz]: http://git.vuxu.org/runit-void/tree/zzz + You see my point? I don't have a use for more than half of the things zzz script does. So I deleted them. @@ -58,11 +59,13 @@ install nap nap-hooks --------- -POSIX-compliant and simplified zzz-user-hooks[2]. +POSIX-compliant and simplified [zzz-user-hooks]. Does not support Wayland. Works with sbase-ubase. Is a shell script instead of a bash script. 32 lines of shell code instead of 112. +[zzz-user-hooks]: https://github.com/bahamas10/zzz-user-hooks + To install run, as root if necessary make -C nap-hooks install @@ -100,64 +103,3 @@ To install run, as root if necessary This will install `notify-send` and `kill-notification` to `/usr/local/bin` - - -pm --- - -Dumb password manager with absolutely no fancy features. By -that I mean, - -* No password generation -* No git integration -* No questions asked -* No grepping/finding passwords -* No clipboard support -* No tree view -* Does not ask for password input (reads from stdin) - -Currently less than 35 LOC. Supports adding/deleting/listing/showing -passwords. I don't intend on implementing any more features. -You can wrap this script with something other to make use of -it. - -To install run, as root if necessary - - make -C pm install - -You really do think that asking for password for twice blah -blah is a really important feature? Okay, then add a function -to your shellrc/profile like this. - - pmask() { - [ "$1" ] || return 1 - printf 'Enter your password: ' - read pass - printf 'Enter your password again: ' - read pass2 - if [ "$pass" = "$pass2" ] ; then - printf '%s' "$pass" | pm a "$1" - else - printf "Passwords don't match\n" - return 1 - fi - } - -You want to copy to clipboard? That's easy! You just need -to do a `pm s passname | xclip -sel c`. You can still make -it a function by doing this - - copypass() { - [ "$1" ] || return 1 - pm s "$1" | xclip -sel c - } - -The whole rationale is that you can already do that with simple -commands. Why complicate (and possibly break) things by introducing -them into a single script? If you want some function that is -a must for you, implement it yourself with some script or -a shell function. This way, it works just as you intended it. - - -[1]: http://git.vuxu.org/runit-void/tree/zzz -[2]: https://github.com/bahamas10/zzz-user-hooks diff --git a/pm/Makefile b/pm/Makefile @@ -1,10 +0,0 @@ -PREFIX = /usr/local -BINDIR = ${PREFIX}/bin - -install: - install -Dm755 -t ${DESTDIR}${BINDIR} pm - -uninstall: - rm -f ${DESTDIR}${BINDIR}/pm - -.PHONY: install uninstall diff --git a/pm/contrib/Makefile b/pm/contrib/Makefile @@ -1,10 +0,0 @@ -PREFIX = /usr/local -BINDIR = ${PREFIX}/bin -contrib = pm-add-dmenu pm-ask pm-copy pm-copy-dmenu pm-git pm-tree - -install: - install -Dm755 -t ${DESTDIR}${BINDIR} ${contrib} - -uninstall: - for bin in ${contrib} ; do \ - rm -f ${DESTDIR}${BINDIR}/$$bin ; done diff --git a/pm/contrib/README b/pm/contrib/README @@ -1,5 +0,0 @@ -contrib scripts -=============== - -These are some example ways you can adapt -pm into your own scripts. diff --git a/pm/contrib/pm-add-dmenu b/pm/contrib/pm-add-dmenu @@ -1,11 +0,0 @@ -#!/bin/sh - -name=$(dmenu -p "Give a name to your password" <&-) -pass=" " - -while ! [ "$pass" = "$pass2" ] ; do - pass=$(dmenu -nb black -nf black -p "Enter your password" <&-) - pass2=$(dmenu -nb black -nf black -p "Enter your password again" <&-) -done - -printf '%s' "$pass" | pm a "$name" diff --git a/pm/contrib/pm-ask b/pm/contrib/pm-ask @@ -1,13 +0,0 @@ -#!/bin/sh -[ "$1" ] || exit 1 -stty -echo -printf 'Enter your password for %s: ' "$1" -read pass -printf '\nEnter your password again: ' -read pass2 -printf '\n' -stty echo -[ "$pass" = "$pass2" ] && { printf '%s' "$pass" | pm a "$1" ;} || { - printf "Passwords don't match\n" - exit 1 -} diff --git a/pm/contrib/pm-copy b/pm/contrib/pm-copy @@ -1,4 +0,0 @@ -#!/bin/sh - -[ "$1" ] || exit 1 -pm s "$1" | xclip -sel c diff --git a/pm/contrib/pm-copy-dmenu b/pm/contrib/pm-copy-dmenu @@ -1,10 +0,0 @@ -#!/bin/sh - -getpass() { - pm l | while read -r file ; do - basename "$file" | cut -d . -f 1 - done -} - -choice=$(getpass | dmenu -p "Choose the password that you would like to copy" -l 10) -[ "$choice" ] && pm s "$choice" | xclip -sel c diff --git a/pm/contrib/pm-git b/pm/contrib/pm-git @@ -1,4 +0,0 @@ -#!/bin/sh - -cd "${PM_DIR:-$HOME/.local/share/pm}" || exit 1 -git "$@" diff --git a/pm/contrib/pm-tree b/pm/contrib/pm-tree @@ -1,5 +0,0 @@ -#!/bin/sh - -printf '%s\n' "pm store" -tree -C -l --noreport "${PM_DIR:-$HOME/.local/share/pm}" | tail -n +2 | sed -E 's/\.asc(\x1B\[[0-9]+m)?( ->|$)/\1\2/g' # remove .gpg at end of line, but keep colors - diff --git a/pm/pm b/pm/pm @@ -1,35 +0,0 @@ -#!/bin/sh -umask 077 -error() { printf '\033[1;31m!> \033[merror: %s\n' "$@" >&2 ;} -die() { error "$1" ; exit 1 ;} - -PM_DIR="${PM_DIR:-$HOME/.local/share/pm}" -usage() { printf '\033[1;36m-> \033[m%s\n' "usage: ${0##*/} [a|d|l|s] [options]" "" \ - "[a]dd <name> - Reads the password from stdin to the given entry" \ - "[d]el <name> - Deletes given enry" \ - "[l]ist - Lists all the passwords" \ - "[s]how <name> - Shows the given password" "" \ - "VARIABLES:" "PM_DIR: $PM_DIR" "PM_GPG_USER: $PM_GPG_USER" >&2 ; exit "${1:-0}" ;} - -gpg="$(command -v gpg2 || command -v gpg)" || die "gnupg cannot be found" -case "$1" in - a|add) - [ "$2" ] || usage 1 - [ "$PM_GPG_USER" ] || die "Please set a \$PM_GPG_USER variable" - [ -e "$PM_DIR/$2.asc" ] && die "an entry for $2 already exists" - mkdir -p "$PM_DIR" - tr -d '\n' < /dev/stdin > "$PM_DIR/$2" - "$gpg" -e -a -r "$PM_GPG_USER" -- "$PM_DIR/$2" || - error "Could not encrypt password" - rm -f "$PM_DIR/$2" - ;; - d|del) [ "$2" ] || usage 1 ; rm -f "$PM_DIR/$2.asc" ;; - l|list) { find "$PM_DIR" -type f -name '*asc' 2>/dev/null || ls -1 "$PM_DIR"/*.asc ;} | sort ;; - s|show) - [ "$2" ] || usage 1 - [ -r "$PM_DIR/$2.asc" ] || - die "Entry for $2 doesn't exist or is not readable" - "$gpg" --decrypt "$PM_DIR/$2.asc" 2>/dev/null | tr -d '\n' || - die "Could not decrypt $PM_DIR/$2.asc" - ;; - *) usage 0 ;; esac