-
Notifications
You must be signed in to change notification settings - Fork 2
/
config.nu
405 lines (385 loc) · 12.1 KB
/
config.nu
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
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
#color config
$env.config.color_config.shape_internalcall = if TERMINUS_SUBLIME in $env {
"light_cyan_bold"
} else {
fg: "#00b7ff" attr: b
}
$env.config.color_config.shape_external = if TERMINUS_SUBLIME in $env {"xterm_skyblue2"} else {"#00b7ff"}
$env.config.color_config.shape_external_resolved = { fg: blue attr: b }
$env.config.color_config.filesize = {|e|
if $e == 0b {
'white'
} else if $e < 1mb {
'cyan'
} else if $e < 1gb {
'cyan_bold'
} else {
'blue'
}
}
#table config
$env.config.table.trim.wrapping_try_keep_words = false
$env.config.table.mode = if TERMINUS_SUBLIME in $env {"ascii_rounded"} else {"rounded"}
$env.config.table.show_empty = false
$env.config.table.trim = {
methodology: "truncating", # wrapping
wrapping_try_keep_words: true,
truncating_suffix: "❱" #...
}
#miscelaneous
$env.config.history.file_format = "sqlite"
$env.config.show_banner = false
$env.config.ls.clickable_links = false
$env.config.use_kitty_protocol = true
$env.config.recursion_limit = 500
$env.config.completions.algorithm = "prefix" #fuzzy
$env.config.completions.use_ls_colors = true
$env.config.float_precision = 4;
$env.config.filesize.metric = true
$env.config.cursor_shape.emacs = "blink_line"
$env.config.highlight_resolved_externals = true
#hooks
let hooks = {
pre_prompt: [
{||
$env.CLOUD = if $env.PWD =~ "rclone/" {
match ($env.PWD | split row "/rclone/" | get 1 | split row "/" | get 0) {
$s if ($s | str starts-with "g") => {"f2df"},
"onedrive" => {"f8c9"},
"photos" => {"fbdb"},
"yandex" => {"f662"},
"box" => {"f5d3"},
"mega" => {"e673"},
_ => {"f4ac"}
}
} else {
match (sys host | get name) {
$p if $p =~ "Debian*" => {"f306"},
"Windows" => {"f17a"},
"Ubuntu" => {"f31b"},
"CentOs" => {"f304"},
"RedHat" => {"ef5d"},
"Rocky Linux" => {"f32b"},
_ => {"e712"}
}
}
}
]
pre_execution: [
{||
#checking existence of data file
if not ("~/.autolister.json" | path expand | path exists) {
cp ($env.MY_ENV_VARS.linux_backup | path join autolister.json) ~/.autolister.json
}
#checking conditions
let interval = 24hr
let now = date now
let update = (open ~/.autolister.json | get updated | into datetime) + $interval < $now
let autolister_file = open ~/.autolister.json
if $update and ((sys host | get hostname) != "rayen") {
## list mounted drives and download directory
nu ($env.MY_ENV_VARS.nu_scripts | path join autolister.nu)
$autolister_file
| upsert updated $now
| save -f ~/.autolister.json
## update ip
print (echo $"(ansi -e { fg: '#00ff00' attr: b })getting device ips...(ansi reset)")
let host = (sys host | get hostname)
let ips_file = $env.MY_ENV_VARS.ips
let ips_content = open $ips_file
let ips = nu ($env.MY_ENV_VARS.nu_scripts | path join get-ips.nu)
$ips_content
| upsert $host ($ips | from json)
| save -f $ips_file
}
}
]
env_change: {
PWD: [
{|before, after|
#checking existence of data file
if not ("~/.pwd_sizes.json" | path expand | path exists) {
cp ($env.MY_ENV_VARS.linux_backup | path join pwd_sizes.json) ~/.pwd_sizes.json
}
#checking conditions
let interval = 12hr
let last_record = (open ~/.pwd_sizes.json | where directory == $env.PWD)
let now = (date now)
let not_update = (
if ($last_record | length) == 0 {
false
} else {
(($last_record | get updated | get 0 | into datetime) + $interval > $now)
}
)
let not_gdrive = not ($env.PWD =~ rclone)
#calculating pwd_size
let pwd_size = (
if ($last_record | length) == 0 and $not_gdrive {
du $env.PWD --exclude *rclone*
| get apparent
| get 0
| into string
| str replace " " ""
} else if $not_gdrive {
if $not_update {
$last_record | get size | get 0
} else {
du $env.PWD --exclude *rclone*
| get apparent
| get 0
| into string
| str replace " " ""
}
} else {
""
}
)
#seting up env var
$env.PWD_SIZE = $pwd_size
let pwd_file = open ~/.pwd_sizes.json
#updating data file
if ($last_record | length) == 0 and $not_gdrive {
$pwd_file
| append {directory: $env.PWD,size: $pwd_size, updated: $now}
| save -f ~/.pwd_sizes.json
} else if (not $not_update) and $not_gdrive {
$pwd_file
| where directory != $env.PWD
| append {directory: $env.PWD,size: $pwd_size, updated: $now}
| save -f ~/.pwd_sizes.json
}
},
{|before, after|
try {print (ls | sort-by -i type name | grid -c)}
},
{|_, after|
zoxide add -- $after
},
{
condition: {".autouse.nu" | path exists},
code: "source .autouse.nu"
},
{
condition: {"venv" | path exists},
code: "overlay use venv/bin/activate.nu"
},
{
condition: {".git" | path exists},
code: "$env.GIT_STATUS = if (git status -s | str length) > 0 {git status -s | lines | length} else {0}"
},
{
condition: {not (".git" | path exists)},
code: "$env.GIT_STATUS = 0"
}
]
}
display_output: {||
table
}
}
$env.config.hooks = $hooks
#menus
let new_menus_names = ["alias_menu" "my_history_menu"]
let menus = [ {
name: alias_menu
only_buffer_difference: false
marker: "👀 "
type: {
layout: columnar
columns: 1
col_width: 20
col_padding: 2
}
style: {
text: green
selected_text: green_reverse
description_text: yellow
}
source: { |buffer, position|
scope aliases
| where name == $buffer
| each { |it| {value: $it.expansion }}
}
},
{
name: my_history_menu
only_buffer_difference: false
marker: ''
type: { layout: ide }
style: {}
source: {|buffer, position|
{
# only history of current directory
value: (
atuin history list --reverse false --cwd --cmd-only --print0
| split row (char nul) | uniq
| par-each {$in | nu-highlight}
| str join (char nul)
| fzf --read0 --ansi -q $buffer --height 40%
| ansi strip
)
}
}
}
]
$env.config.menus = $env.config.menus | where name not-in $new_menus_names | append $menus
#keybindings
let new_keybinds_names = ["alias_menu"
"reload_config"
"update_right_prompt"
"insert_newline"
"insert_last_argument"
"insert_sudo"
"completion_menu"
"ide_completion_menu"
"copy_command"
"my_history_menu"
"change_dir_with_fzf"
"select_file_fzf"
"delete_one_word_backward"
]
let new_keybinds = [
{
name: alias_menu
modifier: alt
keycode: char_a
mode: [emacs, vi_normal, vi_insert]
event: [
{ send: menu name: alias_menu }
{ edit: insertchar, value: ' '}
]
},
{
name: reload_config
modifier: alt
keycode: char_x
mode: emacs
event: {
send: executehostcommand,
cmd: $"source ($nu.config-path)"
}
},
{
name: update_right_prompt
modifier: alt
keycode: char_p
mode: emacs
event: {
send: executehostcommand,
cmd: '$env.MY_ENV_VARS.l_prompt = if not ($env.MY_ENV_VARS | is-column l_prompt) {"short"} else if ($env.MY_ENV_VARS.l_prompt | is-empty) or ($env.MY_ENV_VARS.l_prompt == "short") {"long"} else {"short"}'
}
},
{
name: insert_newline
modifier: alt
keycode: enter
mode: emacs
event: { edit: insertnewline }
},
{
name: insert_last_argument
modifier: alt
keycode: char_i
mode: emacs
event: [{
edit: InsertString,
value: "!$"
},
{ send: Enter }]
},
{
name: insert_sudo
modifier: alt
keycode: char_s
mode: [emacs, vi_insert, vi_normal]
event: [
{ edit: MoveToStart }
{ edit: InsertString,
value: "sudo "
}
{ edit: MoveToEnd }
]
},
{
name: completion_menu
modifier: control
keycode: char_i
mode: [emacs vi_normal vi_insert]
event: {
until: [
{ send: menu name: completion_menu }
{ send: menunext }
{ edit: complete }
]
}
},
{
name: ide_completion_menu
modifier: none
keycode: tab
mode: [emacs vi_normal vi_insert]
event: {
until: [
{ send: menu name: ide_completion_menu }
{ send: menunext }
{ edit: complete }
]
}
},
{
name: copy_command
modifier: control_alt
keycode: char_c
mode: [emacs, vi_normal, vi_insert]
event: {
send: executehostcommand
cmd: "commandline | xsel --input --clipboard; commandline edit --append ' # copied'"
}
},
{
name: my_history_menu
modifier: alt
keycode: char_r
mode: [emacs, vi_insert, vi_normal]
event: { send: menu name: my_history_menu }
},
{
name: change_dir_with_fzf
modifier: alt
keycode: char_c
mode: emacs
event: {
send: executehostcommand,
cmd: "cd (ls | where type == dir | each { |it| $it.name | str prepend (ansi -e { fg: '#5555FF' attr: b})} | input list -f (echo-g 'Select dir:'))"
}
},
{
name: select_file_fzf
modifier: alt
keycode: char_f
mode: emacs
event: [
{
send: executehostcommand
cmd: "let file = ls | where type == file | sort-by name | get name | input list -f (echo-g 'Select file:');commandline edit --append $'`($file)`';commandline set-cursor --end"
}
]
},
{
name: delete_one_word_backward
modifier: alt
keycode: backspace
mode: [emacs, vi_insert, vi_normal]
event: { edit: backspaceword }
}
]
$env.config.keybindings = $env.config.keybindings | where name not-in $new_keybinds | append $new_keybinds
#for fun
# try {
# if (random bool) {
# print (http get -H ["Accept" "text/plain"] https://icanhazdadjoke.com)
# } else {
# print (http get https://api.chucknorris.io/jokes/random).value
# }
# }