rename script k to key

This commit is contained in:
thek4n 2024-11-13 18:24:20 +03:00
parent 09dbd61d1b
commit 1ab3bfe01d
2 changed files with 26 additions and 25 deletions

View File

@ -3,7 +3,7 @@ colors:.config/terminal-colors.d
less:.lesskey .infokey less:.lesskey .infokey
tmux:.config/tmux .tmux .config/systemd/user/tmux.service .local/bin/tmux_start_session.sh .local/bin/tmux_list_sessions.sh .local/bin/tmux_attach_session.sh .local/bin/tmux_kill_sessions.sh tmux:.config/tmux .tmux .config/systemd/user/tmux.service .local/bin/tmux_start_session.sh .local/bin/tmux_list_sessions.sh .local/bin/tmux_attach_session.sh .local/bin/tmux_kill_sessions.sh
t:.local/bin/t t:.local/bin/t
k:.local/bin/k key:.local/bin/key
zsh:.config/zsh .zshenv .inputrc %colors zsh:.config/zsh .zshenv .inputrc %colors
alacritty:.config/alacritty alacritty:.config/alacritty
nvim:.config/nvim .editorconfig .editrc .local/bin/vim_askpass_helper nvim:.config/nvim .editorconfig .editrc .local/bin/vim_askpass_helper

View File

@ -7,23 +7,19 @@ set -o nounset
readonly EXIT_SUCCESS=0 readonly EXIT_SUCCESS=0
readonly SECRETS_DIR_BASE="${HOME}/.k" readonly SECRETS_DIR_BASE="${HOME}/.secrets"
cmd_help() { cmd_help() {
echo "USAGE echo "USAGE
k script for store secrets key script for store secrets
t - Show list secrets key list - Show list secrets
t (SECRET) - Show secret content key get (SECRET) - Show secret content
t add (SECRET) - Add secret (read content from stdin or from EDITOR) key set (SECRET) - Add secret (read content from stdin or from args or from EDITOR)
t edit (SECRET) - Edit secret with INDEX by \$EDITOR key edit (SECRET) - Edit secret with INDEX by \$EDITOR
t delete (SECRET) [SECRET] ... - Delete secrets key delete (SECRET) [SECRET] ... - Delete secrets
t --help - Show this message key --help - Show this message"
t a - alias for add
t e - alias for edit
t d - alias for delete"
} }
@ -32,11 +28,15 @@ die() {
exit "${2:-${EXIT_SUCCESS}}" exit "${2:-${EXIT_SUCCESS}}"
} }
cmd_add_secret() { cmd_set_secret() {
secret_to_add="${SECRETS_DIR_BASE}/${1}"; shift
if read -t 0 _; then if read -t 0 _; then
cat > "${SECRETS_DIR_BASE}/${1}" cat > "${secret_to_add}"
elif [ -n "$*" ]; then
echo "$*" > "${secret_to_add}"
else else
${EDITOR} "${SECRETS_DIR_BASE}/${1}" ${EDITOR} "${secret_to_add}"
fi fi
exit "${EXIT_SUCCESS}" exit "${EXIT_SUCCESS}"
} }
@ -69,7 +69,7 @@ cmd_edit_secret() {
exit "${EXIT_SUCCESS}" exit "${EXIT_SUCCESS}"
} }
cmd_cat_secret() { cmd_get_secret() {
secret="${1}" secret="${1}"
secret_to_cat="${SECRETS_DIR_BASE}/${secret}" secret_to_cat="${SECRETS_DIR_BASE}/${secret}"
@ -81,7 +81,7 @@ cmd_cat_secret() {
exit "${EXIT_SUCCESS}" exit "${EXIT_SUCCESS}"
} }
cmd_show_secrets() { cmd_list_secrets() {
ls "${SECRETS_DIR_BASE}" ls "${SECRETS_DIR_BASE}"
} }
@ -92,18 +92,19 @@ fi
if [ -z "${1+x}" ]; then if [ -z "${1+x}" ]; then
cmd_show_secrets cmd_help
exit "${EXIT_SUCCESS}" exit "${EXIT_SUCCESS}"
fi fi
case "${1}" in case "${1}" in
show) shift; cmd_show_secrets ;; l|list) shift; cmd_list_secrets ;;
a|add) shift; cmd_add_secret "$@" ;; s|set) shift; cmd_set_secret "$@" ;;
g|get) shift; cmd_get_secret "$@" ;;
d|delete) shift; cmd_delete_secret "$@" ;; d|delete) shift; cmd_delete_secret "$@" ;;
e|edit) shift; cmd_edit_secret "$@" ;; e|edit) shift; cmd_edit_secret "$@" ;;
--help) shift; cmd_help ;; --help) shift; cmd_help ;;
*) cmd_cat_secret "$@" ;; *) cmd_help "$@" ;;
esac esac
exit "${EXIT_SUCCESS}" exit "${EXIT_SUCCESS}"