-
Notifications
You must be signed in to change notification settings - Fork 0
/
startup.nu
92 lines (75 loc) · 2.45 KB
/
startup.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
def "config directory" [] { config path | path dirname }
def edit [
filepath: path # Path to file
--editor (-e): string # Use a different editor (default is `$nu.env.EDITOR`)
] {
let editor = (if $editor != "" { $editor } { $nu.env.EDITOR });
^$editor $filepath
}
def "config edit" [
--editor (-e): string # Use a different editor (default is `$nu.env.EDITOR`)
] {
let editor = (if $editor != "" { $editor } { $nu.env.EDITOR })
edit (config path)
}
def "config explorer" [] {
^explorer (config directory)
}
def "startup" [] { help startup }
def "startup path" [] { config path | path dirname | append startup.nu | path join }
def "startup edit" [
--editor (-e): string # Use a different editor (default is `$nu.env.EDITOR`)
] {
let editor = (if $editor != "" { $editor } { $nu.env.EDITOR })
edit (startup path)
}
def "optionals directory" [] {
(config directory | path join optional)
}
def optionals [] {
echo $"Allowed optionals:(char nl)"
ls $"(optionals directory)/*.nu" | get name | path basename | str find-replace ".nu" "" | each { |s| $" - ($s)" } | str collect (char nl)
}
def "optionals edit" [
name: string # name of optional file
--editor (-e): string # Use a different editor (default is `$nu.env.EDITOR`)
] {
let editor = (if $editor != "" { $editor } { $nu.env.EDITOR });
let filepath = (optionals directory | path join $"($name).nu")
edit $filepath
}
let-env CONFIG_DIRECTORY = (config directory)
def numbered [] {
each --numbered { [[num]; [$it.index]] | merge {$it.item} }
}
def replicate [
str: string # Text to repeat
count: int # Repeat count
] {
"" | str lpad -c $"($str)" -l $count
}
alias style_red_bold = ansi -e '31;1m'
alias style_purple_underline = ansi -e '35;4m'
alias style_white_italic = ansi -e '97;3m'
alias style_clear = ansi -e '0m'
def error [
title:any
message:any
] {
echo $"(style_red_bold)[ERORR](style_clear) (style_purple_underline)($title):(style_clear) (style_white_italic)($message)(style_clear)"
}
# copy unicode character into clipboard
def uniclip [
hex: string # Unicode hex number (2FF0)
] {
char -u $hex | clip
}
def base64 [
--decode(-d) # decode base64
] {
if ($decode | empty?) {
python -c "import base64,sys; sys.stdout.buffer.write(base64.b64encode(sys.stdin.buffer.read()))"
} {
python -c "import base64,sys; sys.stdout.buffer.write(base64.b64decode(sys.stdin.buffer.read()))"
}
}