-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwormhole.plugin.zsh
executable file
·79 lines (62 loc) · 1.22 KB
/
wormhole.plugin.zsh
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
# Send given command via netcat
#
wormhole_send_command() {
RESPONSE=$(echo "$@" | netcat 127.0.0.1 5115 -w 1)
# if [ "[OK] " != "${RESPONSE:0:5}" ]; then
echo $RESPONSE
# fi
}
expl() {
wh explore $@
}
start() {
wh start $@
}
term() {
wh shell $@
}
wh() {
SUBCMD=$1
shift
PAYLOAD=""
if [ $# -gt 0 ]; then
PAYLOAD=$(realpath "$@")
fi
case $SUBCMD in
version | reload | exit)
wormhole_send_command "$SUBCMD"
;;
*)
wormhole_send_command "invoke $SUBCMD $PAYLOAD"
;;
esac
}
wormhole_send_pathargs_command() {
CMD=$1
shift
PAYLOAD=()
for f in "$@"; do
# If argument start with "-", treat is as option and keep unchanged
if [ '-' = ${f:0:1} ]; then
PAYLOAD+="$f"
continue;
fi
if [ -r "$f" ]; then
PAYLOAD+=($(realpath "$f"))
elif [ -d $(dirname "$f") ]; then
DIR=$(realpath $(dirname "$f"))
PAYLOAD+=($DIR/$(basename "$f"))
else
PAYLOAD+=($(realpath "$f"))
fi
done
wormhole_send_command "invoke ${CMD} ${PAYLOAD[@]}"
}
s() {
wormhole_send_pathargs_command sublime "$@"
}
code() {
wormhole_send_pathargs_command code "$@"
}
# Publicly export functions
export -f wh expl start term s code >/dev/null