-
Notifications
You must be signed in to change notification settings - Fork 0
/
forward-ports
50 lines (35 loc) · 1.51 KB
/
forward-ports
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
#!/bin/bash
set -e
trap "trap - SIGTERM && kill -- -$$" SIGINT SIGTERM EXIT
CODESPACE=$(gh cs list | grep Available | tail -n 1 | cut -f1)
# Sync any command history
gh cs -c $CODESPACE cp -e 'remote:$HOME/.zsh_history' /tmp/codespace_zsh_history
touch $HOME/codespace_zsh_history
REMOTE_WC=$(wc -l /tmp/codespace_zsh_history | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//' | cut -d' ' -f1)
LOCAL_WC=$(wc -l $HOME/codespace_zsh_history | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//' | cut -d' ' -f1)
echo "REMOTE_WC: $REMOTE_WC"
echo "LOCAL_WC: $LOCAL_WC"
if [ "$REMOTE_WC" -gt "$LOCAL_WC" ]; then
echo "Downloaded remote command history"
cp -f /tmp/codespace_zsh_history $HOME/codespace_zsh_history
else
echo "Uploaded command history"
gh cs -c $CODESPACE cp -e $HOME/codespace_zsh_history 'remote:$HOME/.zsh_history'
fi
# To set up the ssh config, put something like this in ~/.ssh/config
# Match all
# Include ~/.ssh/codespaces
# And create a file called ~/.ssh/codespaces.template with this content
#Host codespace
# User vscode
# ProxyCommand /usr/bin/gh cs ssh -c CODESPACENAME --stdio --
# UserKnownHostsFile=/dev/null
# StrictHostKeyChecking no
# LogLevel quiet
# ControlMaster auto
# and you can install lemonade with
# go install github.com/lemonade-command/lemonade@latest
cat ~/.ssh/codespaces.template | sed "s/CODESPACENAME/$CODESPACE/g" > ~/.ssh/codespaces
ssh -NT -R 2489:localhost:2489 codespace -o ExitOnForwardFailure=yes &
lemonade server &
gh cs -c $CODESPACE ports forward 80:7777