-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.fish
286 lines (236 loc) · 6.7 KB
/
config.fish
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
bind \cd delete-char
if type -q rbenv
rbenv init - | source
end
if type -q salias
salias __init__ | source
end
# Disable package suggestion.
function fish_command_not_found
__fish_default_command_not_found_handler $argv
end
function ngrok
command ngrok $argv -config $XDG_CONFIG_HOME/ngrok2/ngrok.yml
end
function search
if _is_git_repo
git ls-files --exclude-standard -o -c | xargs ls -d 2>/dev/null
else
find . -type f
end | xargs grep --color $argv
end
if not functions -q _orig_cd
functions -c cd _orig_cd
end
function cd
if count $argv >/dev/null
if test -e $argv || test $argv = -
echo $argv
else
z -l $argv 2>&1 | begin
read -l line
and if string match -q -r '^common:' "$line"
read -l line
and echo $line
else
echo $line
cat
end
end | awk '{ print $2 }'
end
else
echo $HOME
z -l | awk '{ print $2 }'
end | sed '/^$/d' | fzf -1 | read -l p
and _orig_cd $p
end
function _is_git_repo
git rev-parse --is-inside-work-tree >/dev/null 2>/dev/null
end
function _is_git_dirty
set -l stat (git status --porcelain=v2)
test -n "$stat"
end
function _git_branch_name
git symbolic-ref --short HEAD 2>/dev/null
end
function _fish_right_prompt_branch_name
if _is_git_repo
_is_git_dirty
and set color (set_color bryellow)
or set color (set_color 88f)
echo -n "$color"(_git_branch_name)
end
end
function _fish_right_prompt_repo_info
echo -n ' '(set_color cyan)(prompt_pwd)
end
function fish_right_prompt
_fish_right_prompt_branch_name
_fish_right_prompt_repo_info
end
function gcd
find (ghq root) -maxdepth 4 -type d -name .git -printf '%P\n' | xargs -n1 dirname | fzf | read -l p
and cd (ghq root)/$p
end
function ctf
chromix-too ls | fzf | awk '{print $0}' | xargs chromix-too focus
end
function nvo
if test -d $argv
read -P'It\'s directory. Sure? ' a
and test "$a" = 'y'
or return
end
nvc ex e (realpath $argv)
end
function nvcd
realpath $argv |read p
nvc ex cd $p
end
function pd
z -l $argv | sed '$d' | awk '{ print $2 }' | fzf -1
end
function pf
find ~ | fzf -q $argv -1
end
function gbf
git branch | awk '{ print $NF }' | fzf
end
function memo
twty -a privmagu $argv >/dev/null
end
function gdb
command gdb -nh -x $XDG_CONFIG_HOME/gdb/init $argv
end
function fish_prompt
set last_status $status
test $last_status = 0
and set_color cyan
or set_color yellow
echo -n -s ' ❯'(set_color cyan)'❯ '(set_color normal)
end
# Configurations for plugins
# async-prompt
set -g async_prompt_functions fish_right_prompt
function fish_right_prompt_loading_indicator -a last_prompt
echo -n "$last_prompt" | sed -r 's/[[:cntrl:]]\[[0-9]{1,3}m//g' | read -zl uncolored_last_prompt
echo -n (set_color brblack)"$uncolored_last_prompt"(set_color normal)
end
function _fish_right_prompt_repo_info_loading_indicator
echo (set_color '#aaa')' … '(set_color normal)
end
function git
if test -z "$argv"
command git
return
end
switch $argv[1]
case push
set -l ghuser acomagu
if test -z (git remote)
and git rev-parse --show-toplevel | sed 's|^'(ghq root)"/github.com/$ghuser/\(.*\)\$|\1|" | read -l dirname
and read -P"Set [email protected]:$ghuser/$dirname as origin remote branch? [Y/n]: " -l ans
and contains "$ans" y Y ''
command git remote add origin [email protected]:$ghuser/$dirname
end
set -l head
if not string join \n -- $argv | sed 1d | grep -E '^[^-]' >/dev/null
and command git status -b --porcelain=v2 | grep -E 'upstream|head' | cut -d' ' -f3 | begin
read head
and not read -l upstream
end
and command git remote get-url origin >/dev/null
and read -P"Set origin/$head as the upstream branch? [Y/n]: " -l ans
and contains "$ans" y Y ''
command git $argv -u origin $head
else
command git $argv
end
case add
command git $argv
and command git status
case chb
git branch --sort=-committerdate --color | fzf --reverse --ansi | awk '{ print $NF }' | xargs git checkout
case '*'
command git $argv
end
end
function yay
if test -z "$argv"
command yay --sudoloop -Syu
end
command yay --sudoloop $argv
end
function genid
python3 -c "import string,random;print(''.join(random.choices(string.ascii_uppercase+string.ascii_lowercase+string.digits,k=3)))"
end
function hugo
set -l cmd $argv[1]
switch "$cmd"
case new
set -l cmd $argv[2]
switch "$cmd"
case image
set -l id $argv[3]
set -l path $argv[4]
set -l ext (echo $path | awk -F. '{ print $NF }')
set -l fname (genid).$ext
mkdir -p static/assets/$id
and cp $path static/assets/$id/$fname
and echo "![](/assets/$id/$fname)"
return
end
end
command hugo $argv
end
function goinstall
if test $GO111MODULE != on
echo 'GO111MODULE is not on' >&2
return 1
end
set -l mod
if test (count $argv) -ge 1
set mod $argv
else
set mod (pwd | sed -n 's|.*\(github.com/[^/]\+/[^/]\+\).*|\1|p')
end
if test (count $mod) -ne 1
echo "Could not determine the module name: $mod" >&2
return 1
end
set -l prodrt "$GHQ_ROOT/$mod"
test -e $prodrt/go.mod || echo "module $mod" > $prodrt/go.mod
echo "
cd $prodrt
go install
" | fish
end
function goget
ghq get -p --shallow https://$argv
goinstall $argv
end
function encode-uri
if test -z "$argv"
cat
else
echo $argv
end | python3 -c "import urllib.parse;print(urllib.parse.quote(input()))"
end
function youtube-dl
command youtube-dl --no-mtime $argv
end
function diff
git diff --no-index $argv
end
function sshfs
command sshfs -o reconnect,ServerAliveInterval=15,ServerAliveCountMax=1 $argv
end
function switch-insomnia-conf
set -l confs $XDG_CONFIG_HOME/Insomnia-*
string join \n $confs | fzf --height=10 | read -l selection
test -z "$selection"
and return 1
rm -rf "$XDG_CONFIG_HOME/Insomnia"
cp -r "$selection" "$XDG_CONFIG_HOME/Insomnia"
end