Changeset 23 in code


Ignore:
Timestamp:
Jul 13, 2024, 10:32:13 PM (11 months ago)
Author:
yakumo.izuru
Message:

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

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

Location:
trunk
Files:
1 deleted
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Makefile

    r18 r23  
    11PREFIX=/usr/local
    22
    3 install: install-bin install-examples install-man
    4 uninstall: uninstall-bin uninstall-examples uninstall-man
     3fmt:
     4        shfmt --posix --write kanako
    55
    6 install-bin:
     6install:
    77        install -Dm0755 kanako ${DESTDIR}${PREFIX}/bin/kanako
    8 install-examples:
    98        install -Dm0600 kanako.conf.example ${DESTDIR}${PREFIX}/share/examples/kanako/kanako.conf
    10 install-man:
    119        install -Dm0600 kanako.mdoc ${DESTDIR}${PREFIX}/share/man/man1/kanako.1
    1210        install -Dm0600 kanako.conf.mdoc ${DESTDIR}${PREFIX}/share/man/man5/kanako.conf.5
    13 uninstall-bin:
     11uninstall:
    1412        rm -f ${PREFIX}/bin/kanako
    15 uninstall-examples:
    16         rm -f ${PREFIX}/share/examples/kanako/kanako.conf ${PREFIX}/share/exmaples/kanako/kanakomenu.conf
    17 uninstall-man:
     13        rm -f ${PREFIX}/share/examples/kanako/kanako.conf
    1814        rm -f ${PREFIX}/share/man/man1/kanako.1 ${PREFIX}/share/man/man5/kanako.conf.5
  • trunk/kanako

    r22 r23  
    77
    88if test -d "${kanako_store_dir}"; then
    9     cd "${kanako_store_dir}"
     9        cd "${kanako_store_dir}"
    1010else
    11     printf "Password store not found!\n"
    12     printf "Create it with mkdir -p %s\n" "$kanako_store_dir"
    13     exit 1
     11        printf "Password store not found!\n"
     12        printf "Create it with mkdir -p %s\n" "$kanako_store_dir"
     13        exit 1
    1414fi
    1515
    1616if test -f "${kanako_conf_dir}/kanako.conf"; then
    17     . "${kanako_conf_dir}/kanako.conf";
     17        . "${kanako_conf_dir}/kanako.conf"
    1818else
    19     printf "Configuration file has not been found!\n"
    20     printf "Copy kanako.conf from the examples directory,\n"
    21     printf "and edit accordingly.\n"
    22     exit 1
     19        printf "Configuration file has not been found!\n"
     20        printf "Copy kanako.conf from the examples directory,\n"
     21        printf "and edit accordingly.\n"
     22        exit 1
    2323fi
    2424
    2525copy() {
    26     view "$1" | "${kanako_clip_cmd}"
     26        view "$1" | "${kanako_clip_cmd}"
    2727}
    2828edit() {
    29     # FIXME: Need a way to find out if file exists
    30     ${kanako_encrypt_cmd} ${kanako_decrypt_args} ${1%%.enc}.enc > ${1%%.enc}
    31     "${EDITOR:-${EDITOR:-vi}}" "${1%%.enc}"
    32     ${kanako_encrypt_cmd} ${kanako_encrypt_args} ${1%%.enc} > ${1%%.enc}.enc
    33     rm "${1%%.enc}"
     29        if [ -f ${1%%.enc}.enc ]; then
     30                ${kanako_encrypt_cmd} ${kanako_decrypt_args} ${1%%.enc}.enc >${1%%.enc}
     31                "${EDITOR:-${EDITOR:-vi}}" "${1%%.enc}"
     32                ${kanako_encrypt_cmd} ${kanako_encrypt_args} ${1%%.enc} >${1%%.enc}.enc
     33                rm "${1%%.enc}"
     34        else
     35                printf "%s does not exist, maybe there was a typo on your end?\n" "${1%%.enc}.enc"
     36        fi
    3437}
    3538gen() {
    36     printf "%s\n" $(strings </dev/urandom | dd bs=1 count="${1:-30}" 2>/dev/null | tr -d ' \t\n\r')
     39        printf "%s\n" $(strings </dev/urandom | dd bs=1 count="${1:-30}" 2>/dev/null | tr -d ' \t\n\r')
    3740}
    3841list() {
    39     if [ -z "$1" ]; then
    40         $(which tree) "${kanako_store_dir}/" | sed 's/\.enc//g'
    41     else
    42         $(which tree) "${1:-.}" | sed 's/\.enc//g'
    43     fi
     42        if [ -z "$1" ]; then
     43                $(which tree) "${kanako_store_dir}/" | sed 's/\.enc//g'
     44        else
     45                $(which tree) "${1:-.}" | sed 's/\.enc//g'
     46        fi
    4447}
    4548new() {
    46     test -d "$1" && usage
     49        test -d "$1" && usage
    4750
    48     tmpfile="$(mktemp)"
    49     "${EDITOR:-${EDITOR:-vi}}" "${tmpfile}"
     51        tmpfile="$(mktemp)"
     52        "${EDITOR:-${EDITOR:-vi}}" "${tmpfile}"
    5053
    51     mkdir -p "$(dirname "$1")"
    52     ${kanako_encrypt_cmd} ${kanako_encrypt_args} ${tmpfile} > ${1%%.enc}.enc
    53     rm ${tmpfile}
     54        mkdir -p "$(dirname "$1")"
     55        ${kanako_encrypt_cmd} ${kanako_encrypt_args} ${tmpfile} >${1%%.enc}.enc
     56        rm ${tmpfile}
    5457}
    5558delete_directory() {
    56     rm -r -I "$1"
     59        rm -r -I "$1"
    5760}
    5861delete_file() {
    59     rm -i "${1}${2}".enc
     62        rm -i "${1}${2}".enc
    6063}
    6164usage() {
    62     printf "Usage: %s [-c|-e|-g|-l|-n|-R|-r|-v [file or directory]]\n" "$0"
    63     printf "The arguments for all switches are relative to \${kanako_store_dir}\n"
    64     printf "which is located at %s\n" "${kanako_store_dir}"
    65     exit 1
     65        printf "Usage: %s [-c|-e|-g|-l|-n|-R|-r|-v [file or directory]]\n" "$0"
     66        printf "The arguments for all switches are relative to \${kanako_store_dir}\n"
     67        printf "which is located at %s\n" "${kanako_store_dir}"
     68        exit 1
    6669}
    6770view() {
    68     if [ -f "${1%%.enc}".enc ]; then
    69         ${kanako_encrypt_cmd} ${kanako_decrypt_args} "${1%%.enc}".enc
    70     elif [ -d "${1:-.}" ]; then
    71         list "${1:-.}"
    72     else
    73         usage
    74     fi   
     71        if [ -f "${1%%.enc}".enc ]; then
     72                ${kanako_encrypt_cmd} ${kanako_decrypt_args} "${1%%.enc}".enc
     73        elif [ -d "${1:-.}" ]; then
     74                list "${1:-.}"
     75        else
     76                usage
     77        fi
    7578}
    7679
    7780case $1 in
    78     -c) copy $2 ;;
    79     -e) edit $2 ;;
    80     -g) gen $2 ;;
    81     -l) list $2;;
    82     -n) new $2 ;;
    83     -R) delete_directory $2 ;;
    84     -r) delete_file $2 ;;
    85     -v) view $2 ;;
    86     *) usage ;;
     81-c) copy $2 ;;
     82-e) edit $2 ;;
     83-g) gen $2 ;;
     84-l) list $2 ;;
     85-n) new $2 ;;
     86-R) delete_directory $2 ;;
     87-r) delete_file $2 ;;
     88-v) view $2 ;;
     89*) usage ;;
    8790esac
  • trunk/kanako.mdoc

    r22 r23  
    77.Sh SYNOPSIS
    88.Nm
    9 .Fl c Ar args
    10 .Fl e Ar args
    11 .Fl g Ar args
    12 .Fl l
    13 .Fl n Ar args
    14 .Fl r Ar args
    15 .Fl R Ar args
    16 .Fl v Ar args
     9.Op Fl ceglnrRv
     10.Op Ar args
    1711.Sh DESCRIPTION
    1812It is a clean rewrite of
Note: See TracChangeset for help on using the changeset viewer.