-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvit.go
86 lines (68 loc) · 1.97 KB
/
vit.go
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
// vit is a simple and tiny filesystem navigator
package main
import (
"fmt"
"log"
"os"
)
const conf = "/.vitconfig"
func check(e error) {
if e != nil {
panic(e)
}
}
func exitGracefully(msg string) {
fmt.Fprintln(os.Stderr, msg)
fmt.Fprintln(os.Stdout, ".")
os.Exit(1)
}
func main() {
args := os.Args[1:]
if len(args) == 0 {
printConfig()
os.Exit(0)
}
if len(args) == 1 && args[0] == "--help" {
fmt.Printf(`
vit is a tiny and simple filesystem navigation helper.
The term 'vit' is a play 'git' and 'vite', the French word for fast.
vit was initially imagined to help navigate amongst the may git repos scattered on the author's filesystem, but vite isn't git specific; it supports aliasing and navigating to any path.
The techical challenge with this idea is simply that no application may alter your shell's current path.
See 'you can do this' https://stackoverflow.com/questions/52435908/how-to-change-the-shells-current-working-directory-in-go
This tool's solution is to combine the 'vit' bin with a tiny bash function 'vd' which combines 'vit' and 'cd'.
--help : view this message\n
vit init -> create a vit config file (typically ~/.vit/config)\n
vit list -> list current config\n
`)
}
if len(args) == 1 && args[0] == "init" {
path := getConfPath()
if f, _ := os.Stat(path); f != nil {
fmt.Printf("%s: File already exists. Skipping\n", path)
os.Exit(0)
}
createVitConfig()
os.Exit(0)
}
if len(args) == 3 && args[0] == "alias" && args[1] == "get" {
getAliasPath(args[2])
os.Exit(0)
}
if len(args) == 3 && args[0] == "alias" && args[1] == "rm" {
removeAlias(args[2])
os.Exit(0)
}
if len(args) == 3 && args[0] == "alias" && args[1] == "add" {
addAliasCurrentPath(args[2])
os.Exit(0)
}
if len(args) == 4 && args[0] == "alias" && args[1] == "add" {
addAliasNamedPath(args[2], args[3])
os.Exit(0)
}
if len(args) == 1 {
getAliasPath(args[0])
os.Exit(0)
}
log.Fatal(fmt.Errorf("cmd: invalid arguments"))
}