Fixed annoying bug on edit() after months of leaving it unnoticed

Signed-off-by: Izuru Yakumo <yakumo.izuru@chaotic.ninja>

git-svn-id: file:///srv/svn/repo/kanako/trunk@23 62e5d677-aa6e-8c4a-b8cb-b9416171cb8e
This commit is contained in:
yakumo.izuru 2024-07-13 22:32:13 +00:00
parent 12ab49594b
commit 0ffc813500
4 changed files with 59 additions and 84 deletions

View File

@ -1,18 +1,14 @@
PREFIX=/usr/local PREFIX=/usr/local
install: install-bin install-examples install-man fmt:
uninstall: uninstall-bin uninstall-examples uninstall-man shfmt --posix --write kanako
install-bin: install:
install -Dm0755 kanako ${DESTDIR}${PREFIX}/bin/kanako install -Dm0755 kanako ${DESTDIR}${PREFIX}/bin/kanako
install-examples:
install -Dm0600 kanako.conf.example ${DESTDIR}${PREFIX}/share/examples/kanako/kanako.conf install -Dm0600 kanako.conf.example ${DESTDIR}${PREFIX}/share/examples/kanako/kanako.conf
install-man:
install -Dm0600 kanako.mdoc ${DESTDIR}${PREFIX}/share/man/man1/kanako.1 install -Dm0600 kanako.mdoc ${DESTDIR}${PREFIX}/share/man/man1/kanako.1
install -Dm0600 kanako.conf.mdoc ${DESTDIR}${PREFIX}/share/man/man5/kanako.conf.5 install -Dm0600 kanako.conf.mdoc ${DESTDIR}${PREFIX}/share/man/man5/kanako.conf.5
uninstall-bin: uninstall:
rm -f ${PREFIX}/bin/kanako rm -f ${PREFIX}/bin/kanako
uninstall-examples: rm -f ${PREFIX}/share/examples/kanako/kanako.conf
rm -f ${PREFIX}/share/examples/kanako/kanako.conf ${PREFIX}/share/exmaples/kanako/kanakomenu.conf
uninstall-man:
rm -f ${PREFIX}/share/man/man1/kanako.1 ${PREFIX}/share/man/man5/kanako.conf.5 rm -f ${PREFIX}/share/man/man1/kanako.1 ${PREFIX}/share/man/man5/kanako.conf.5

101
kanako
View File

