bak plugin: unbak -> unmvbak, uncpbak added

This commit is contained in:
Roman Inflianskas 2014-08-21 23:17:24 +04:00 committed by Bruno Pinto
parent d9aece92c8
commit c2c69a91e7
6 changed files with 52 additions and 35 deletions

View File

@ -1,20 +1,47 @@
function __bak_name
# trim / for directories
set arg (echo $argv[1] | sed 's/\/$//')
echo "$arg.(date +"%Y%m%d_%H%M%S").bak"
end
function __bak_help
echo -e \
"Usage:
$argv[1]bak SOURCE..."
$argv[1] SOURCE..."
end
function __bak
set program $argv[1]
if [ (count $argv) -gt 1 ]
for arg in $argv[2..-1]
eval $program $arg (__bak_name $arg)
set program $argv[2]
if [ (count $argv) -gt 2 ]
for file in $argv[3..-1]
function bak_name
# trim / for directories
set file (echo $argv[1] | sed 's/\/$//')
echo "$file.(date +"%Y%m%d_%H%M%S").bak"
end
eval $program $file (bak_name $file)
end
else
__bak_help $argv[1]
end
end
function __unbak
set program $argv[2]
if [ (count $argv) -gt 2 ]
for file in $argv[3..-1]
set re_bak '(.*)\.[0-9]{8,8}_[0-9]{6,6}\.bak'
set file $argv[1]
set normalized (echo "$file" | sed -r "s/$re_bak/\1/g")
function is_bak
echo "$file" | perl -ne "print if /$re_bak/" > /dev/null
end
if test ! -e $file
echo "File \"$file\" not exists! Cannot unbak \"$file\"."
else if not is_bak $file
echo "File \"$file\" don't meet bak files convention! Cannot unbak \"$file\"."
else if test -e $normalized
echo "File \"$normalized\" exists! Cannot unbak \"$file\"."
else
eval $program $file $normalized
end
end
else
__bak_help $argv[1]

View File

@ -2,5 +2,5 @@
# (c) Roman Inflianskas (rominf) <infroma@gmail.com>, 2014
function cpbak
__bak 'cp -a' $argv
__bak cpbak 'cp -a' $argv
end

View File

@ -2,5 +2,5 @@
# (c) Roman Inflianskas (rominf) <infroma@gmail.com>, 2014
function mvbak
__bak mv $argv
__bak mvbak mv $argv
end

View File

@ -1,22 +0,0 @@
# Function to move files and directories (a.txt.20140608_195859.bak move to a.txt)
# (c) Roman Inflianskas (rominf) <infroma@gmail.com>, 2014
function unbak
set re_bak '(.*)\.[0-9]{8,8}_[0-9]{6,6}\.bak'
set file $argv[1]
set normalized (echo "$file" | sed -E "s/$re_bak/\1/g")
function is_bak
echo "$file" | perl -ne "print if /$re_bak/" > /dev/null
end
if test ! -e $file
echo "File \"$file\" not exists! Cannot unbak \"$file\"."
else if not is_bak $file
echo "File \"$file\" don't meet bak files convention! Cannot unbak \"$file\"."
else if test -e $normalized
echo "File \"$normalized\" exists! Cannot unbak \"$file\"."
else
mv $file $normalized
end
end

6
plugins/bak/uncpbak.fish Normal file
View File

@ -0,0 +1,6 @@
# Function to copy files and directories (a.txt.20140608_195859.bak copy to a.txt)
# (c) Roman Inflianskas (rominf) <infroma@gmail.com>, 2014
function uncpbak
__unbak uncpbak 'cp -a' $argv
end

6
plugins/bak/unmvbak.fish Normal file
View File

@ -0,0 +1,6 @@
# Function to move files and directories (a.txt.20140608_195859.bak move to a.txt)
# (c) Roman Inflianskas (rominf) <infroma@gmail.com>, 2014
function unmvbak
__unbak unmvbak mv $argv
end