-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbookmark_for_dir.nu
52 lines (43 loc) · 1.13 KB
/
bookmark_for_dir.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
#!/usr/bin/env nu
let bookmark_file_dir = $"($env.HOME)/.config/bookmark_for_dir"
let bookmark_file = $"($bookmark_file_dir)/bookmark.json"
# add bookmark
def "bm -a" [desc: string] {
checkAndInitFile
let work_dir = (pwd)
open $bookmark_file | append [[desc path];[$desc $work_dir]] | collect | save -f $bookmark_file
echo 'SUCCESS'
}
def descList [] {
open $bookmark_file | get desc
}
def checkAndInitFile [] {
# create dir
if ($bookmark_file_dir | path exists) == false {
mkdir $bookmark_file_dir
}
if ($bookmark_file | path exists) == false {
# create file
touch $bookmark_file
}
}
# change dir by num
def --env "bm -c" [num: int] {
cd (open $bookmark_file | get path | get $num)
}
# delete bookmark
def "bm -d" [desc: string@descList] {
open $bookmark_file | where desc != $desc | collect | save -f $bookmark_file
open $bookmark_file
}
# manage bookmark, change dir(cd).
def --env bm [
desc?: string@descList # if input desc, will change dir.
] {
if ($desc == null) {
checkAndInitFile
open $bookmark_file
} else {
cd (open $bookmark_file | where desc == $desc | get path | get 0)
}
}