-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjoin-file
More file actions
executable file
·44 lines (37 loc) · 997 Bytes
/
join-file
File metadata and controls
executable file
·44 lines (37 loc) · 997 Bytes
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
#!/usr/bin/env sh
# Usage: doc/api.md#join-file
# Create an alias
. "${SHELL_API_PATH}"/common/expand-aliases
alias join-file="join_file"
join_file(){
part_a=""
part_b=""
sudo_cmd=""
target="${1}"
if [ -z "${1}" ]; then
echo "join-file: arguments are missing"
return 127
fi
if [ "${1}" = "-a" ] || [ "${1}" = "--auth" ]; then
sudo_cmd="sudo "
shift $(( $# > 0 ? 1 : 0 ))
fi
# 2 files
if [ -f "${1}" ] && [ -f "${2}" ]; then
part_a=$(awk '1' "${1}")
part_b=$(awk '1' "${2}")
# File and string
elif [ -f "${1}" ] && [ -n "${2}" ]; then
part_a=$(awk '1' "${1}")
part_b="${2}"
# String and file
elif [ -f "${2}" ] && [ -n "${1}" ]; then
part_a="${1}"
part_b=$(awk '1' "${2}")
target="${2}"
else
echo "Cannot find target - no such file"
return 127
fi
echo "${part_a}${part_b}" | "${sudo_cmd}"tee "${target}" >/dev/null 2>&1
}