-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathxclip-cmd
More file actions
executable file
·75 lines (66 loc) · 2.26 KB
/
xclip-cmd
File metadata and controls
executable file
·75 lines (66 loc) · 2.26 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
#!/usr/bin/env bash
#
# ############################################################################
# Project: scripts (none)
# File...: xclip-cmd
# Created: Wednesday, 2021/01/27 - 10:46:26
# Author.: @fbnmtz, (devel.fgm@gmail.com)
# ~·~·~·~·~·~·~·~·~·~·~·~·~~·~·~·~·~·~·~·~·~·~·~·~·~~·~·~·~·~·~~·~·~·~·~·~·~·~
# Last Modified: Saturday, 2025/02/22 - 11:35:32
# Modified By..: @fbnmtz, (fabiano.matoz@gmail.com)
# ~·~·~·~·~·~·~·~·~·~·~·~·~~·~·~·~·~·~·~·~·~·~·~·~·~~·~·~·~·~·~~·~·~·~·~·~·~·~
# Version: 0.3.2.221
# ~·~·~·~·~·~·~·~·~·~·~·~·~~·~·~·~·~·~·~·~·~·~·~·~·~~·~·~·~·~·~~·~·~·~·~·~·~·~
# Description:
# > https://unix.stackexchange.com/questions/61183/bash-script-that-reads-filenames-from-a-pipe-or-from-command-line-args
# ############################################################################
# HISTORY:
#
# ~·~·~·~·~·~·~·~·~·~·~·~·~~·~·~·~·~·~·~·~·~·~·~·~·~~·~·~·~·~·~
# shellcheck disable=SC1090,SC2154
source "$xSHELL_INIT"
use args colors
xrequirements "xclip|pbcopy tee"
# xarg --id -s,--silent --desc "disable notifications"
xarg --id -p,--paste --desc "paste clipboard content"
xarg --header "clipboard command line for Linux/Darwin (command | $APP)"
xrun --xversionrc --xapp-data "$@"
declare -a ARGS=("$@")
_data(){
local arg data
# format an array with received args
# ex:
# seq 1 3 | xclip-cmd foo bar baz
# ARGS=([0]="foo" [1]="bar" [2]="baz" [3]="1" [4]="2" [5]="3")
# while read -rt .02 arg; do
while read -r arg; do
ARGS+=($arg)
done
# join all args to pass everything to xclip
for arg in "${ARGS[@]}"; do
case "$arg" in
# -s|--silent) ;;
-p|--paste ) ;;
*) data+="$arg "
esac
done
echo -n $data
}
case "$(xsys.os)" in
Linux )
_cmd_="xclip -selection primary|secondary|clipboard"
xcase p "_cmd_='xclip -out'"
;;
Darwin)
_cmd_=pbcopy
xcase p "xrequirements pbpaste; _cmd_=pbpaste"
;;
esac
if [ "$xarg" == "p" ]; then
output=$($_cmd_)
echo "$output"
else
output=$(_data "$@")
echo -n "$output" | $_cmd_
echo "$output" | tee -a "$APP_HOME"/clipboard
fi