Skip to content

Commit

Permalink
feat: easily backup file/dir via mkbak command
Browse files Browse the repository at this point in the history
Signed-off-by: Vladislav Doster <mvdoster@gmail.com>
  • Loading branch information
vladdoster committed Apr 15, 2023
1 parent 7ed9318 commit 018638c
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions zsh/.config/zsh/functions/mkbak
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#autoload

emulate -L zsh
setopt extendedglob

local flag_help
local -a usage=(
"mkbak [-h|--help]"
"mkbak [<filenames...>]"
)

zmodload zsh/zutil
zparseopts -D -F -K -- \
{h,-help}=flag_help \
|| return 1

(( $flag_help )) && { builtin print -l -- $usage; return 0; }

(( !$# )) && {
builtin print -P -- "%F{red}Error%f mkbkp requires one or more arguments"
return 1
}

for f in $@; do
command cp ${f}{,.bak}
(( $? )) || { builtin print -P -- "%F{green}==>%f ${f}.bak created"; }
done


# vim: set expandtab filetype=zsh shiftwidth=2 softtabstop=2 tabstop=2:

0 comments on commit 018638c

Please sign in to comment.