-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmyfunctions.sh
190 lines (168 loc) · 4.46 KB
/
myfunctions.sh
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
#!/bin/bash
# Default opts that set the dracula fzf color theme
#export FZF_DEFAULT_OPTS='--color=fg:#f8f8f2,bg:#282a36,hl:#bd93f9 --color=fg+:#f8f8f2,bg+:#44475a,hl+:#bd93f9 --color=info:#ffb86c,prompt:#50fa7b,pointer:#ff79c6 --color=marker:#ff79c6,spinner:#ffb86c,header:#6272a4 --height 80% --layout=reverse --border'
export FZF_DEFAULT_OPTS='--prompt="🔭 " --height 80% --layout=reverse --border'
# Default command
export FZF_DEFAULT_COMMAND='rg --files --no-ignore --hidden --follow --glob "!.git/" --glob "!node_modules/" --glob "!vendor/" --glob "!undo/" --glob "!plugged/"'
# Preview them using bat
export BAT_THEME='gruvbox-dark'
# TODO: make a function that does fzf at root of git project
#function gitHelper {
# # check if we are in a git project
# # https://stackoverflow.com/a/2180367
# git rev-parse --git-dir 2> /dev/null
#
# # this shows the directory for the root of the git local repo
# git rev-parse --show-toplevel | echo . | fd -t f | fzf;
#}
function displayFZFFiles {
echo $(fzf --preview 'bat --theme=gruvbox-dark --color=always --style=header,grid --line-range :400 {}')
}
function nvimGoToFiles {
nvimExists=$(which nvim)
if [ -z "$nvimExists" ]; then
return;
fi;
selection=$(displayFZFFiles);
if [ -z "$selection" ]; then
return;
else
nvim $selection;
fi;
}
function vimGoToFiles {
vimExists=$(which vim)
if [ -z "$vimExists" ]; then
return;
fi;
selection=$(displayFZFFiles);
if [ -z "$selection" ]; then
return;
else
if [ "$TERM" != "xterm-256color" ]; then
TERM="xterm-256color"
fi
vim $selection;
fi;
}
function displayRgPipedFzf {
echo $(rg . -n --glob "!.git/" --glob "!vendor/" --glob "!node_modules/" | fzf);
}
function nvimGoToLine {
nvimExists=$(which nvim)
if [ -z "$nvimExists" ]; then
return;
fi
selection=$(displayRgPipedFzf)
if [ -z "$selection" ]; then
return;
else
filename=$(echo $selection | cut -d: -f1)
line=$(echo $selection | cut -d: -f2)
nvim $(printf "+%s %s" $line $filename) +"normal zz^";
fi
}
function vimGoToLine {
vimExists=$(which vim)
if [ -z "$vimExists" ]; then
return;
fi
selection=$(displayRgPipedFzf)
if [ -z "$selection" ]; then
return;
else
filename=$(echo $selection | awk -F ':' '{print $1}')
line=$(echo $selection | awk -F ':' '{print $2}')
if [ "$TERM" != "xterm-256color" ]; then
TERM="xterm-256color";
fi;
vim $(printf "+%s %s" $line $filename) +"normal zz";
fi
}
function fdFzf {
fdExists=$(which fd)
if [ -z "$fdExists" ]; then
return;
else
if [ "$(pwd)" = "$HOME" ]; then
goTo=$(fd -t d -d 1 . | fzf)
if [ -z "$goTo" ]; then
return;
else
cd $goTo
return;
fi
fi
goTo=$(fd -t d . | grep -vE '(node_modules)' | fzf)
if [ -z "$goTo" ]; then
return;
else
cd $goTo
fi
fi
}
function tmuxAttachFZF {
tmuxExists=$(which tmux)
if [ -z "$tmuxExists" ]; then
return;
fi
sessions=$(tmux ls)
if [ -z "$sessions" ]; then
return;
fi
selectedSession=$(echo $sessions | awk -F ':' '{print $1}' | fzf)
if [ -z "$selectedSession" ]; then
return;
fi
tmux attach -t $selectedSession;
}
function tmuxKillFZF {
tmuxExists=$(which tmux)
if [ -z "$tmuxExists" ]; then
return;
fi
sessions=$(tmux ls)
if [ -z "$sessions" ]; then
return;
fi
selectedSession=$(echo $sessions | awk -F ':' '{print $1}' | fzf)
if [ -z "$selectedSession" ]; then
return;
fi
tmux kill-session -t $selectedSession;
}
function lvimGoToFiles {
lvimExists=$(which nvim)
if [ -z "$lvimExists" ]; then
return;
fi;
selection=$(displayFZFFiles);
if [ -z "$selection" ]; then
return;
else
lvim $selection;
fi;
}
function lvimGoToLine {
lvimExists=$(which lvim)
if [ -z "$lvimExists" ]; then
return;
fi
selection=$(displayRgPipedFzf)
if [ -z "$selection" ]; then
return;
else
filename=$(echo $selection | awk -F ':' '{print $1}')
line=$(echo $selection | awk -F ':' '{print $2}')
lvim $(printf "+%s %s" $line $filename) +"normal zz";
fi
}
alias vf='vimGoToFiles'
alias nf='nvimGoToFiles'
alias ngl='nvimGoToLine'
alias vgl='vimGoToLine'
alias fzd='fdFzf'
alias ta='tmuxAttachFZF'
alias tk='tmuxKillFZF'
alias lf='lvimGoToFiles'
alias lgl='lvimGoToLine'