-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlast_copy
More file actions
executable file
·53 lines (38 loc) · 1000 Bytes
/
Copy pathlast_copy
File metadata and controls
executable file
·53 lines (38 loc) · 1000 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
45
46
47
48
49
50
51
52
53
#!/bin/bash
set -eou pipefail
CMD="${1:-default_fallback}"
CMD_ARGS="${2:-unknown}"
lookup() {
local file_path=""
file_path=$(_l)
local file_size=""
file_size=$(gstat --printf="%s" "$file_path")
file_size=$(echo "${file_size}" | awk '{ split( "B KB MB GB TB PB" , v ); s=1; while( $1>1024 ){ $1/=1024; s++ } printf "%.2f %s", $1, v[s] }')
local title="Copy $file_path"
local subtitle="Size: $file_size"
local output=""
output=$( jq -n \
--arg title "$title" \
--arg subtitle "$subtitle" \
--arg fp "$file_path" \
'{"items": [
{"title": $title, "subtitle": $subtitle, "arg": $fp }
]}' )
echo "$output"
}
run() {
local file_path="$1"
pbcopy < "$file_path"
}
case "$CMD" in
lookup)
lookup
;;
run)
run "$CMD_ARGS"
;;
*)
echo "Unknown build.sh command: '$CMD', exiting" >&2
exit 1
;;
esac