Skip to content

Commit

Permalink
[scripts] ,remote-workspace: few cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
meain committed Feb 17, 2024
1 parent 61d5e97 commit f442b0a
Showing 1 changed file with 24 additions and 13 deletions.
37 changes: 24 additions & 13 deletions scripts/.local/bin/random/,remote-workspace
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,29 @@ set -e
TNAME="$(pwd | xargs basename)"
IGNORE_STRING=""

echo Navigating to project root : "$(git rev-parse --show-toplevel 2>/dev/null)"
cd "$(git rev-parse --show-toplevel 2>/dev/null)"

# git status --ignored|grep -E '^\s'|grep -v '^ ('|sed 's|\s||'>.rworkspaceignore
if [ -f .rworkspaceignore ]; then
IGNORE_STRING="$(sed '/^\ *$/d;s|^|--exclude |' .rworkspaceignore | tr '\n' ' ')"
IGNORE_STRING="$(sed '/^\ *$/d;s|^|--exclude |' .rworkspaceignore | tr '\n' ' ')"
elif [ -f .dockerignore ]; then
IGNORE_STRING="$(sed '/^\ *$/d;s|^|--exclude |' .dockerignore | tr '\n' ' ')"
IGNORE_STRING="$(sed '/^\ *$/d;s|^|--exclude |' .dockerignore | tr '\n' ' ')"
elif [ -f .gitignore ]; then
IGNORE_STRING="$(sed '/^\ *$/d;s|^|--exclude |' .gitignore | tr '\n' ' ')"
fi

[ "$1" = "shell" ] &&
ssh "$EXPERIMENT_VM" -t "cd workspace/$TNAME && bash" && exit 0

[ "$1" = "web" ] && sed -n "/Host $EXPERIMENT_VM/,/^$/p" ~/.ssh/config |
grep HostName | awk '{print $2}' | xargs -I{} open "http://{}" && exit 0
if [ "$1" = "shell" ]; then
ssh "$EXPERIMENT_VM" -t "cd workspace/$TNAME && bash"
exit 0
elif [ "$1" = "nix" ]; then
ssh "$EXPERIMENT_VM" -t "cd workspace/$TNAME && bash -ic nix-shell"
exit 0
elif [ "$1" = "web" ]; then
sed -n "/Host $EXPERIMENT_VM/,/^$/p" ~/.ssh/config |
grep HostName | awk '{print $2}' | xargs -I{} open "http://{}"
exit 0
fi

# sync with deletion
[ "$1" = "dsync" ] && rsync -azvr --exclude '.git' $IGNORE_STRING . "$EXPERIMENT_VM:workspace/$TNAME" --delete && exit 0
Expand All @@ -27,13 +38,13 @@ fi
[ "$1" = "sync" ] && exit 0

if [ "$1" = "run" ]; then
shift
ssh "$EXPERIMENT_VM" -t "cd workspace/$TNAME && bash -ic '$1'"
shift
ssh "$EXPERIMENT_VM" -t "cd workspace/$TNAME && bash -ic '$1'"
elif [ "$1" = "cnys" ]; then
# sync in reverse
rsync -azvr --exclude '.git' $IGNORE_STRING "$EXPERIMENT_VM:workspace/$TNAME/" .
# sync in reverse
rsync -azvr --exclude '.git' $IGNORE_STRING "$EXPERIMENT_VM:workspace/$TNAME/" .
elif [ "$1" = "csync" ]; then
find . | entr rsync -azvr --exclude '.git' $IGNORE_STRING . "$EXPERIMENT_VM:workspace/$TNAME"
find . | entr rsync -azvr --exclude '.git' $IGNORE_STRING . "$EXPERIMENT_VM:workspace/$TNAME"
else
ssh "$EXPERIMENT_VM" -t "cd workspace/$TNAME && bash"
ssh "$EXPERIMENT_VM" -t "cd workspace/$TNAME && bash"
fi

0 comments on commit f442b0a

Please sign in to comment.