Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ The aim of this project is to make the `code` cli available to _any_ terminal, n
- **Python 3**
> Tested under Python 3.6 and Python 3.8, but should work fine in Python 3.5 or newer.
- **socat** - used for pinging UNIX sockets
```bash
```sh
apt-get install socat
```

Expand Down Expand Up @@ -59,24 +59,24 @@ fisher update chvolkmann/code-connect
fisher remove chvolkmann/code-connect
```

### Bash
### POSIX-compliant shells (bash, dash, etc.)

#### Installing & Updating

With [`bash/install.sh`](./bash/install.sh)
With [`shell/install.sh`](./shell/install.sh)

```bash
curl -sS https://raw.githubusercontent.com/chvolkmann/code-connect/main/bash/install.sh | bash
```sh
sh -c "$(curl -sSLo- https://raw.githubusercontent.com/chvolkmann/code-connect/main/shell/install.sh)"
```

This downloads [`code_connect.py`](./bin/code_connect.py) along with two scripts and sets up aliases in your `.bashrc` for you. See [`bash/code.sh`](./bash/code.sh) and [`bash/code-connect.sh`](./bash/code-connect.sh)
This downloads [`code_connect.py`](./bin/code_connect.py) along with two scripts and sets up aliases in your `.bashrc` for you. See [`shell/code.sh`](./shell/code.sh) and [`shell/code-connect.sh`](./shell/code-connect.sh)

#### Uninstalling

With [`bash/uninstall.sh`](./bash/uninstall.sh)
With [`shell/uninstall.sh`](./shell/uninstall.sh)

```bash
curl -sS https://raw.githubusercontent.com/chvolkmann/code-connect/main/bash/uninstall.sh | bash
```sh
sh -c "$(curl -sSLo- https://raw.githubusercontent.com/chvolkmann/code-connect/main/shell/uninstall.sh)"
```

Deletes the aliases from `~/.bashrc` and removes the folder `~/.code-connect`
Expand Down Expand Up @@ -130,15 +130,15 @@ You can verify this by opening a connection to your remote machine. In one case,

Run

```bash
```sh
echo $VSCODE_IPC_HOOK_CLI
```

which displays an output in the integrated terminal, but not on the other one.

In order, every socket is checked to see if it is listening. For this, the following snippet based on [this answer on StackOverflow](https://unix.stackexchange.com/a/556790) was used.

```bash
```sh
socat -u OPEN:/dev/null UNIX-CONNECT:/path/to/socket
```

Expand Down
8 changes: 0 additions & 8 deletions bash/code-connect.sh

This file was deleted.

68 changes: 0 additions & 68 deletions bash/uninstall.sh

This file was deleted.

2 changes: 1 addition & 1 deletion conf.d/code-connect.fish
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

function _on_code-connect_install --on-event code-connect_install
mkdir -p ~/.code-connect/bin
curl -sS "https://raw.githubusercontent.com/chvolkmann/code-connect/main/bin/code_connect.py" >~/.code-connect/bin/code_connect.py
curl -sSL "https://raw.githubusercontent.com/chvolkmann/code-connect/main/bin/code_connect.py" >~/.code-connect/bin/code_connect.py
chmod +x ~/.code-connect/bin/code_connect.py
end

Expand Down
9 changes: 9 additions & 0 deletions shell/code-connect.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env sh

# https://github.com/chvolkmann/code-connect

# Use this script through an alias
# alias code-connect="/path/to/code-connect.sh"

code_connect_dir=$(CDPATH='' cd -- "$(dirname -- "$(dirname -- "$0")")" && pwd)
"$code_connect_dir/bin/code_connect.py" "$@"
7 changes: 4 additions & 3 deletions bash/code.sh → shell/code.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
#!/usr/bin/env sh

# https://github.com/chvolkmann/code-connect

Expand All @@ -8,8 +8,9 @@
local_code_executable="$(which code 2>/dev/null)"
if test -n "$local_code_executable"; then
# code is in the PATH, use that binary instead of the code-connect
$local_code_executable $@
"$local_code_executable" "$@"
else
# code not locally installed, use code-connect
~/.code-connect/bin/code_connect.py $@
code_connect_dir=$(CDPATH='' cd -- "$(dirname -- "$(dirname -- "$0")")" && pwd)
"$code_connect_dir/bin/code_connect.py" "$@"
fi
99 changes: 55 additions & 44 deletions bash/install.sh → shell/install.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
#!/usr/bin/env sh

# https://github.com/chvolkmann/code-connect

Expand All @@ -12,35 +12,28 @@ CODE_CONNECT_BASE_URL="https://raw.githubusercontent.com/chvolkmann/code-connect

# Fancy output helpers

c_cyan=`tput setaf 7`
c_red=`tput setaf 1`
c_magenta=`tput setaf 6`
c_grey=`tput setaf 8`
c_green=`tput setaf 10`
c_reset=`tput sgr0`
c_cyan="$(tput setaf 7)"
c_red="$(tput setaf 1)"
c_magenta="$(tput setaf 6)"
c_grey="$(tput setaf 8)"
c_green="$(tput setaf 10)"
c_reset="$(tput sgr0)"

