-
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: add more installers and uninstallers
- Loading branch information
1 parent
a1e5ee0
commit 30cd7bb
Showing
15 changed files
with
182 additions
and
145 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,29 @@ | ||
APP_NAME := dotfiles-cli | ||
|
||
GOBASE := $(shell pwd) | ||
GOBIN := $(GOBASE)/bin | ||
GOFILES := $(wildcard *.go) | ||
|
||
GOCMD := go | ||
GOBUILD := $(GOCMD) build | ||
GOCLEAN := $(GOCMD) clean | ||
GOINSTALL := $(GOCMD) install | ||
|
||
BINARY_NAME := $(GOBIN)/$(APP_NAME) | ||
|
||
.PHONY: all build clean install | ||
|
||
all: build | ||
|
||
build: | ||
$(GOBUILD) -o $(BINARY_NAME) -v | ||
|
||
clean: | ||
$(GOCLEAN) | ||
rm -f $(BINARY_NAME) | ||
|
||
install: | ||
$(GOINSTALL) | ||
|
||
run: build | ||
$(BINARY_NAME) |
Binary file not shown.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,60 @@ | ||
package dotfiles | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"path" | ||
|
||
utils "github.com/pablobfonseca/dotfiles-cli/src" | ||
"github.com/pablobfonseca/dotfiles-cli/src/utils" | ||
"github.com/vbauerster/mpb/v7" | ||
"github.com/vbauerster/mpb/v7/decor" | ||
) | ||
|
||
var emacsConfigPath = path.Join(os.Getenv("HOME"), ".emacs.d") | ||
|
||
func InstallEmacs(p *mpb.Progress) { | ||
installEmacs := p.AddBar(100, | ||
mpb.PrependDecorators( | ||
decor.Name("Installing emacs", decor.WC{W: len("Installing emacs") + 1, C: decor.DidentRight}), | ||
), | ||
mpb.AppendDecorators( | ||
decor.OnComplete(decor.EwmaETA(decor.ET_STYLE_GO, 60), "done"), | ||
), | ||
) | ||
|
||
if err := utils.ExecuteCommand("brew", "--cask", "install", "emacs"); err != nil { | ||
fmt.Println("Error installing emacs:", err) | ||
if emacsInstalled() { | ||
utils.SkipMessage("Emacs is already installed") | ||
} else { | ||
installEmacsBar := utils.NewBar("Installing emacs", 1, p) | ||
|
||
if err := utils.ExecuteCommand("brew", "install", "--cask", "emacs"); err != nil { | ||
utils.ErrorMessage("Error installing emacs symlink", err) | ||
} | ||
installEmacsBar.Increment() | ||
|
||
} | ||
|
||
if utils.DirExists(emacsConfigPath) { | ||
utils.SkipMessage("Emacs folder already exists") | ||
return | ||
} | ||
installEmacs.Increment() | ||
|
||
bar := p.AddBar(100, | ||
mpb.PrependDecorators( | ||
decor.Name("Symlinking emacs folder", decor.WC{W: len("Symlinking emacs folder") + 1, C: decor.DidentRight}), | ||
), | ||
mpb.AppendDecorators( | ||
decor.OnComplete(decor.EwmaETA(decor.ET_STYLE_GO, 60), "done"), | ||
), | ||
) | ||
|
||
src := path.Join(os.Getenv("HOME"), ".dotfiles", "emacs.d") | ||
dest := path.Join(os.Getenv("HOME"), ".emacs.d") | ||
if err := os.Symlink(src, dest); err != nil { | ||
fmt.Println("Error creating symlink:", err) | ||
|
||
cloningBar := utils.NewBar("Cloning emacs files", 1, p) | ||
utils.InfoMessage("Emacs directory does not exists, cloning...") | ||
if err := utils.ExecuteCommand("git", "clone", "/~https://github.com/pablobfonseca/emacs.d", emacsConfigPath); err != nil { | ||
utils.ErrorMessage("Error cloning the repository", err) | ||
} | ||
cloningBar.Increment() | ||
} | ||
|
||
func UninstallEmacs(p *mpb.Progress) { | ||
if !emacsInstalled() { | ||
utils.SkipMessage("Emacs is not installed") | ||
return | ||
} | ||
bar.Increment() | ||
|
||
uninstallBar := utils.NewBar("Uninstalling emacs", 2, p) | ||
|
||
if err := utils.ExecuteCommand("brew", "uninstall", "emacs"); err != nil { | ||
utils.ErrorMessage("Error uninstalling emacs", err) | ||
} | ||
uninstallBar.Increment() | ||
|
||
if err := utils.ExecuteCommand("rm", "-rf", emacsConfigPath); err != nil { | ||
utils.ErrorMessage("Error removing emacs files", err) | ||
} | ||
uninstallBar.Increment() | ||
} | ||
|
||
func emacsInstalled() bool { | ||
return utils.DirExists(path.Join("/Applications", "Emacs.app")) | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,27 @@ | ||
package dotfiles | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"path" | ||
|
||
utils "github.com/pablobfonseca/dotfiles-cli/src" | ||
"github.com/pablobfonseca/dotfiles-cli/src/utils" | ||
"github.com/vbauerster/mpb/v7" | ||
"github.com/vbauerster/mpb/v7/decor" | ||
) | ||
|
||
func CloneRepo(p *mpb.Progress) { | ||
bar := p.AddBar(100, | ||
mpb.PrependDecorators( | ||
decor.Name("Cloning repository", decor.WC{W: len("Cloning") + 1, C: decor.DidentRight}), | ||
), | ||
mpb.AppendDecorators( | ||
decor.OnComplete(decor.EwmaETA(decor.ET_STYLE_GO, 60), "done"), | ||
), | ||
) | ||
bar := utils.NewBar("Cloning dotfiles repo", 1, p) | ||
|
||
if err := utils.ExecuteCommand("git", "clone", "/~https://github.com/pablobfonseca/dotfiles.git", path.Join(os.Getenv("HOME"), ".dotfiles")); err != nil { | ||
fmt.Println("Error cloning the repository:", err) | ||
return | ||
if err := utils.ExecuteCommand("git", "clone", utils.DotfilesRepo, path.Join(os.Getenv("HOME"), ".dotfiles")); err != nil { | ||
utils.ErrorMessage("Error cloning the repository", err) | ||
} | ||
bar.Increment() // 100 % since cloning is done | ||
bar.Increment() | ||
} | ||
|
||
func DeleteRepo(p *mpb.Progress) { | ||
bar := utils.NewBar("Deleting dotfiles repo", 1, p) | ||
|
||
if err := utils.ExecuteCommand("rm", "-rf", path.Join(os.Getenv("HOME"), ".dotfiles")); err != nil { | ||
utils.ErrorMessage("Error deleting the repository", err) | ||
} | ||
bar.Increment() | ||
} |
Oops, something went wrong.