- Timestamp:
- May 17, 2025, 4:39:01 PM (3 weeks ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/addons/kanako-menu
r20 r28 1 1 #!/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 $ 5 3 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 4 kanako_conf_dir="${kanako_conf_dir:-$HOME/.config/kanako}" 5 kanako_store_dir="${kanako_store_dir:-$HOME/.kanako-store}" 12 6 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 14 find ${kanako_store_dir} -name '*.enc' | sort | sed 's,^\./,,;s,\.enc$,,' | ${kanako_menu_cmd} | xargs kanako -c -
trunk/kanako
r27 r28 7 7 8 8 _die() { 9 10 9 printf "\033[0;31m%s\033[0m\n" "$*" >&2 10 exit 1 11 11 } 12 12 _info() { 13 13 printf "\033[0;32m%s\033[0m\n" "$*" 14 14 } 15 15 _warn() { 16 16 printf "\033[0;33m%s\033[0m\n" "$*" 17 17 } 18 18 … … 24 24 } 25 25 edit() { 26 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}.enc30 rm "${1%%.enc}"31 32 _warn "${1%%.enc}.enc does not exist, maybe there was a typo on your end?"33 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 34 34 } 35 35 gen() { 36 36 printf "%s\n" $(strings </dev/urandom | dd bs=1 count="${1:-30}" 2>/dev/null | tr -d ' \t\n\r') 37 37 } 38 38 list() { 39 40 _die "Required dependency 'tree' not found"39 if [ -z "$(command -v tree)" ]; then 40 _die "Required dependency 'tree' not found" 41 41 42 43 44 tree "${kanako_store_dir}/" | sed 's/\.enc//g'45 46 tree "${1:-.}" | sed 's/\.enc//g'47 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 48 48 } 49 49 new() { 50 51 52 53 54 55 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} 56 56 } 57 57 otp() { 58 59 _die "Required dependency 'oathtool' not found"60 61 62 63 oathtool --totp -b ${totp_seed}64 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 65 65 } 66 66 delete_directory() { 67 68 69 70 71 n|N) _info "Abort" ;;72 y|Y) rm -rf "${1}" && _info "Removed $1";;73 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 74 74 } 75 75 delete_file() { 76 77 78 79 80 n|N) _info "Abort" ;;81 y|Y) rm -f "${1}.enc" && _info "Removed $1/$2";;82 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 83 83 } 84 84 usage() { 85 86 87 88 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 89 89 } 90 90 view() { 91 92 ${kanako_encrypt_cmd} ${kanako_decrypt_args} "${1%%.enc}".enc93 94 _die "${1%%.enc} was not found"95 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 96 96 } 97 97 … … 100 100 101 101 case ${cmd} in 102 103 104 105 106 107 108 109 110 111 112 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 ;; 113 113 esac
Note:
See TracChangeset
for help on using the changeset viewer.