Repository navigation
Expand file tree
/
Copy pathfile-processing-tool.sh
More file actions
107 lines (99 loc) · 2.59 KB
/
Copy pathfile-processing-tool.sh
File metadata and controls
107 lines (99 loc) · 2.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#!/bin/bash
function help_msg() {
echo -e "View and processing of given files.\n\nUsage:\n\t$0"
}
if [ "$1" == '-h' ]; then
help_msg
exit 0
fi
if [ $# -lt 1 ]; then
help_msg
exit 1
fi
function main() {
declare -a files=($*)
declare -a selected=('Selected:')
declare -a edited=('Edited:')
declare -a deleted=('Deleted:')
function printa() {
array=($1)
if [ ${#array[*]} -gt 1 ]
then
printf "%s\n" "${array[@]}"
fi
}
i=0
while [ $i -ge 0 ] && [ $i -lt ${#files[*]} ]
do
f=${files[$i]}
if [ ! -f ${f} ]; then
files=(${files[@]/$f})
continue
fi
clear
printf "%$((`tput cols`))s\n" "[$i:${#files[*]}]"
head_cols=$((`tput lines`-15))
head -n${head_cols} ${f}
if [ `cat ${f} | wc -l` -gt ${head_cols} ]
then
echo "------------------------------ 8< ------------------------------"
tail -n3 ${f}
fi
echo
echo -e "What do you want to do with the file ${f}?"
echo -n "Choose (e)dit, (d)elete, (r)eplace the first string of php file, (a)dd to selection, (n)ext, (p)revious or (q)uit "
while true
do
read -s -n1 choise
echo "${choise}"
case "${choise}" in
e)
/usr/bin/vim ${f}
edited+=($f)
i=$(($i+1))
break
;;
d)
/bin/rm -f ${f}
deleted+=($f)
i=$(($i+1))
break
;;
r)
/bin/sed -i '1c\<?php' ${f}
edited+=($f)
i=$(($i+1))
break
;;
p)
i=$(($i-1))
break
;;
a)
selected+=($f)
i=$(($i+1))
break
;;
n)
i=$(($i+1))
break
;;
q)
clear
printa "${selected[*]}"
printa "${edited[*]}"
printa "${deleted[*]}"
exit 0
;;
*)
break
;;
esac
done
done
clear
printa "${selected[*]}"
printa "${edited[*]}"
printa "${deleted[*]}"
}
main $*