-
Notifications
You must be signed in to change notification settings - Fork 0
/
.aliasrc
288 lines (249 loc) · 8.09 KB
/
.aliasrc
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
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
#!/usr/bin/env bash
# Jump Directories - could replace with zoxide
alias ....="cd ../../../"
alias ...="cd ../../"
alias ..="cd .."
alias finb="cd \$SRC/github.com/jeffwindsor/financials/gnucash/business/imports"
alias finh="cd \$SRC/github.com/jeffwindsor/financials/gnucash/home/imports"
alias hub="cd \$SRC/github.com"
alias icloud="cd \$HOME/Library/Mobile\\ Documents/com~apple~CloudDocs/Documents"
alias jeff="cd \$SRC/github.com/jeffwindsor/"
alias src="cd \$SRC && lla"
# package manager
if command -v brew &>/dev/null; then
function brew-list-all() {
echo '== Formula Leaves =='
brew leaves
echo
echo '== Casks =='
# -1 is to 'Force output to be one entry per line'
brew list -1 --casks
}
alias bi="brew info"
alias bl="brew-list-all"
alias blc="brew list --casks --versions"
alias blf="brew list --formula --versions"
alias bs="brew search"
alias bsd="brew search --desc"
alias bup="brew update && brew upgrade"
alias bx="brew autoremove"
if type fuzzy_brew_install >/dev/null; then
# requires fzf-brew zsh plugin or equivilant be installed
alias bn="fuzzy_brew_install"
alias brm="fuzzy_brew_uninstall"
alias bnc="fuzzy_cask_install"
alias brmc="fuzzy_cask_uninstall"
else
alias bn="brew install"
alias brm="brew remove" # same as uninstall or rm
fi
elif command -v nix &>/dev/null; then
# standard nix
alias ni="nix-env --install"
alias nl="nix-env -q"
alias nlg="nix-env --list-generations"
alias nr="nix-env --uninstall"
alias ns="nix-shell -p"
alias nup="nix-env --upgrade"
alias ngc="nix-store --gc"
# nix-darwin
if command -v darwin-rebuild &>/dev/null; then
alias ndr="darwin-rebuild build --flake $XDG_CONFIG_HOME/nix"
alias nds="nix run nix-darwin -- switch --flake ~/.config/nix"
fi
# nix-home-manager
# nixos
fi
if command -v asdf &>/dev/null; then
# Install one or more versions of specified language
asdf_add() {
local lang=${1}
if [[ ! $lang ]]; then
lang=$(asdf plugin-list | fzf)
fi
if [[ $lang ]]; then
local versions=$(asdf list-all $lang | fzf --tac --no-sort --multi)
if [[ $versions ]]; then
for version in $(echo $versions);
do; asdf install $lang $version; done;
fi
fi
}
# Remove one or more versions of specified language
asdf_rm() {
local lang=${1}
if [[ ! $lang ]]; then
lang=$(asdf plugin-list | fzf)
fi
if [[ $lang ]]; then
local versions=$(asdf list $lang | fzf -m)
if [[ $versions ]]; then
for version in $(echo $versions);
do; asdf uninstall $lang $version; done;
fi
fi
}
fi
# cat replacement (rust): https://github.com/sharkdp/bat
if command -v bat &>/dev/null; then
alias cat="bat --style=plain"
fi
# ls replacement (rust): https://github.com/eza-community/eza
if command -v eza &>/dev/null; then
alias l="eza -F --group-directories-first"
alias la="eza -F --group-directories-first --git --all"
alias ll="eza -lF --group-directories-first"
alias lla="eza -lF --group-directories-first --git --all"
alias tree="eza --tree --git"
alias treea="eza --tree --git --all"
alias treed="eza --tree --git --level"
else
alias l="ls"
alias la="ls -a"
alias ll="ls -l"
alias lla="ls -la"
fi
# bling: https://github.com/fastfetch-cli/fastfetch
if command -v fastfetch &>/dev/null; then
alias ff="fastfetch"
fi
# fuzzy finder: https://github.com/junegunn/fzf
if command -v fzf &>/dev/null; then
function wezterm-theme() {
local color_scheme=$(fzf <"$XDG_CONFIG_HOME"/wezterm/color_schemes.txt)
# if color_scheme was selected, change the wezterm config file colorscheme value
[ -n "$color_scheme" ] && sd '^config.color_scheme.*$' "config.color_scheme = '${color_scheme}'" "$XDG_CONFIG_HOME"/wezterm/wezterm.lua
}
alias theme="wezterm-theme"
# prompt user to select from list of git directories under $2 and if user selects one, execute command $1 on it
function exec-on-git-repos() {
local root_folder="$2"
local exec_command="$1"
# find list of directories containing a .git subfolder, presumably a repo
local git_repos=$(fd '^.git$' "$root_folder" -HItd --max-depth 4 | sed 's/.git\/$//' | fzf --reverse)
[ -n "$git_repos" ] && "$exec_command" "$git_repos"
}
alias hubs="exec-on-git-repos cd \$SRC/github.com/ && lla"
alias srcd="exec-on-git-repos cd \$SRC && lla"
alias srcs=srcd
alias srcv="exec-on-git-repos cd \$SRC && nvim ."
alias ten="cd $SRC/github.com/steveshogren/10-minute-vim-exercises/ && fzf | xargs nvim && cd -"
alias startpage="cd $SRC/github.com/jeffwindsor/startpage/ && nvim index.html && cd -"
fzf_rg() {
if [ ! "$#" -gt 0 ]; then
echo "Need a string to search for!";
return 1;
fi
# if FZF_PREVIEW_WINDOW is undefined, quoting it breaks the script
rg --files-with-matches --no-messages "$1" | fzf --preview-window "$FZF_PREVIEW_WINDOW" --preview "rg --ignore-case --pretty --context 10 '$1' {}"
}
fi
# Source Control: https://github.com/git/git
if command -v git &>/dev/null; then
# used at work because there is a limit on how many pulls per sec
function git-rec() {
for d in */; do
echo "==> $d"
sleep 5
cd ./$d
git pull
cd ..
done
}
alias gclean="git clean -xdf"
alias gs="git status"
alias gpl="git pull"
# git blame (more precise)
alias gb="git blame -w -C -C -C"
# git blame line range
alias gbl="git blame -w -C -C -C -L"
# git diff by words changed
alias gdw="git diff --word-diff"
alias gm="git maintenance start"
# git clone from git hub to my source directory
function ghub() { git clone [email protected]:"$1" "$SRC"/github.com/"$1"; }
# git clone from git hub to my source directory
function glab() { git clone [email protected]:"$1" "$SRC"/gitlab.cj.dev/"$1"; }
fi
# editor: https://github.com/helix-editor/helix
if command -v hx &>/dev/null; then
alias h="hx"
fi
if command -v lazygit &>/dev/null; then
alias gg="lazygit"
alias lg="lazygit"
fi
# editor: https://github.com/neovim/neovim
if command -v nvim &>/dev/null; then
alias v="nvim"
alias vim=v
alias vi=v
alias v.="nvim ."
function fuzzy-search-dotfiles() {
yadm list -a | sd "^" "$HOME/" | rg -v -e "$HOME/$" | fzf --query ${1:-""} | xargs nvim
}
alias vd="fuzzy-search-dotfiles"
alias dots="fuzzy-search-dotfiles"
function fuzzy-search-neovim-config() {
cd $XDG_CONFIG_HOME/nvim/lua/plugins
fzf --query ${1:-""} | xargs nvim
cd -
}
alias vdn="fuzzy-search-neovim-config"
alias dotsn="fuzzy-search-neovim-config"
alias ve="nvim $HOME/portable/exocortex"
alias vf="nvim -c \":Telescope find_files cwd=\$HOME/portable/financials\""
function nvim-clean-caches() {
rm -rf "$HOME"/.local/share/nvim
rm -rf "$HOME"/.local/state/nvim
rm -rf "$HOME"/.cache/nvim
}
fi
if command -v zoxide &>/dev/null; then
eval "$(zoxide init zsh)"
fi
# GREP replacement: https://github.com/BurntSushi/ripgrep
if command -v rg &>/dev/null; then
alias grep="rg"
alias ar="alias | rg"
alias er="env | rg"
fi
# dotfiles: https://github.com/TheLocehiliosan/yadm
if command -v yadm &>/dev/null; then
alias da="yadm add"
alias daa="yadm add -u" #stage modified and deletions
alias dg="cd && yadm enter lazygit && cd -"
alias ds="yadm status -sb --ignore-submodules"
alias dpl="yadm pull"
alias ya="yadm add"
alias yaa="yadm add -u" #stage modified and deletions
alias yg="cd && yadm enter lazygit && cd -"
alias ys="yadm status -sb --ignore-submodules"
alias ypl="yadm pull"
fi
# tui file manager: https://github.com/sxyazi/yazi
if command -v yazi &>/dev/null; then
alias f="yy"
alias f.="yazi"
# shell wrapper that will change to the selected directory on exit
function yy() {
local tmp="$(mktemp -t "yazi-cwd.XXXXX")"
yazi "$@" --cwd-file="$tmp"
if cwd="$(cat -- "$tmp")" && [ -n "$cwd" ] && [ "$cwd" != "$PWD" ]; then
cd -- "$cwd"
fi
rm -f -- "$tmp"
}
fi
function exec-in-subdirs() {
for d in */; do
cd ./$d
echo "=== Executing $1 on $(pwd)"
eval "$1"
cd ..
done
}
# source machine specific aliases
if test -f $HOME/.aliasrc.local; then
source $HOME/.aliasrc.local
fi