File tree Expand file tree Collapse file tree 1 file changed +49
-0
lines changed Expand file tree Collapse file tree 1 file changed +49
-0
lines changed Original file line number Diff line number Diff line change
1
+ package backup
2
+
3
+ import (
4
+ "os"
5
+ "strings"
6
+ )
7
+
8
+ var DotfilePaths = []string {
9
+ "~/.bashrc" ,
10
+ "~/.zshrc" ,
11
+ "~/.vimrc" ,
12
+ "~/.config" ,
13
+ "~/.bash_history" ,
14
+ "~/.zsh_history" ,
15
+ "~/.gitconfig" ,
16
+ "~/.profile" ,
17
+ "~/.npmrc" ,
18
+ }
19
+
20
+ type Dotfile struct {
21
+ Path string
22
+ Found bool
23
+ }
24
+
25
+ // Expand ~ to home directory
26
+ func expandHome (path string ) string {
27
+ if strings .HasPrefix (path , "~" ) {
28
+ if home , err := os .UserHomeDir (); err == nil {
29
+ return strings .Replace (path , "~" , home , 1 )
30
+ }
31
+ }
32
+ return path
33
+ }
34
+
35
+ // Check which dotfiles exist
36
+ func CheckDotfiles () ([]Dotfile , error ) {
37
+ var result []Dotfile
38
+
39
+ for _ , rawPath := range DotfilePaths {
40
+ fullPath := expandHome (rawPath )
41
+
42
+ _ , err := os .Stat (fullPath )
43
+ result = append (result , Dotfile {
44
+ Path : fullPath ,
45
+ Found : err == nil ,
46
+ })
47
+ }
48
+ return result , nil
49
+ }
You can’t perform that action at this time.
0 commit comments