-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunctions
More file actions
145 lines (100 loc) · 2.34 KB
/
functions
File metadata and controls
145 lines (100 loc) · 2.34 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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#!/bin/bash
function Ask()
{
#0 = description
#1= variables
local args=("$@")
echo "##############################"
echo ${args[0]}
unset args[0] # deltes description value
echo "---------- Optionen ---------- [1] is default"
#echo ${#variables[*]} # anzahl der elemente
for index in ${!args[*]}
do
printf "[$index] = ${args[$index]}\n"
done
read inputkey
# test if it is numeric
if [[ "$inputkey" != +([0-9]) ]]
then
#echo "is not an Integer"
inputkey=1
fi
result=${args[$inputkey]}
echo "Option is [$inputkey] = $result"
}
function rmstring()
{
echo $1 | sed -e "s/$2//g"
}
function rmline()
{
echo $1 | sed -e "/$2/d"
}
function copyfile()
{
if [ -f "$1" ]; then
cp -u "$1" "$2"
echo "$1 copied"
else
echo "$1 is no existing file"
fi
}
function filesize()
{
echo $(stat -c%s "$1")
}
function calc()
{
echo "$*"| bc -l
}
function niceformat()
{
echo "$*"| xargs printf "%1.3f"
}
function writecaption() # $1 is the text. $2 is the character (like +) $3 is the txtcolor
{
local c="#"
if [[ "$2" != "" ]] ; then
c="$2"
fi
printf "$3"
printf "%$(tput cols)s\n"|tr ' ' "$c"
if [[ $1 != "" ]] ; then
local w=" $1 "
local lw=${#w}
printf "%$(( ($(tput cols)-lw) /2))s"|tr ' ' "$c"
printf "$w"
printf "%$(( ($(tput cols)-lw) /2))s\n"|tr ' ' "$c"
printf "%$(tput cols)s\n"|tr ' ' "$c"
fi
printf "$(tput sgr0)" # text reset
}
function copyrsyncfile()
{
#1= from
#2= to
#3= limit KB/s
local l=$3
if [[ "$l" = "" ]]; then
l=0
fi
local frompath="$1"
local topath="$2"
echo "$frompath ---> $topath"
rsync --recursive --human-readable --progress --ignore-existing --protect-args -v --compress --bwlimit="$l" "$frompath" "$topath"
}
# Text color variables
txtund=$(tput sgr 0 1) # Underline
txtbld=$(tput bold) # Bold
txtred=$(tput setaf 1) # Red
txtgrn=$(tput setaf 2) # Green
txtylw=$(tput setaf 3) # Yellow
txtblu=$(tput setaf 4) # Blue
txtpur=$(tput setaf 5) # Purple
txtcyn=$(tput setaf 6) # Cyan
txtwht=$(tput setaf 7) # White
txtrst=$(tput sgr0) # Text reset
colorarray=($txtred $txtgrn $txtylw $txtblu $txtpur $txtcyn $txtwht $txtrst)
#rc=${colorarray[$((RANDOM%(${#colorarray[@]})))]} # random color
#http://www.thegeekstuff.com/2010/06/bash-array-tutorial/