-
Notifications
You must be signed in to change notification settings - Fork 0
/
.zshrc
197 lines (152 loc) · 5.4 KB
/
.zshrc
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
# detect on which system we are running on (ubuntu or macos)
if [ -f /etc/os-release ]; then
source /etc/os-release
OS=$ID # ubuntu
elif [ -f /usr/bin/sw_vers ]; then
OS="macos"
fi
# Fig pre block. Keep at the top of this file.
[[ $OS == macos && -f "$HOME/.fig/shell/zshrc.pre.zsh" ]] && . "$HOME/.fig/shell/zshrc.pre.zsh"
# If you come from bash you might have to change your $PATH.
# export PATH=$HOME/bin:/usr/local/bin:$PATH
### ZNAP
# Download Znap, if it's not there yet.
[[ -f ~/.zsh-plugins/zsh-snap/znap.zsh ]] ||
git clone --depth 1 -- \
https://github.com/marlonrichert/zsh-snap.git ~/.zsh-plugins/zsh-snap
# Start Znap
source ~/.zsh-plugins/zsh-snap/znap.zsh
###
if [[ $OS == "macos" ]]; then
source ~/.zprofile
export PATH=/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
export PATH="$PATH:/Applications/Visual Studio Code.app/Contents/Resources/app/bin"
fi
znap source ohmyzsh/ohmyzsh
znap prompt spaceship-prompt/spaceship-prompt
# znap source zsh-users/zsh-completions
znap source zsh-users/zsh-autosuggestions
ZSH_HIGHLIGHT_HIGHLIGHTERS=(main brackets)
znap source zsh-users/zsh-syntax-highlighting
znap source supercrabtree/k
zstyle ':omz:update' mode disabled # managed by znap
omz_plugins=(
zsh-interactive-cd
git
npm
wp-cli
)
[[ $OS == "macos" ]] && omz_plugins+=(macos)
for plugin in "${omz_plugins[@]}"; do
znap source ohmyzsh/ohmyzsh plugins/$plugin
done
# export FZF_BASE=~[ohmyzsh/ohmyzsh]/plugins/fzf
[[ $OS == "macos" ]] && export EDITOR="code -w"
### HOMEBREW
case $OS in
macos)
znap eval brew-shellenv 'brew shellenv'
;;
ubuntu)
znap eval brew '/home/linuxbrew/.linuxbrew/bin/brew shellenv'
;;
esac
###
# https://github.com/roots/trellis-cli#virtualenv
znap eval trellis 'trellis shell-init zsh'
znap function _pyenv pyenv 'eval "$( pyenv init - --no-rehash )"'
compctl -K _pyenv pyenv
znap eval pip-completion 'pip completion --zsh'
# NVM
export NVM_COMPLETION=true
# export NVM_LAZY_LOAD=true
znap source lukechilds/zsh-nvm
if [[ $OS == macos ]]; then
# Home Assistant CLI
eval "$(_HASS_CLI_COMPLETE=source_zsh hass-cli)"
# use gnu-sed instead of the mac osx sed
alias sed=gsed
# Create a folder and move into it in one command
function mkcd() { mkdir -p "$@" && cd "$_"; }
# fd - cd to selected directory
fd() {
local dir
dir=$(find ${1:-.} -path '*/\.*' -prune \
-o -type d -print 2>/dev/null | fzf +m) &&
cd "$dir"
}
# fh - search in your command history and execute selected command
fh() {
eval $( ([ -n "$ZSH_NAME" ] && fc -l 1 || history) | fzf +s --tac | sed 's/ *[0-9]* *//')
}
alias g='git'
eval "$(op completion zsh)"
compdef _op op
alias sync='./sync.sh'
# =================== Spotify ===============================
# Spotify is supported using the OMZSH MacOS plugin. (using the official Spotify API)
# Raycast is also using the official API.
alias spp="spotify pause"
spotify() {
local track=$(spotify status track)
local artist=$(spotify status artist)
case "$1" in
show)
printf "%s\n" "$track ($artist)"
;;
search)
local search="$track $artist music"
google "$search"
;;
*)
printf "Usage: spotifyshow [show|search]"
;;
esac
}
bureau() {
# toggle the speaker in the office and automatally (un)switch the system audio device
# See: https://github.com/home-assistant-ecosystem/home-assistant-cli
# See: https://www.home-assistant.io/docs/scripts/service-calls/
[[ $OS != macos ]] && printf "ERROR: Your system is not supported. (%s)" "$OS" && return 1
BUREAU_SPEAKER_STATE="$(hass-cli --columns=state --no-headers state get switch.enceinte_bureau_salon)"
BUREAU_AUDIO_DEVICE="OWC Thunderbolt 3 Audio Device"
turn_on() {
printf '%s\n' 'turning the speaker on...'
hass-cli service call homeassistant.turn_on --arguments entity_id=switch.enceinte_bureau_salon >/dev/null
export BUREAU_CURRENT_AUDIO_DEVICE="$(SwitchAudioSource -c)"
printf "Switching device from %s to %s...\n" "$BUREAU_CURRENT_AUDIO_DEVICE" "$BUREAU_AUDIO_DEVICE"
SwitchAudioSource -f cli -s "$BUREAU_AUDIO_DEVICE" >/dev/null
}
turn_off() {
printf "%s\n" "turning the speaker off..."
hass-cli service call homeassistant.turn_off --arguments entity_id=switch.enceinte_bureau_salon >/dev/null
printf "Switching device from %s to %s...\n" "$BUREAU_AUDIO_DEVICE" "$BUREAU_CURRENT_AUDIO_DEVICE"
SwitchAudioSource -f cli -s "$BUREAU_CURRENT_AUDIO_DEVICE" >/dev/null
}
[[ $BUREAU_SPEAKER_STATE = off ]] && turn_on || turn_off
}
# GitHub
alias gho="gh repo view -w"
fi # end macos
# React
cra() {
if [ -z "${1// /}" ]; then
echo "No application name provided" >&2
return 1
else
npx create-react-app "$1"
fi
}
export ITERM_ENABLE_SHELL_INTEGRATION_WITH_TMUX=YES
znap eval iterm2 'curl -fsSL https://iterm2.com/shell_integration/zsh'
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # loads nvm bash_completion
# do not register commands preceded by a space
export HISTCONTROL=ignorespace
function forget() {
history -d $(history | awk 'END{print $1-1}')
}
# ==========================================================
# Fig post block. Keep at the bottom of this file.
[[ $OS == macos && -f "$HOME/.fig/shell/zshrc.post.zsh" ]] && . "$HOME/.fig/shell/zshrc.post.zsh"