c_fg="$c_cyan"
c_log="$c_grey"
c_err="$c_red"
c_emph="$c_magenta"
c_path="$c_green"

print () {
echo "$c_fg$@$c_reset"
}

log () {
echo "$c_log$@$c_reset"
}

error () {
echo "$c_err$@$c_reset"
}
print() ( IFS=" " printf "$c_fg%s$c_reset\n" "$*" )
print_n() ( IFS=" " printf "$c_fg%s$c_reset" "$*" )
log() ( IFS=" " printf "$c_log%s$c_reset\n" "$*" )
error() ( IFS=" " printf "$c_err%s$c_reset\n" "$*" >&2 )


# Helpers

download-repo-file () {
download_repo_file () {
repo_path="$1"
output_path="$2"
url="$CODE_CONNECT_BASE_URL/$repo_path"
Expand All @@ -49,7 +42,7 @@ download-repo-file () {
log "Downloading ${c_path}$repo_path${c_log} from ${c_path}$url"
fi

curl -sS -o "$output_path" "$url"
curl -sSL -o "$output_path" "$url"
ret="$?"
if test "$ret" != "0"; then
error "ERROR: Could not fetch ${c_path}$url${c_err}"
Expand All @@ -58,68 +51,86 @@ download-repo-file () {
fi
}

alias-exists () {
alias_exists () {
name="$1"
cat ~/.bashrc | grep -q "alias $name=*"
grep -q "alias $name=*" ~/.bashrc
}

ensure-alias () {
ensure_alias () {
name="$1"
val="$2"
if alias-exists "$name"; then
if alias_exists "$name"; then
log "Alias ${c_emph}$name${c_log} already registered in ${c_path}~/.bashrc${c_log}, skipping"
else
echo "alias $name='$val'" >> ~/.bashrc
log "Adding alias ${c_emph}$name${c_log} to ${c_path}~/.bashrc"
fi
}

ensure_aliases () {
code_sh_path="$1"
code_connect_sh_path="$2"
print_n "May I modify your ${c_path}~/.bashrc${c_fg}? [yN] "
read -r yn

case $yn in
[Yy]*)
# Add the aliases to ~/.bashrc if not already done
ensure_alias "code" "$code_sh_path"
ensure_alias "code-connect" "$code_connect_sh_path"

;;
*)
print "Okay; make sure to add the following to your shell-profile manually:"
print "alias code='$code_sh_path'"
print "alias code-connect='$code_connect_sh_path'"
;;
esac

printf \\n
}


#####


version=$(download-repo-file "VERSION" -)
print ""
version=$(download_repo_file "VERSION" -)
printf \\n
print "${c_emph}code-connect ${c_log}v$version"
print ""
printf \\n


# Download the required files from the repository

mkdir -p "$CODE_CONNECT_INSTALL_DIR/bin"

CODE_CONNECT_PY="$CODE_CONNECT_INSTALL_DIR/bin/code_connect.py"
download-repo-file "bin/code_connect.py" $CODE_CONNECT_PY
download_repo_file "bin/code_connect.py" $CODE_CONNECT_PY
chmod +x "$CODE_CONNECT_PY"

mkdir -p "$CODE_CONNECT_INSTALL_DIR/bash"
mkdir -p "$CODE_CONNECT_INSTALL_DIR/shell"

CODE_SH="$CODE_CONNECT_INSTALL_DIR/bash/code.sh"
download-repo-file "bash/code.sh" $CODE_SH
CODE_SH="$CODE_CONNECT_INSTALL_DIR/shell/code.sh"
download_repo_file "shell/code.sh" $CODE_SH
chmod +x "$CODE_SH"

CODE_CONNECT_SH="$CODE_CONNECT_INSTALL_DIR/bash/code-connect.sh"
download-repo-file "bash/code-connect.sh" $CODE_CONNECT_SH
CODE_CONNECT_SH="$CODE_CONNECT_INSTALL_DIR/shell/code-connect.sh"
download_repo_file "shell/code-connect.sh" $CODE_CONNECT_SH
chmod +x "$CODE_CONNECT_SH"

print ""


# Add the aliases to ~/.bashrc if not already done
ensure-alias "code" "$CODE_SH"
ensure-alias "code-connect" "$CODE_CONNECT_SH"
printf \\n

ensure_aliases "$CODE_SH" "$CODE_CONNECT_SH"

print ""
print "${c_emph}code-connect${c_fg} installed to ${c_path}$CODE_CONNECT_INSTALL_DIR${c_fg} successfully!"
print ""
printf \\n
print "Restart your shell or reload your ${c_path}.bashrc${c_fg} to see the changes."
print ""
printf \\n
print " ${c_emph}source ${c_path}.bashrc"
print ""
printf \\n


local_code_binary=$(which code)
local_code_binary="$(which code)"
if test -z "$local_code_binary"; then
print "Local installation of ${c_emph}code${c_fg} detected at ${c_path}$local_code_binary"
print "Use the ${c_emph}code${c_fg} executable as you would normally."
Expand Down
Loading