-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathc
More file actions
executable file
·96 lines (79 loc) · 2.16 KB
/
c
File metadata and controls
executable file
·96 lines (79 loc) · 2.16 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
#!/usr/bin/env bash
# Resolve the real script directory so config loading still works via symlink.
script_path="${BASH_SOURCE[0]}"
while [ -L "$script_path" ]; do
script_dir="$(cd -P "$(dirname "$script_path")" && pwd)"
script_path="$(readlink "$script_path")"
if [[ "$script_path" != /* ]]; then
script_path="${script_dir}/${script_path}"
fi
done
script_dir="$(cd -P "$(dirname "$script_path")" && pwd)"
# Load config file
config_file="${script_dir}/config.sh"
if [ -f "$config_file" ]; then
source "$config_file"
else
echo "Error: Config file not found: $config_file"
exit 1
fi
remote_host="${EASY_REMOTE_SSH_HOST:-$remote_host}"
editor="${EASY_REMOTE_SSH_EDITOR:-$editor}"
urlencode() {
local input="$1"
local output=""
local i char hex
for ((i = 0; i < ${#input}; i++)); do
char="${input:i:1}"
case "$char" in
[a-zA-Z0-9.~_-]|/)
output+="$char"
;;
*)
printf -v hex '%%%02X' "'$char"
output+="$hex"
;;
esac
done
printf '%s' "$output"
}
print_vscode_link() {
case "$editor" in
code)
local remote_uri
remote_uri="vscode://vscode-remote/ssh-remote+${remote_host}$(urlencode "$absolute_dir")"
printf '\e]8;;%s\a%s\e]8;;\a\n' "$remote_uri" "Open in VS Code"
;;
code-insiders)
local remote_uri
remote_uri="vscode-insiders://vscode-remote/ssh-remote+${remote_host}$(urlencode "$absolute_dir")"
printf '\e]8;;%s\a%s\e]8;;\a\n' "$remote_uri" "Open in VS Code Insiders"
;;
esac
}
# Check configuration variables
if [ -z "$remote_host" ]; then
echo "Error: Please set remote_host in config.sh file."
exit 1
fi
if [ -z "$editor" ]; then
echo "Error: Please set editor in config.sh file."
exit 1
fi
if [ -z "$1" ]; then
target_dir="."
else
target_dir="$1"
fi
if ! absolute_dir=$(cd "$target_dir" && pwd); then
echo "Error: Cannot access '$target_dir'"
exit 1
fi
remote_command="${editor} --remote ssh-remote+${remote_host} ${absolute_dir}"
# Copy to clipboard
printf "\033]52;c;%s\a" "$(printf "%s" "$remote_command" | base64 | tr -d '\r\n')"
echo
echo "$remote_command"
print_vscode_link
echo -e "\e[1;32mCopied to Clipboard!\e[0m"
echo