Commit 07860bc5 authored by Roman Inflianskas's avatar Roman Inflianskas Committed by Bruno Pinto

bak plugin: tabs -> spaces

parent 5b861f5c
...@@ -4,6 +4,16 @@ function __bak_help ...@@ -4,6 +4,16 @@ function __bak_help
$argv[1] SOURCE..." $argv[1] SOURCE..."
end end
function __bak_parse_help
function has_help_arg
# non implemented
end
if [ (count $argv) -lt 3 ]; or has_help_arg $argv
__bak_help $argv[1]
end
end
function __bak_name function __bak_name
# trim / for directories # trim / for directories
set file (echo $argv[1] | sed 's/\/$//') set file (echo $argv[1] | sed 's/\/$//')
...@@ -11,13 +21,12 @@ function __bak_name ...@@ -11,13 +21,12 @@ function __bak_name
end end
function __bak function __bak
set program $argv[2] __bak_parse_help $argv
if [ (count $argv) -gt 2 ] or begin
set program $argv[2]
for file in $argv[3..-1] for file in $argv[3..-1]
eval $program $file (__bak_name $file) eval $program $file (__bak_name $file)
end end
else
__bak_help $argv[1]
end end
end end
...@@ -34,8 +43,9 @@ function __bak_normalized ...@@ -34,8 +43,9 @@ function __bak_normalized
end end
function __unbak function __unbak
set program $argv[2] __bak_parse_help $argv
if [ (count $argv) -gt 2 ] or begin
set program $argv[2]
for file in $argv[3..-1] for file in $argv[3..-1]
set normalized (__bak_normalized $file) set normalized (__bak_normalized $file)
if test ! -e $file if test ! -e $file
...@@ -48,7 +58,5 @@ function __unbak ...@@ -48,7 +58,5 @@ function __unbak
eval $program $file $normalized eval $program $file $normalized
end end
end end
else
__bak_help $argv[1]
end end
end end
# Function to copy files and directories (a.txt copy to a.txt.20140608_195859.bak) # Function to copy files and directories (a.txt copy to a.txt.20140608_195859.bak)
# (c) Roman Inflianskas (rominf) <infroma@gmail.com>, 2014 # (c) Roman Inflianskas (rominf) <infroma@gmail.com>, 2014
function cpbak function cpbak --description 'Copy files to make a backup copies'
__bak cpbak 'cp -a' $argv __bak cpbak 'cp -a' $argv
end end
# Function to rename files and directories (a.txt rename to a.txt.20140608_195859.bak) # Function to rename files and directories (a.txt rename to a.txt.20140608_195859.bak)
# (c) Roman Inflianskas (rominf) <infroma@gmail.com>, 2014 # (c) Roman Inflianskas (rominf) <infroma@gmail.com>, 2014
function mvbak function mvbak --description 'Rename files to make a backup copies'
__bak mvbak mv $argv __bak mvbak mv $argv
end end
set -l fish_tank /usr/local/share/fish-tank/tank.fish set -l fish_tank /usr/local/share/fish-tank/tank.fish
if not test -e $fish_tank if not test -e $fish_tank
echo 'error: fish-tank is required to run these tests (https://github.com/terlar/fish-tank)' echo 'error: fish-tank is required to run these tests (https://github.com/terlar/fish-tank)'
exit 1 exit 1
end end
source $fish_tank source $fish_tank
......
function suite_bak function suite_bak
function setup function setup
return 0 return 0
end end
function teardown function teardown
rm -rf $test_dir/* rm -rf $test_dir/*
end end
function test_is_bak function test_is_bak
assert (__is_bak '.ccnet.20140817_234302.bak') assert (__is_bak '.ccnet.20140817_234302.bak')
assert (__is_bak 'file with spaces.20140817_234302.bak') assert (__is_bak 'file with spaces.20140817_234302.bak')
assert (not __is_bak '.ccnet.bak') assert (not __is_bak '.ccnet.bak')
end end
function test_normalized function test_normalized
assert_equal '.ccnet' (__bak_normalized '.ccnet.20140817_234302.bak') assert_equal '.ccnet' (__bak_normalized '.ccnet.20140817_234302.bak')
assert_equal 'file with spaces' (__bak_normalized 'file with spaces.20140817_234302.bak') assert_equal 'file with spaces' (__bak_normalized 'file with spaces.20140817_234302.bak')
end end
function test_mv_single function test_mv_single
touch a touch a
mvbak a mvbak a
assert __is_bak (ls) assert __is_bak (ls)
end end
function test_mv_multiple function test_mv_multiple
touch a b touch a b
mvbak a b mvbak a b
for f in (ls) for f in (ls)
assert __is_bak $f assert __is_bak $f
end end
end end
function test_unmv_single function test_unmv_single
touch a touch a
mvbak a mvbak a
unmvbak (ls) unmvbak (ls)
assert_equal a (ls) assert_equal a (ls)
end end
function test_unmv_multiple function test_unmv_multiple
set files (seq 4) set files (seq 4)
touch $files touch $files
mvbak $files mvbak $files
unmvbak (ls) unmvbak (ls)
assert_equal "$files" (ls) assert_equal "$files" (ls)
end end
function test_cp_single function test_cp_single
touch a touch a
cpbak a cpbak a
assert_equal (echo -e 'a' (__bak_name a) | sort) (ls | sort) assert_equal (echo -e 'a' (__bak_name a) | sort) (ls | sort)
end end
function test_cp_multiple function test_cp_multiple
set files (seq 4) set files (seq 4)
touch $files touch $files
cpbak $files cpbak $files
for f in $files for f in $files
set files_bak "$files_bak\n"(__bak_name $f) set files_bak "$files_bak\n"(__bak_name $f)
end end
set expected (begin; echo $files | sed 's/ /\n/g'; echo -e $files_bak; end | sort | grep -v '^$') set expected (begin; echo $files | sed 's/ /\n/g'; echo -e $files_bak; end | sort | grep -v '^$')
assert_equal "$expected" (ls | sort) assert_equal "$expected" (ls | sort)
end end
function test_uncp_single function test_uncp_single
touch a touch a
cpbak a cpbak a
rm a rm a
uncpbak (ls) uncpbak (ls)
assert_equal (echo -e 'a' (__bak_name a) | sort) (ls | sort) assert_equal (echo -e 'a' (__bak_name a) | sort) (ls | sort)
end end
function test_cp_multiple function test_cp_multiple
set files (seq 4) set files (seq 4)
touch $files touch $files
cpbak $files cpbak $files
rm $files rm $files
uncpbak (ls) uncpbak (ls)
for f in $files for f in $files
set files_bak "$files_bak\n"(__bak_name $f) set files_bak "$files_bak\n"(__bak_name $f)
end end
set expected (begin; echo $files | sed 's/ /\n/g'; echo -e $files_bak; end | sort | grep -v '^$') set expected (begin; echo $files | sed 's/ /\n/g'; echo -e $files_bak; end | sort | grep -v '^$')
end end
end end
if not set -q tank_running if not set -q tank_running
......
# Function to copy files and directories (a.txt.20140608_195859.bak copy to a.txt) # Function to copy files and directories (a.txt.20140608_195859.bak copy to a.txt)
# (c) Roman Inflianskas (rominf) <infroma@gmail.com>, 2014 # (c) Roman Inflianskas (rominf) <infroma@gmail.com>, 2014
function uncpbak function uncpbak --description 'Copy files to revert a backup copies to a normal files'
__unbak uncpbak 'cp -a' $argv __unbak uncpbak 'cp -a' $argv
end end
# Function to move files and directories (a.txt.20140608_195859.bak move to a.txt) # Function to move files and directories (a.txt.20140608_195859.bak move to a.txt)
# (c) Roman Inflianskas (rominf) <infroma@gmail.com>, 2014 # (c) Roman Inflianskas (rominf) <infroma@gmail.com>, 2014
function unmvbak function unmvbak --description 'Move files to revert a backup copies to a normal files'
__unbak unmvbak mv $argv __unbak unmvbak mv $argv
end end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment