-
Notifications
You must be signed in to change notification settings - Fork 0
/
.bashrc.osx
77 lines (72 loc) · 2.02 KB
/
.bashrc.osx
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
#!/bin/bash
# NOTE: This file is not loaded automatically, because it's not needed in ALL OS X installs, just on client machines (my notebook).
# It's recommended to load from .bashrc.local :
# . ~/.kkrc/.bashrc.osx
export PATH="/opt/homebrew/bin:/opt/homebrew/sbin:$PATH"
# NOTE: Use this if you can't add `IdentityAgent ~/.gnupg/S.gpg-agent.ssh` to your `.ssh/config`
#export SSH_AUTH_SOCK="/Users/$USER/.gnupg/S.gpg-agent.ssh"
# This is my preferred way of working with Ubuntu multipass on OS X.
function vm()
{
local name dir
case "$1" in
"ls" | "list" | "")
multipass list
;;
"stop")
while [ $# -gt 1 ]; do
shift
multipass stop "$1"
done
multipass list
;;
"rm" | "kill")
while [ $# -gt 1 ]; do
shift
multipass stop "$1"
multipass delete -v -p "$1"
done
multipass list
;;
"ip")
multipass info "$2" | grep '^IPv4' | awk '{print $2}'
;;
"ssh")
name="${2}"
shift; shift;
# NOTE: Using "ubuntu" user, because multipass's "mount" uses it.
# NOTE: Agent forwarding ON by default
ssh -A ubuntu@$(vm ip "${name}") "$@"
;;
*)
# Start a new VM
name="${1}"
dir="${2:-/Users/user/wrk}"
shift; shift;
# Sorry for identation, it's necessary because of the HEREDOC
eval "cat <<EOF
$(<~/.kkrc/other/cloud-config.multipass.yml)
EOF" | multipass launch --disk 10G --memory 2G --cloud-init - -v -n "${name}" "$@" 24.04
# Check if mount was already set up or not
if multipass info "$name" | grep "Mounts: *--"; then
multipass stop "$name" # Stop/start needed for native mount
multipass mount --type native "$dir" "$name:/persist"
multipass start "$name" # Stop/start needed for native mount
fi
tmux rename-window "${name}"
#multipass shell "${name}"
vm ssh "${name}"
;;
esac
}
# Get/set DNS on OS X
function dns()
{
if [ $# -eq 1 ]; then
networksetup -setdnsservers Wi-Fi "$1"
elif [ $# -eq 2 ]; then
networksetup -setdnsservers "$1" "$2"
fi
networksetup -getdnsservers Wi-Fi
}
#alias nets="networksetup -listallhardwareports"