-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: easily backup file/dir via mkbak command
Signed-off-by: Vladislav Doster <mvdoster@gmail.com>
- Loading branch information
1 parent
7ed9318
commit 018638c
Showing
1 changed file
with
30 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: |