terminalio

package
v0.0.0-...-46b9f05 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 16, 2023 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package terminalio handles interaction with the command line.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddDotfile

func AddDotfile(userspaceFile, userspaceHomedir, dotfilesDir string) error

Copies file from userspace to the dotfiles directory and creates symlink from userspace file into the newly copied file in the dotfiles dirctory. The identical relative path is used for both 'homeDir' and 'dotfilesDir'.

func CheckIfFileExists

func CheckIfFileExists(absPath string) (bool, error)

Checks if file exists by trying to open it. The given path should be absolute or relative to dotf executable. An error is returned if the file does not exist.

func CopyExternalDotfile

func CopyExternalDotfile(fpath, fromdir, todir string, confirm bool) (string, error)

Copies a file from an external location into current dotfiles directory. E.g. fromdir can be the root of another dotfiles directory and todir can be the path to current dotfiles root dir. Returns the path of the copied file. If confirm==true an empty string and an error containing the calucated path to the new dotfile are returned. If the file to be copied is a symlink, a symlink will be created in todir pointing back to the symlink in fromdir. This is to keep the semantics, that userspace links always point into their own dotfiles dir.

func FindCommonPathPrefix

func FindCommonPathPrefix(path1, path2 string) (string, error)

Finds common prefix of two already split strings. E.g. '/a/b/c' and '/a/b/c/d' gives 'a/b/c'.

func FindCommonPathSuffix

func FindCommonPathSuffix(path1, path2 string) (string, error)

Finds common suffix of two already split strings. E.g. '/a/b/c' and 'd/b/c' gives 'b/c'.

func GetAndValidateAbsolutePath

func GetAndValidateAbsolutePath(path string) (string, error)

Returns the absolute path from current directory or an error if the created path does not point to a file.

func InstallDotfile

func InstallDotfile(file, userspaceDir, dotfilesDir string, overwrite bool) error

Installs a dotfile into its relative equal location in userspace by way of a symlink in userspace pointing back to the file in dotfiles. The userspace file will be removed if 'overwrite' is true. Both the filepath inside dotfile as well as in userspace can be given.

func IsFileSymlink(file string) (bool, error)

IsFileSymlink returns true if the given path is an existing symlink.

func RevertDotfile

func RevertDotfile(file, userspaceDir, dotfilesDir string) error

Reverts the insertion of a file into the dotfiles directory and return it to its original location in userspace. The symlink is removed first. The operation can be applied both to the symlink in userspace and the actual file in the dotfiles directory.

func SyncLocalRemote

func SyncLocalRemote(repoPath string) error

SyncLocalRemote uses Git to update local and remote repository with newest changes from either place. The given path 'absPathToLocalRepo' must point to a directory initialized with git and with push/pull abilities to a remote. If it is not possible to merge changes or if a command fails in the shell, an error will be returned.

func UpdateSymlinks(userSpaceDir, dotfilesDir string) error

UpdateSymlinks walks over files and folders in the dotfiles dir, while updating their respective symlinks in userspace relative to the placement in the dotfiles directory. If a matching symlink is not found in userspace, the file is ignored. `dotfilesDirPath` denotes the path to the dotfiles directory. `userSpacePath` denotes the root of where the symlinks can be found.

func WriteFile

func WriteFile(fpath string, contents []byte, overwrite bool) error

Writes a file to disk

Types

type ErrAbortOnOverwrite

type ErrAbortOnOverwrite struct {
	Path string
}

func (*ErrAbortOnOverwrite) Error

func (e *ErrAbortOnOverwrite) Error() string

type ErrConfirmProceed

type ErrConfirmProceed struct {
	Path string
}

func (*ErrConfirmProceed) Error

func (e *ErrConfirmProceed) Error() string

type ErrFileAlreadyExists

type ErrFileAlreadyExists struct {
	// contains filtered or unexported fields
}

func (*ErrFileAlreadyExists) Error

func (e *ErrFileAlreadyExists) Error() string

type ErrFileNotFound

type ErrFileNotFound struct {
	// contains filtered or unexported fields
}

func (*ErrFileNotFound) Error

func (e *ErrFileNotFound) Error() string

type ErrMergeFail

type ErrMergeFail struct {
	// contains filtered or unexported fields
}

The ErrMergeFail is returned if the remote could not be merged into the local data without interaction.

func (*ErrMergeFail) Error

func (e *ErrMergeFail) Error() string

type ErrSymlinkNotFound

type ErrSymlinkNotFound struct {
	// contains filtered or unexported fields
}

func (*ErrSymlinkNotFound) Error

func (e *ErrSymlinkNotFound) Error() string

type ErrUnmatchedShellReturn

type ErrUnmatchedShellReturn struct {
	// contains filtered or unexported fields
}

func (*ErrUnmatchedShellReturn) Error

func (e *ErrUnmatchedShellReturn) Error() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL