-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutilities.sh
More file actions
45 lines (42 loc) · 1.05 KB
/
Copy pathutilities.sh
File metadata and controls
45 lines (42 loc) · 1.05 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
# Utility functions
# encode URL using given input
rawurlencode() {
local string="${1}"
local strlen=${#string}
local encoded=""
for (( pos=0 ; pos<strlen ; pos++ )); do
c=${string:$pos:1}
case "$c" in
[-_.~a-zA-Z0-9] ) o="${c}" ;;
* ) printf -v o '%%%02x' "'$c"
esac
encoded+="${o}"
done
echo "${encoded}" # You can either set a return variable (FASTER)
REPLY="${encoded}" #+or echo the result (EASIER)... or both... :p
}
# get current time
ts(){
if [[ $1 == '-d' ]]; then
# timestamp with (US) date
echo $(date '+%T %D');
elif [[ $1 == '-e' ]]; then
# timestamp with euro-style date
echo $(date '+%T %d.%m.%y');
elif [[ $1 == '-f' ]]; then
# url encoded timestamp
DATESTR=$(echo $(date '+%T %d.%m.%y'));
DATESTR=${DATESTR//\:/\_};
DATESTR=${DATESTR//\./\_};
DATESTR=${DATESTR// /\-};
echo $DATESTR;
else
if [[ $1 == '-s' ]]; then
# ...with seconds and TimeOfDay stamp
echo $(date +%r);
else
# simple 24hr timestamp
echo $(date +%R);
fi
fi
};