-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy paths
More file actions
executable file
·81 lines (75 loc) · 2 KB
/
s
File metadata and controls
executable file
·81 lines (75 loc) · 2 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
#!/usr/bin/env bash
#
# SSH wrapper with optional dotfiles bootstrapping.
# Uses Kitty SSH kitten when available, plain ssh otherwise.
#
# Usage: s [options] <host> [ssh args...]
set -e
usage() {
echo "Usage: s [options] <host> [ssh args...]"
echo ""
echo "SSH wrapper with optional dotfiles bootstrapping."
echo "Uses Kitty SSH kitten when available, plain ssh otherwise."
echo ""
echo "Options:"
echo " --install-dotfiles Install dotfiles (or update if already present)"
echo " --reinstall-dotfiles Delete existing dotfiles and reinstall from scratch"
echo " --update-dotfiles Pull latest changes and re-run install"
echo " -h, --help Show this help message"
}
action=""
args=()
for arg in "$@"; do
case "$arg" in
-h|--help) usage; exit 0 ;;
--install-dotfiles) action="install" ;;
--reinstall-dotfiles) action="reinstall" ;;
--update-dotfiles) action="update" ;;
--*) echo "Unknown option: $arg" >&2; usage >&2; exit 1 ;;
*) args+=("$arg") ;;
esac
done
set -- "${args[@]}"
if [ -z "$1" ]; then
usage >&2
exit 1
fi
case "$action" in
install)
ssh "$@" bash << 'EOF'
if [ -d ~/dotfiles ]; then
echo "Updating dotfiles..."
cd ~/dotfiles && bin/dotfiles update --minimal
else
echo "Installing dotfiles..."
git clone https://github.com/gideonshaked/dotfiles ~/dotfiles
cd ~/dotfiles && ./install --minimal
fi
EOF
;;
reinstall)
ssh "$@" bash << 'EOF'
echo "Reinstalling dotfiles..."
rm -rf ~/dotfiles
git clone https://github.com/gideonshaked/dotfiles ~/dotfiles
cd ~/dotfiles && ./install --minimal
EOF
;;
update)
ssh "$@" bash << 'EOF'
if [ -d ~/dotfiles ]; then
cd ~/dotfiles && bin/dotfiles update --minimal
else
echo "Dotfiles not installed on this host"
fi
EOF
;;
esac
if test "$TERM" = "xterm-kitty"; then
case "$1" in
shamir* | elkon*) ssh "$@" ;;
*) kitty +kitten ssh "$@" ;;
esac
else
ssh "$@"
fi