Changeset 28 in code


Ignore:
Timestamp:
May 17, 2025, 4:39:01 PM (3 weeks ago)
Author:
yakumo.izuru
Message:

「kanako-menu」書き換え

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/addons/kanako-menu

    r20 r28  
    11#!/bin/sh -e
    2 # $TheSupernovaDuo: kanako,v 1.9 2023/5/18 21:9:33 yakumo_izuru Exp $
    3 readonly kanako_conf_dir="${kanako_conf_dir:-$HOME/.config/kanako}"
    4 readonly kanako_store_dir="${kanako_store_dir:-$HOME/.kanako-store}"
     2# $YakumoLabs, kanako-menu v2.0, 2025/05/17 15:51:40 yakumo_izuru Exp $
    53
    6 if test -f "${kanako_conf_dir}"/kanako.conf; then
    7     . "${kanako_conf_dir}"/kanako.conf
    8 else
    9     echo "Configuration file has not been found!"
    10     exit 1
    11 fi
     4kanako_conf_dir="${kanako_conf_dir:-$HOME/.config/kanako}"
     5kanako_store_dir="${kanako_store_dir:-$HOME/.kanako-store}"
    126
    13 find . -name '*.enc' | sort | sed 's,^\./,,;s,\.enc$,,' | "${kanako_menu_cmd}" | xargs $(which kanako) -c
     7# Load configuration file
     8[ -f "${kanako_conf_dir}/kanako.conf" ] && . ${kanako_conf_dir}/kanako.conf || \
     9        printf "\033[0;31m%s\033[0m\n" "Unable to load configuration file" && exit 1
     10
     11# Choice of dynamic menu program
     12[ -z "${kanako_menu_cmd}" ] && kanako_menu_cmd="dmenu"
     13
     14find ${kanako_store_dir} -name '*.enc' | sort | sed 's,^\./,,;s,\.enc$,,' | ${kanako_menu_cmd} | xargs kanako -c
  • trunk/kanako

    r27 r28  
    77
    88_die() {
    9     printf "\033[0;31m%s\033[0m\n" "$*" >&2
    10     exit 1
     9        printf "\033[0;31m%s\033[0m\n" "$*" >&2
     10        exit 1
    1111}
    1212_info() {
    13     printf "\033[0;32m%s\033[0m\n" "$*"
     13        printf "\033[0;32m%s\033[0m\n" "$*"
    1414}
    1515_warn() {
    16     printf "\033[0;33m%s\033[0m\n" "$*"
     16        printf "\033[0;33m%s\033[0m\n" "$*"
    1717}
    1818
     
    2424}
    2525edit() {
    26     if [ -f ${1%%.enc}.enc ]; then
    27         ${kanako_encrypt_cmd} ${kanako_decrypt_args} ${1%%.enc}.enc >${1%%.enc}
    28         "${EDITOR:-${EDITOR:-vi}}" "${1%%.enc}"
    29         ${kanako_encrypt_cmd} ${kanako_encrypt_args} ${1%%.enc} >${1%%.enc}.enc
    30         rm "${1%%.enc}"
    31     else
    32         _warn "${1%%.enc}.enc does not exist, maybe there was a typo on your end?"
    33     fi
     26        if [ -f ${1%%.enc}.enc ]; then
     27                ${kanako_encrypt_cmd} ${kanako_decrypt_args} ${1%%.enc}.enc >${1%%.enc}
     28                "${EDITOR:-${EDITOR:-vi}}" "${1%%.enc}"
     29                ${kanako_encrypt_cmd} ${kanako_encrypt_args} ${1%%.enc} >${1%%.enc}.enc
     30                rm "${1%%.enc}"
     31        else
     32                _warn "${1%%.enc}.enc does not exist, maybe there was a typo on your end?"
     33        fi
    3434}
    3535gen() {
    36     printf "%s\n" $(strings </dev/urandom | dd bs=1 count="${1:-30}" 2>/dev/null | tr -d ' \t\n\r')
     36        printf "%s\n" $(strings </dev/urandom | dd bs=1 count="${1:-30}" 2>/dev/null | tr -d ' \t\n\r')
    3737}
    3838list() {
    39     if [ -z "$(command -v tree)" ]; then
    40         _die "Required dependency 'tree' not found"
     39        if [ -z "$(command -v tree)" ]; then
     40                _die "Required dependency 'tree' not found"
    4141
    42     fi
    43     if [ -z "$1" ]; then
    44         tree "${kanako_store_dir}/" | sed 's/\.enc//g'
    45     else
    46         tree "${1:-.}" | sed 's/\.enc//g'
    47     fi
     42        fi
     43        if [ -z "$1" ]; then
     44                tree "${kanako_store_dir}/" | sed 's/\.enc//g'
     45        else
     46                tree "${1:-.}" | sed 's/\.enc//g'
     47        fi
    4848}
    4949new() {
    50     [ -d "$1" ] && usage
    51     tmpfile="$(mktemp)"
    52     "${EDITOR:-${EDITOR:-vi}}" "${tmpfile}"
    53     mkdir -p "$(dirname "$1")"
    54     ${kanako_encrypt_cmd} ${kanako_encrypt_args} ${tmpfile} >${1%%.enc}.enc
    55     rm ${tmpfile}
     50        [ -d "$1" ] && usage
     51        tmpfile="$(mktemp)"
     52        "${EDITOR:-${EDITOR:-vi}}" "${tmpfile}"
     53        mkdir -p "$(dirname "$1")"
     54        ${kanako_encrypt_cmd} ${kanako_encrypt_args} ${tmpfile} >${1%%.enc}.enc
     55        rm ${tmpfile}
    5656}
    5757otp() {
    58     if [ -z "$(command -v oathtool)" ]; then
    59         _die "Required dependency 'oathtool' not found"
    60     fi
    61     totp_seed=$(view "$1" | grep 'totp: ' | head -n1 | cut -d' ' -f2)
    62     if ! [ -z ${totp_seed} ]; then
    63         oathtool --totp -b ${totp_seed}
    64     fi
     58        if [ -z "$(command -v oathtool)" ]; then
     59                _die "Required dependency 'oathtool' not found"
     60        fi
     61        totp_seed=$(view "$1" | grep 'totp: ' | head -n1 | cut -d' ' -f2)
     62        if ! [ -z ${totp_seed} ]; then
     63                oathtool --totp -b ${totp_seed}
     64        fi
    6565}
    6666delete_directory() {
    67     _warn "Will be removing $1"
    68     _warn "Are you okay with that?"
    69     read junk
    70     case ${junk} in
    71         n|N) _info "Abort" ;;
    72         y|Y) rm -rf "${1}" && _info "Removed $1";;
    73     esac
     67        _warn "Will be removing $1"
     68        _warn "Are you okay with that?"
     69        read junk
     70        case ${junk} in
     71                n | N) _info "Abort" ;;
     72                y | Y) rm -rf "${1}" && _info "Removed $1" ;;
     73        esac
    7474}
    7575delete_file() {
    76     _warn "Will be removing $1"
    77     _warn "Are you okay with that?"
    78     read junk
    79     case ${junk} in
    80         n|N) _info "Abort" ;;
    81         y|Y) rm -f "${1}.enc" && _info "Removed $1/$2";;
    82     esac
     76        _warn "Will be removing $1"
     77        _warn "Are you okay with that?"
     78        read junk
     79        case ${junk} in
     80                n | N) _info "Abort" ;;
     81                y | Y) rm -f "${1}.enc" && _info "Removed $1/$2" ;;
     82        esac
    8383}
    8484usage() {
    85     _info "Usage: kanako [-ceglnorRv] args"
    86     _info "The arguments for all switches are relative to \${kanako_store_dir}"
    87     _info "which is located at ${kanako_store_dir}"
    88     exit
     85        _info "Usage: kanako [-ceglnorRv] args"
     86        _info "The arguments for all switches are relative to \${kanako_store_dir}"
     87        _info "which is located at ${kanako_store_dir}"
     88        exit
    8989}
    9090view() {
    91     if [ -f "${1%%.enc}".enc ]; then
    92         ${kanako_encrypt_cmd} ${kanako_decrypt_args} "${1%%.enc}".enc
    93     else
    94         _die "${1%%.enc} was not found"
    95     fi
     91        if [ -f "${1%%.enc}".enc ]; then
     92                ${kanako_encrypt_cmd} ${kanako_decrypt_args} "${1%%.enc}".enc
     93        else
     94                _die "${1%%.enc} was not found"
     95        fi
    9696}
    9797
     
    100100
    101101case ${cmd} in
    102     -c) copy ${arg} ;;
    103     -e) edit ${arg} ;;
    104     -g) gen ${arg} ;;
    105     -h) usage ;;
    106     -l) list ${arg} ;;
    107     -n) new ${arg} ;;
    108     -o) otp ${arg} ;;
    109     -r) delete_file ${arg} ;;
    110     -R) delete_directory ${arg} ;;
    111     -v) view ${arg} ;;
    112     *) usage ;;
     102        -c) copy ${arg} ;;
     103        -e) edit ${arg} ;;
     104        -g) gen ${arg} ;;
     105        -h) usage ;;
     106        -l) list ${arg} ;;
     107        -n) new ${arg} ;;
     108        -o) otp ${arg} ;;
     109        -r) delete_file ${arg} ;;
     110        -R) delete_directory ${arg} ;;
     111        -v) view ${arg} ;;
     112        *) usage ;;
    113113esac
Note: See TracChangeset for help on using the changeset viewer.