@ -6,82 +6,85 @@ readonly kanako_key_dir="${kanako_key_dir:-$HOME/.kanako}"
readonly kanako_store_dir="${kanako_store_dir:-$HOME/.kanako-store}" readonly kanako_store_dir="${kanako_store_dir:-$HOME/.kanako-store}"
if test -d "${kanako_store_dir}"; then if test -d "${kanako_store_dir}"; then
cd "${kanako_store_dir}" cd "${kanako_store_dir}"
else else
printf "Password store not found!\n" printf "Password store not found!\n"
printf "Create it with mkdir -p %s\n" "$kanako_store_dir" printf "Create it with mkdir -p %s\n" "$kanako_store_dir"
exit 1 exit 1
fi fi
if test -f "${kanako_conf_dir}/kanako.conf"; then if test -f "${kanako_conf_dir}/kanako.conf"; then
. "${kanako_conf_dir}/kanako.conf"; . "${kanako_conf_dir}/kanako.conf"
else else
printf "Configuration file has not been found!\n" printf "Configuration file has not been found!\n"
printf "Copy kanako.conf from the examples directory,\n" printf "Copy kanako.conf from the examples directory,\n"
printf "and edit accordingly.\n" printf "and edit accordingly.\n"
exit 1 exit 1
fi fi
copy() { copy() {
view "$1" | "${kanako_clip_cmd}" view "$1" | "${kanako_clip_cmd}"
} }
edit() { edit() {
# FIXME: Need a way to find out if file exists if [ -f ${1%%.enc}.enc ]; then
${kanako_encrypt_cmd} ${kanako_decrypt_args} ${1%%.enc}.enc > ${1%%.enc} ${kanako_encrypt_cmd} ${kanako_decrypt_args} ${1%%.enc}.enc >${1%%.enc}
"${EDITOR:-${EDITOR:-vi}}" "${1%%.enc}" "${EDITOR:-${EDITOR:-vi}}" "${1%%.enc}"
${kanako_encrypt_cmd} ${kanako_encrypt_args} ${1%%.enc} > ${1%%.enc}.enc ${kanako_encrypt_cmd} ${kanako_encrypt_args} ${1%%.enc} >${1%%.enc}.enc
rm "${1%%.enc}" rm "${1%%.enc}"
else
printf "%s does not exist, maybe there was a typo on your end?\n" "${1%%.enc}.enc"
fi
} }
gen() { gen() {
printf "%s\n" $(strings </dev/urandom | dd bs=1 count="${1:-30}" 2>/dev/null | tr -d ' \t\n\r') printf "%s\n" $(strings </dev/urandom | dd bs=1 count="${1:-30}" 2>/dev/null | tr -d ' \t\n\r')
} }
list() { list() {
if [ -z "$1" ]; then if [ -z "$1" ]; then
$(which tree) "${kanako_store_dir}/" | sed 's/\.enc//g' $(which tree) "${kanako_store_dir}/" | sed 's/\.enc//g'
else else
$(which tree) "${1:-.}" | sed 's/\.enc//g' $(which tree) "${1:-.}" | sed 's/\.enc//g'
fi fi
} }
new() { new() {
test -d "$1" && usage test -d "$1" && usage
tmpfile="$(mktemp)" tmpfile="$(mktemp)"
"${EDITOR:-${EDITOR:-vi}}" "${tmpfile}" "${EDITOR:-${EDITOR:-vi}}" "${tmpfile}"
mkdir -p "$(dirname "$1")" mkdir -p "$(dirname "$1")"
${kanako_encrypt_cmd} ${kanako_encrypt_args} ${tmpfile} > ${1%%.enc}.enc ${kanako_encrypt_cmd} ${kanako_encrypt_args} ${tmpfile} >${1%%.enc}.enc
rm ${tmpfile} rm ${tmpfile}
} }
delete_directory() { delete_directory() {
rm -r -I "$1" rm -r -I "$1"
} }
delete_file() { delete_file() {
rm -i "${1}${2}".enc rm -i "${1}${2}".enc
} }
usage() { usage() {
printf "Usage: %s [-c|-e|-g|-l|-n|-R|-r|-v [file or directory]]\n" "$0" printf "Usage: %s [-c|-e|-g|-l|-n|-R|-r|-v [file or directory]]\n" "$0"
printf "The arguments for all switches are relative to \${kanako_store_dir}\n" printf "The arguments for all switches are relative to \${kanako_store_dir}\n"
printf "which is located at %s\n" "${kanako_store_dir}" printf "which is located at %s\n" "${kanako_store_dir}"
exit 1 exit 1
} }
view() { view() {
if [ -f "${1%%.enc}".enc ]; then if [ -f "${1%%.enc}".enc ]; then
${kanako_encrypt_cmd} ${kanako_decrypt_args} "${1%%.enc}".enc ${kanako_encrypt_cmd} ${kanako_decrypt_args} "${1%%.enc}".enc
elif [ -d "${1:-.}" ]; then elif [ -d "${1:-.}" ]; then
list "${1:-.}" list "${1:-.}"
else else
usage usage
fi fi
} }
case $1 in case $1 in
-c) copy $2 ;; -c) copy $2 ;;
-e) edit $2 ;; -e) edit $2 ;;
-g) gen $2 ;; -g) gen $2 ;;
-l) list $2;; -l) list $2 ;;
-n) new $2 ;; -n) new $2 ;;
-R) delete_directory $2 ;; -R) delete_directory $2 ;;
-r) delete_file $2 ;; -r) delete_file $2 ;;
-v) view $2 ;; -v) view $2 ;;
*) usage ;; *) usage ;;
esac esac

View File

@ -6,14 +6,8 @@
.Nd the adaptable password manager .Nd the adaptable password manager
.Sh SYNOPSIS .Sh SYNOPSIS
.Nm .Nm
.Fl c Ar args .Op Fl ceglnrRv
.Fl e Ar args .Op Ar args
.Fl g Ar args
.Fl l
.Fl n Ar args
.Fl r Ar args
.Fl R Ar args
.Fl v Ar args
.Sh DESCRIPTION .Sh DESCRIPTION
It is a clean rewrite of It is a clean rewrite of
.Xr ayu 1 .Xr ayu 1

18
mkfile
View File

@ -1,18 +0,0 @@
PREFIX=/usr/local
install:V: install-bin install-examples install-man
uninstall:V: uninstall-bin uninstall-examples uninstall-man
install-bin:
install -Dm0755 kanako $DESTDIR$PREFIX/bin/kanako
install-examples:
install -Dm0600 kanako.conf.example $DESTDIR$PREFIX/share/examples/kanako/kanako.conf
install-man:
install -Dm0600 kanako.mdoc $DESTDIR$PREFIX/share/man/man1/kanako.1
install -Dm0600 kanako.conf.mdoc $DESTDIR$PREFIX/share/man/man5/kanako.conf.5
uninstall-bin:
rm -f $PREFIX/bin/kanako
uninstall-examples:
rm -f $PREFIX/share/examples/kanako/kanako.conf $PREFIX/share/exmaples/kanako/kanakomenu.conf
uninstall-man:
rm -f $PREFIX/share/man/man1/kanako.1 $PREFIX/share/man/man5/kanako.conf.5