/
.zshrc
138 lines (116 loc) · 3.77 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
source ~/.zshrc.private
function source_if_exists () {
[ -f "${1}" ] && source "${1}"
}
# source_if_exists "${HOME}/.nix-profile/share/zsh-vi-mode/zsh-vi-mode.plugin.zsh"
source_if_exists "${HOME}/.nix-profile/share/zsh-z/zsh-z.plugin.zsh"
source_if_exists "${HOME}/.fzf.zsh"
# sharing paths between vim and the shell.
export VIM_CWD_PATH='/tmp/vimcwd.path'
function vcd() cd $(cat $VIM_CWD_PATH)
# general
function ls () { $HOME/.nix-profile/bin/ls --group-directories-first --color $@ } # default to color ls.
# ranger
function ranger {
local IFS=$'\t\n'
local tempfile="$(mktemp -t tmp.XXXXXX)"
local ranger_cmd=(
command
ranger
--cmd="map Q chain shell echo %d > "$tempfile"; quitall"
)
${ranger_cmd[@]} "$@"
if [[ -f "$tempfile" ]] && [[ "$(cat -- "$tempfile")" != "$(echo -n `pwd`)" ]]; then
cd -- "$(cat "$tempfile")" || return
fi
command rm -f -- "$tempfile" 2>/dev/null
}
# nix
function nix-zsh () { nix-shell --command "zsh" $@ } # start nix-shell using zsh instead.
# docker
function dcu () { docker compose up }
function dcub () { docker compose up --build }
function dcrun () { docker compose run $@ }
# git
function g () { nvim -c "Git" -c "only" } # requires (n)vim `fugitive` plugin
function gs () { git stash }
function gsp () { git stash pop }
function gt { pushd $(git rev-parse --show-toplevel) } # goto root of git directory.
function GT { pushd $(git rev-parse --show-toplevel) }
# tree
function tree () { command tree -A -C --dirsfirst $@ }
function wtree () { command tree --prune -P "*.java" -I "build" -A -C $@ }
# gradle
function grr () gradle run $@
function grt () gradle test $@
function grtt () gradle test --tests $@
# clones todo repo if file doesn't exist.
function todo () {
if [ ! -d "${HOME}/Info" ]; then (
cd ${HOME}
mkdir -p "${HOME}/Info"
touch "${HOME}/Info/todo.md"
) fi
nvim ${HOME}/Info/todo.md
}
# change fzf default to use ripgrep
export FZF_DEFAULT_COMMAND="rg --glob '!*.git' --glob '!*.class' --glob '!*.jar' --glob '!*.java.html' --files --hidden"
function fzfd() dirname $(fzf $@)
# fix a color scheme issue i hated
export FZF_DEFAULT_OPTS=$FZF_DEFAULT_OPTS'
--color=bg+:-1
'
# pipe a standard `psql` query into `visidata` as a `csv` for better viewing.
function query {
QUERY=$1
dvs -c "\copy ($QUERY) TO STDOUT CSV HEADER" | vd -f csv
}
# when switching branches sometimes jdtls gets confused, cleaning quickly remedies this.
function clean_jdtls {
find . -name ".project" -or -name ".settings" -or -name 'profile-out' | xargs rm -rf
}
# prompt config
setopt prompt_subst
autoload -Uz vcs_info
zstyle ':vcs_info:*' enable git cvs svn
zstyle ':vcs_info:*' check-for-changes true
zstyle ':vcs_info:*' stagedstr "%f[%F{6}staged changes%f] "
zstyle ':vcs_info:*' unstagedstr "%f[%F{11}unstaged changes%f] "
zstyle ':vcs_info:*' actionformats \
'%F{7}%r.%s %f[%F{4}%b|%a%f] %c%u
'
zstyle ':vcs_info:*' formats \
'%F{7}%r.%s %f[%F{4}%b%f] %c%u
'
zstyle ':vcs_info:(sv[nk]|bzr):*' branchformat '%b%F{1}:%F{3}%r
'
# add new line after each command
precmd () {
vcs_info
echo " "
[ ! -z $IN_NIX_SHELL ] && echo '[nix-shell]'
}
PS1='${vcs_info_msg_0_}%f%n %2~ %F{4}> %f'
ZZ_DEFAULT_PROMPT=$PS1
function sp_default { export PS1="$ZZ_DEFAULT_PROMPT" }
function sp_level { export PS1="%n %${1}~ > " }
# vi mode cursors.
cursor_block="\033[2 q"
cursor_thin="\033[6 q"
# special zle functions.
zle-line-init () {
zle -K viins # starts new shell with insert mode active.
printf $cursor_thin
}
zle-keymap-select () {
case $KEYMAP in
vicmd) printf $cursor_block ;;
*) printf $cursor_thin ;;
esac
}
# set zle widgets.
zle -N zle-keymap-select
zle -N zle-line-init
bindkey -v
eval "$(direnv hook zsh)"
# vim: ft=zsh fdm=manual foldlevel=0