-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmenu_config.nu
137 lines (131 loc) · 3.22 KB
/
menu_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
# Example of a me.nu configuration inspired by Telescope.nvim
# Requirements:
# - ripgrep
# - fzf
# - bat
# - vim / micro (* for micro edit fzf-code last two lines)
# Cd directories using fzf and fd
def-env fzf-dir [] {(
(fd -d 4 -c always --type directory)
| (fzf --preview "fd -d 1 -c always . {}"
--ansi --layout reverse --tiebreak length,chunk)
| cd $in
)}
# Run ripgrep on the current folder, pipe it to fzf interactive
# and start the editor on the selected line
def fzf-code [
query: string = "." # Query
--type(-t): string # Filetype to search for
--type-not(-T): string # Filetype to exclude
--max-depth(-d): int = 5 # Max depth
--lines(-l): int = 20 # numer of lines to include in preview
] {
# Check if we are in a danger dir (slow or useless grep)
let pwd_len = $env.PWD | path split | length
if ($env.PWD == ("~" | path expand) or $pwd_len < 4) {
let v = (
[no yes]
| input list "You are grepping in ~, are you sure you want to do that?"
)
if ($v != "yes") { return }
}
# Parse flags
mut flags = []
if not ($type | is-empty) {
$flags ++= [-t $type]
}
if not ($type_not | is-empty) {
$flags ++= [-T $type_not]
}
# Ripgrep
( rg ($flags)
--line-number --with-filename --color=always
--field-match-separator ' ' --max-depth ($max_depth)
($query)
)
# Fzf + bat
| ( fzf --ansi
--preview-window 'up,60%,border-bottom,+{2}+3/3,~3'
--preview "bat --color always {1} --highlight-line {2}"
--exact
)
# Parse fzf out
| parse "{file} {line} {code}" | first
# Open editor
| vim $"+($in.line)" $in.file
# | micro -parsecursor true $"($in.file):($in.line)"
}
$env.nu_menu_commands = [
{
description: "Search Dir"
keymap: "sd"
command: { fzf-dir }
group: "Search"
}
{
description: "Search Code"
keymap: "sc"
command: { fzf-code }
group: "Search"
}
{
description: "Git Status"
keymap: "gs"
command: { git status }
group: "Git"
}
{
description: "Git Add Update"
keymap: "gau"
command: {git add --update}
group: "Git"
}
{
description: "Git Add All"
keymap: "gaa"
command: {git add --all}
group: "Git"
}
{
description: "Git Commit"
keymap: "gc"
command: {
print (git status)
input "Message: "
| git commit -m $in
}
group: "Git"
}
{
description: "Git Push"
keymap: "gp"
command: { git push }
group: "Git"
}
{
description: "Git pulL"
keymap: "gl"
command: { git pull }
group: "Git"
}
{
description: "Vim in Directory"
keymap: "vd"
command: { nvim . }
}
{
description: "Refresh nu"
keymap: "r"
command: { nu }
}
{
description: "Clear"
keymap: "c"
command: { clear }
}
{
description: "Hello"
keymap: "h"
command: { print "Hello" }
}
]