This repository has been archived by the owner on Jan 22, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: abstract the fs.Walk to an Apply/Unapply action
- Loading branch information
1 parent
c33383e
commit 3288fe9
Showing
10 changed files
with
87 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package actions | ||
|
||
import ( | ||
"github.com/eankeen/dotty/fs" | ||
) | ||
|
||
// Apply (symlink) dotfiles | ||
func Apply(dotDir string, srcDir string, destDir string) { | ||
onFile := func(src string, dest string, rel string) { | ||
fs.ApplyFile(src, dest, rel) | ||
} | ||
|
||
onFolder := func(src string, dest string, rel string) { | ||
fs.ApplyFolder(src, dest, rel) | ||
} | ||
|
||
fs.Walk(dotDir, srcDir, destDir, onFile, onFolder) | ||
} | ||
|
||
// Unapply (un-symlink) dotfiles | ||
func Unapply(dotDir string, srcDir string, destDir string) { | ||
onFile := func(src string, dest string, rel string) { | ||
fs.UnapplyFile(src, dest, rel) | ||
} | ||
|
||
onFolder := func(src string, dest string, rel string) { | ||
fs.UnapplyFolder(src, dest, rel) | ||
} | ||
|
||
fs.Walk(dotDir, srcDir, destDir, onFile, onFolder) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package actions | ||
|
||
import ( | ||
"os" | ||
"os/exec" | ||
|
||
"github.com/eankeen/dotty/internal/util" | ||
) | ||
|
||
// OpenEditor opens a file for editing | ||
func OpenEditor(file string) { | ||
editor := os.Getenv("EDITOR") | ||
program := "vim" | ||
if editor != "" { | ||
program = editor | ||
} | ||
|
||
cmd := exec.Command(program, file) | ||
cmd.Stdin = os.Stdin | ||
cmd.Stdout = os.Stdout | ||
cmd.Stderr = os.Stderr | ||
|
||
err := cmd.Run() | ||
util.HandleError(err) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters