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
install: install-bin install-examples install-man
uninstall: uninstall-bin uninstall-examples uninstall-man
fmt:
shfmt --posix --write kanako
install-bin:
install:
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:
uninstall:
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/examples/kanako/kanako.conf
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}"
if test -d "${kanako_store_dir}"; then
cd "${kanako_store_dir}"
cd "${kanako_store_dir}"
else
printf "Password store not found!\n"
printf "Create it with mkdir -p %s\n" "$kanako_store_dir"
exit 1
printf "Password store not found!\n"
printf "Create it with mkdir -p %s\n" "$kanako_store_dir"
exit 1
fi
if test -f "${kanako_conf_dir}/kanako.conf"; then
. "${kanako_conf_dir}/kanako.conf";
. "${kanako_conf_dir}/kanako.conf"
else
printf "Configuration file has not been found!\n"
printf "Copy kanako.conf from the examples directory,\n"
printf "and edit accordingly.\n"
exit 1
printf "Configuration file has not been found!\n"
printf "Copy kanako.conf from the examples directory,\n"
printf "and edit accordingly.\n"
exit 1
fi
copy() {
view "$1" | "${kanako_clip_cmd}"
view "$1" | "${kanako_clip_cmd}"
}
edit() {
# FIXME: Need a way to find out if file exists
${kanako_encrypt_cmd} ${kanako_decrypt_args} ${1%%.enc}.enc > ${1%%.enc}
"${EDITOR:-${EDITOR:-vi}}" "${1%%.enc}"
${kanako_encrypt_cmd} ${kanako_encrypt_args} ${1%%.enc} > ${1%%.enc}.enc
rm "${1%%.enc}"
if [ -f ${1%%.enc}.enc ]; then
${kanako_encrypt_cmd} ${kanako_decrypt_args} ${1%%.enc}.enc >${1%%.enc}
"${EDITOR:-${EDITOR:-vi}}" "${1%%.enc}"
${kanako_encrypt_cmd} ${kanako_encrypt_args} ${1%%.enc} >${1%%.enc}.enc
rm "${1%%.enc}"
else
printf "%s does not exist, maybe there was a typo on your end?\n" "${1%%.enc}.enc"
fi
}
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() {
if [ -z "$1" ]; then
$(which tree) "${kanako_store_dir}/" | sed 's/\.enc//g'
else
$(which tree) "${1:-.}" | sed 's/\.enc//g'
fi
if [ -z "$1" ]; then
$(which tree) "${kanako_store_dir}/" | sed 's/\.enc//g'
else
$(which tree) "${1:-.}" | sed 's/\.enc//g'
fi
}
new() {
test -d "$1" && usage
test -d "$1" && usage
tmpfile="$(mktemp)"
"${EDITOR:-${EDITOR:-vi}}" "${tmpfile}"
tmpfile="$(mktemp)"
"${EDITOR:-${EDITOR:-vi}}" "${tmpfile}"
mkdir -p "$(dirname "$1")"
${kanako_encrypt_cmd} ${kanako_encrypt_args} ${tmpfile} > ${1%%.enc}.enc
rm ${tmpfile}
mkdir -p "$(dirname "$1")"
${kanako_encrypt_cmd} ${kanako_encrypt_args} ${tmpfile} >${1%%.enc}.enc
rm ${tmpfile}
}
delete_directory() {
rm -r -I "$1"
rm -r -I "$1"
}
delete_file() {
rm -i "${1}${2}".enc
rm -i "${1}${2}".enc
}
usage() {
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 "which is located at %s\n" "${kanako_store_dir}"
exit 1
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 "which is located at %s\n" "${kanako_store_dir}"
exit 1
}
view() {
if [ -f "${1%%.enc}".enc ]; then
${kanako_encrypt_cmd} ${kanako_decrypt_args} "${1%%.enc}".enc
elif [ -d "${1:-.}" ]; then
list "${1:-.}"
else
usage
fi
if [ -f "${1%%.enc}".enc ]; then
${kanako_encrypt_cmd} ${kanako_decrypt_args} "${1%%.enc}".enc
elif [ -d "${1:-.}" ]; then
list "${1:-.}"
else
usage
fi
}
case $1 in
-c) copy $2 ;;
-e) edit $2 ;;
-g) gen $2 ;;
-l) list $2;;
-n) new $2 ;;
-R) delete_directory $2 ;;
-r) delete_file $2 ;;
-v) view $2 ;;
*) usage ;;
-c) copy $2 ;;
-e) edit $2 ;;
-g) gen $2 ;;
-l) list $2 ;;
-n) new $2 ;;
-R) delete_directory $2 ;;
-r) delete_file $2 ;;
-v) view $2 ;;
*) usage ;;
esac

View File

@ -6,14 +6,8 @@
.Nd the adaptable password manager
.Sh SYNOPSIS
.Nm
.Fl c Ar args
.Fl e Ar args
.Fl g Ar args
.Fl l
.Fl n Ar args
.Fl r Ar args
.Fl R Ar args
.Fl v Ar args
.Op Fl ceglnrRv
.Op Ar args
.Sh DESCRIPTION
It is a clean rewrite of
.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