-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.zshrc
213 lines (168 loc) · 6.49 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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
zstyle ':zim:zmodule' use 'degit'
DEDUPE_PATH="$(printf %s "$PATH" | awk -v RS=: '{ if (!arr[$0]++) {printf("%s%s",!ln++?"":":",$0)}}')"
export PATH=$DEDUPE_PATH
bindkey '^A' beginning-of-line
bindkey '^E' end-of-line
ZIM_CONFIG_FILE=~/.config/zsh/zimrc
ZIM_HOME=~/.zim
# Get OS type using uname
OS_TYPE=$(uname)
# Check if the OS is Linux or macOS
if [[ "$OS_TYPE" == "Linux" ]]; then
export SSH_AUTH_SOCK="$XDG_RUNTIME_DIR/keyring/ssh"
export OPEN="xdg-open"
alias open="xdg-open"
elif [[ "$OS_TYPE" == "Darwin" ]]; then
export OPEN="open"
else
:
fi
#HISTORY
HISTFILE=~/.zsh_history
HISTSIZE=999999999
SAVEHIST=$HISTSIZE
setopt SHARE_HISTORY # all instances share the same history
setopt HIST_VERIFY # history expansion goes into the editor buffer first
setopt HIST_FIND_NO_DUPS # don't show dupes in history search
setopt HIST_IGNORE_SPACE # don't history commands beginning in space (consistent with bash)
setopt INTERACTIVE_COMMENTS # allow comments in the shell
setopt APPEND_HISTORY # Append new history to the file, instead of overwriting it.
setopt INC_APPEND_HISTORY # Add commands to the history file as they are executed.
setopt HIST_IGNORE_DUPS # Avoid duplicate entries in the history file.
setopt EXTENDED_HISTORY # Save timestamps in the history file.
autoload -U up-line-or-beginning-search
autoload -U down-line-or-beginning-search
zle -N up-line-or-beginning-search
zle -N down-line-or-beginning-search
bindkey "^[[A" up-line-or-beginning-search # Up
bindkey "^[[B" down-line-or-beginning-search # Down
bindkey -v
export KEYTIMEOUT=1
cursor_mode() {
# See https://ttssh2.osdn.jp/manual/4/en/usage/tips/vim.html for cursor shapes
cursor_block='\e[2 q'
cursor_beam='\e[6 q'
function zle-keymap-select {
if [[ ${KEYMAP} == vicmd ]] ||
[[ $1 = 'block' ]]; then
echo -ne $cursor_block
elif [[ ${KEYMAP} == main ]] ||
[[ ${KEYMAP} == viins ]] ||
[[ ${KEYMAP} = '' ]] ||
[[ $1 = 'beam' ]]; then
echo -ne $cursor_beam
fi
}
zle-line-init() {
echo -ne $cursor_beam
}
# Restore cursor to default on exit
reset_cursor() {
echo -ne '\e[0 q'
}
trap reset_cursor EXIT
zle -N zle-keymap-select
zle -N zle-line-init
}
cursor_mode
zmodload zsh/complist
bindkey -M menuselect 'h' vi-backward-char
bindkey -M menuselect 'k' vi-up-line-or-history
bindkey -M menuselect 'l' vi-forward-char
bindkey -M menuselect 'j' vi-down-line-or-history
# Download zimfw plugin manager if missing.
if [[ ! -e ${ZIM_HOME}/zimfw.zsh ]]; then
curl -fsSL --create-dirs -o ${ZIM_HOME}/zimfw.zsh \
https://github.com/zimfw/zimfw/releases/latest/download/zimfw.zsh
fi
# Install missing modules and update ${ZIM_HOME}/init.zsh if missing or outdated.
if [[ ! ${ZIM_HOME}/init.zsh -nt ${ZIM_CONFIG_FILE:-${ZDOTDIR:-${HOME}}/.zimrc} ]]; then
source ${ZIM_HOME}/zimfw.zsh init -q
fi
source ${ZIM_HOME}/init.zsh
# Enable Powerlevel10k instant prompt with quiet mode to reduce console output
typeset -g POWERLEVEL9K_INSTANT_PROMPT=quiet
# Enable Powerlevel10k instant prompt. Should stay close to the top of ~/.zshrc.
if [[ -r "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh" ]]; then
source "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh"
fi
[[ ! -f ~/.p10k.zsh ]] || source ~/.p10k.zsh
# export LANG=en_US.UTF-8
# Preferred editor for local and remote sessions
if [[ -n $SSH_CONNECTION ]]; then
export EDITOR='vim'
else
export EDITOR='nvim'
fi
if command -v direnv &> /dev/null
then
source <(direnv hook zsh)
fi
# Only add this if you have the plugin installed
if [ -f $HOME/.config/tmux/plugins/tmux-git-autofetch/git-autofetch.tmux ]; then
tmux-git-autofetch() {($HOME/.config/tmux/plugins/tmux-git-autofetch/git-autofetch.tmux --current &)}
add-zsh-hook chpwd tmux-git-autofetch
fi
# TMUX
export XDG_CONFIG_HOME="$HOME/.config"
alias rclone_config='rclone config reconnect GDrive: --auto-confirm'
alias vimv='vimv -e nvim'
# Finished adapting your PATH environment variable for use with MacPorts.
#PATH="\$PATH:/Applications/Visual Studio Code.app/Contents/Resources/app/bin"
#export VIM=~/.config/nvim
alias vi="nvim -c 'if filereadable(\"Session.vim\") | source Session.vim | endif'"
alias vim="nvim -c 'if filereadable(\"Session.vim\") | source Session.vim | endif'"
# # Added DBUS for vim zathura integration
# # Creates problems in the nixos login
# export DBUS_SESSION_BUS_ADDRESS="unix:path=$DBUS_LAUNCHD_SESSION_BUS_SOCKET"
alias h='cd ~'
alias o="fzf -m | xargs -I % $OPEN %"
alias f="fzf | xargs -I % $OPEN -R %"
alias cl='clear'
alias ta='tmux attach'
alias c='dir=$(fzf | xargs -I {} dirname "{}") && cd "$dir"'
alias t="tree -d -L 7| grep --color="never" -E '── \d\d-'"
if command -v brew &> /dev/null; then
alias upgrade_apps='brew upgrade --cask --no-quarantine --greedy'
fi
if [[ "$OS_TYPE" == "Darwin" ]]; then
alias flushdns='sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder'
alias finderhide='defaults write com.apple.finder CreateDesktop -bool false; killall Finder'
alias findershow='defaults write com.apple.finder CreateDesktop -bool true; killall Finder'
fi
alias passg='pass generate'
alias passc='pass edit'
alias ga='git commit --amend'
alias dump_all='find . -type d -name .git -prune -o -type f -print | while read file; do echo "== $file =="; cat "$file"; echo ""; done'
function dump_files() {
for file in "$@"; do
[[ -f "$file" ]] && echo "== $file ==" && /bin/cat "$file" && echo ""
done
}
# check if bat is installed
if command -v bat &> /dev/null; then
alias cat='bat'
fi
if command -v automator &> /dev/null; then
wallpaper () { automator -i "${1}" ~/.Workflows/SetWallpaper.workflow }
fi
wttr () { curl wttr.in/$1 }
cheat() { curl cheat.sh/$1 }
_fzf_complete_pass() {
_fzf_complete +m -- "$@" < <(
local prefix
prefix="${PASSWORD_STORE_DIR:-$HOME/.password-store}"
command find -L "$prefix" \
-name "*.gpg" -type f | \
sed -e "s#${prefix}/\{0,1\}##" -e 's#\.gpg##' -e 's#\\#\\\\#' | sort
)
}
# Check if the `pass` command successfully retrieves the API key
if api_key=$(pass show api-key/anthropic 2>/dev/null); then
export ANTHROPIC_API_KEY="$api_key"
fi
if api_key=$(pass show api-key/oco 2>/dev/null); then
export OCO_API_KEY="$api_key"
fi
[ -f $HOME/.bindkey.zsh ] && source $HOME/.bindkey.zsh
# zvm_after_init_commands+=('[ -f $HOME/.bindkey.zsh ] && source $HOME/.bindkey.zsh')