forked from emmercm/dotfiles
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.10_macos.bash
executable file
·106 lines (85 loc) · 2.94 KB
/
.10_macos.bash
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
if [[ "${OSTYPE:-}" != "darwin"* ]]; then
return 0
fi
##### Homebrew #####
if [[ ! -x "$(command -v brew)" && -f /opt/homebrew/bin/brew ]]; then
eval "$(/opt/homebrew/bin/brew shellenv)"
fi
if [[ -x "$(command -v brew)" ]]; then
brew() {
if [[ "${1:-}" == "purge" ]]; then
brew list | xargs command brew uninstall --force
brew list --cask | xargs command brew uninstall --force
return
fi
command brew "$@"
}
fi
##### App installs #####
# Homebrew packages
if [[ -x "$(command -v brew)" ]]; then
command -v gawk > /dev/null || brew install gawk
command -v gdate > /dev/null || brew install coreutils
command -v gsed > /dev/null || brew install gnu-sed
command -v jq > /dev/null || brew install jq
command -v rename > /dev/null || brew install rename
command -v tree > /dev/null || brew install tree
command -v watch > /dev/null || brew install watch
command -v wget > /dev/null || brew install wget
if [[ ! -x "$(command -v hstr)" ]]; then
brew install hstr
hstr --show-configuration >> ~/.bashrc
fi
fi
# App store applications
if [[ -x "$(command -v brew)" && ! -x "$(command -v mas)" ]]; then
brew install mas
# Installed applications aren't enumerated immediately, `mas list` may return nothing
fi
# if [[ -x "$(command -v mas)" ]]; then
# mas_list=$(mas list)
# # 1Password for Safari
# # echo "${mas_list}" | grep '^1569813296 ' &> /dev/null || mas install 1569813296
# # Menu World Time
# # echo "${mas_list}" | grep '^1446377255 ' &> /dev/null || mas install 1446377255
# fi
# macOS DNS flush
flush() {
sudo dscacheutil -flushcache
sudo killall -HUP mDNSResponder
}
##### Aliases #####
# Prefer GNU's coreutils binaries
command -v gdate > /dev/null && alias date="gdate"
command -v gsed > /dev/null && alias sed="gsed"
# macOS has no `md5sum`, so use `md5` as a fallback
command -v md5sum > /dev/null || alias md5sum="md5"
# macOS has no `sha1sum`, so use `shasum` as a fallback
command -v sha1sum > /dev/null || alias sha1sum="shasum"
command -v sha256sum > /dev/null || alias sha256sum="shasum --algorithm 256"
alias dl="cd ~/Downloads"
alias dt="cd ~/Desktop"
alias lsports="sudo lsof -iTCP -sTCP:LISTEN -n -P"
alias lsp=lsports
# macOS has no `realpath` by default, so emulate it
# @link https://stackoverflow.com/a/18443300
command -v realpath > /dev/null || realpath() {
OURPWD=$PWD
cd "$(dirname "$1")" || return 1
LINK=$(readlink "$(basename "$1")")
while [ "$LINK" ]; do
cd "$(dirname "$LINK")" || return 1
LINK=$(readlink "$(basename "$1")")
done
REALPATH="$PWD/$(basename "$1")"
cd "$OURPWD" || return 1
echo "$REALPATH"
}
##### JetBrains #####
if [[ "$(mdfind -name 'kMDItemFSName == "IntelliJ IDEA.app"')" != "" ]]; then
intellij() {
open -na "IntelliJ IDEA.app" --args "$@"
}
alias ij=intellij
alias idea=intellij
fi