-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfullpath.sh
More file actions
executable file
·129 lines (119 loc) · 2.94 KB
/
Copy pathfullpath.sh
File metadata and controls
executable file
·129 lines (119 loc) · 2.94 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
#!/bin/bash
# Determine script dir for sourcing lib
script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# shellcheck source=fullpath_lib.sh
source "${script_dir}/fullpath_lib.sh"
# Defaults
mode="default"
user="$(whoami)"
include_md5="yes"
show_header="yes"
use_fqdn="yes"
use_color="yes"
output_format="text"
# Parse arguments
args=()
while [[ $# -gt 0 ]]; do
case "$1" in
--scp)
mode="scp"
shift
;;
--vim-url)
mode="vim-url"
shift
;;
--user)
user="$2"
shift 2
;;
--no-md5)
include_md5="no"
shift
;;
--short)
mode="short"
shift
;;
--no-header)
show_header="no"
shift
;;
--no-color)
use_color="no"
shift
;;
--json)
output_format="json"
shift
;;
--yaml)
output_format="yaml"
shift
;;
--fqdn)
use_fqdn="yes"
shift
;;
--hostname)
use_fqdn="no"
shift
;;
--help | -h)
print_usage
exit 0
;;
*)
args+=("$1")
shift
;;
esac
done
# Get host info
fqdn=$(get_fqdn "$use_fqdn")
ip=$(get_primary_ip)
[[ "$show_header" == "yes" && "$mode" == "default" ]] && {
echo "fqdn=${fqdn}"
echo "ip=${ip}"
echo
}
# Output collection for JSON/YAML
entries=()
file_count=0
total_size=0
for file in "${args[@]}"; do
if [[ -e "$file" ]]; then
((file_count++))
file_info=$(get_file_info "$file" "$include_md5")
abs_path="$(cut -d'|' -f1 <<<"$file_info")"
size_bytes=$(du -b --apparent-size --max-depth=0 "$file" | cut -f1)
total_size=$((total_size + size_bytes))
case "$output_format" in
json | yaml) entries+=("$file_info") ;;
*)
case "$mode" in
default) output_default_mode "$fqdn" "$ip" "$file_info" "$use_color" ;;
short) output_short_mode "$fqdn" "$file_info" ;;
scp) output_scp_mode "$user" "$fqdn" "$file" ;;
vim-url) output_vim_url_mode "$user" "$fqdn" "$file" ;;
esac
echo
;;
esac
else
echo "Error: '$file' does not exist." >&2
fi
done
# Output JSON or YAML if requested
if [[ "$output_format" == "json" ]]; then
print_json_output "${entries[@]}"
elif [[ "$output_format" == "yaml" ]]; then
print_yaml_output "${entries[@]}"
fi
# Summary if default mode
if [[ "$mode" == "default" && $file_count -gt 1 ]]; then
total_size_hr=$(numfmt --to=iec --suffix=B "$total_size")
echo "Summary:"
echo "- $file_count file(s)"
echo "- Total size: $total_size_hr"
fi