shared

package
v0.0.0-...-b355e5a Latest Latest
Warning

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

Go to latest
Published: Jun 23, 2020 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Functions shared between borrowedtime packages.

Utilities shared between different packages.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddExtension

func AddExtension(filename, ext string) string

AddExtension removes the old extension and adds a new one.

func DeletePath

func DeletePath(pathname string) error

DeletePath deletes a path and all its children from disk.

func DesktopPath

func DesktopPath() (string, error)

DesktopPath returns the path to Desktop on a Windows machine.

func DetectApp

func DetectApp(executable string) string

DetectApp parses the start menu, looks for an executable name (e.g. code.exe) in base paths, and returns the complete path.

func EscapeString

func EscapeString(inp string) string

EscapeString, escapes a single \ by converting it to "\ \".

func HomeDir

func HomeDir() (string, error)

HomeDir calls homedir.Dir() but changes the backslashes with forwardslashes on Windows.

func ListFiles

func ListFiles(root, pattern string) (files []string, err error)

ListFiles returns all files with a specific pattern under a path. The path is relative to root. Pattern is the typical "shell file name pattern" (e.g. *.exe or * to list all files).

func OpenWithDefaultEditor

func OpenWithDefaultEditor(path string) error

OpenWithDefaultEditor opens a file with the default editor depdening on the OS. Only Windows is supported. TODO: Add other OS default editors.

func OpenWithEditor

func OpenWithEditor(editor string, paths ...string) error

OpenWithEditor opens paths with the editor in the config file. The editor must support passing one or more paths as the first parameter or just ignore everything after the first one.

func PathExists

func PathExists(path string) (bool, error)

PathExists returns true if a path exists or cannot be accessed. Return the error if we cannot access because of a permission issue.

func PrettyPrintJSON

func PrettyPrintJSON(in string, w io.Writer) error

PrettyPrintJSON gets a string and pretty prints it to io.Writer.

func ReadFileByte

func ReadFileByte(filename string) ([]byte, error)

ReadFileByte reads the contents of a file.

func ReadFileString

func ReadFileString(filename string) (string, error)

ReadFileString is the same as ReadFile but returns a string.

func RemoveExtension

func RemoveExtension(filename string) string

RemoveExtension removes the extension from a filename.

func SortedKeys

func SortedKeys(mp map[string]string) []string

SortedKeys returns a sorted slice of keys for a map[string]string.

func StructToJSONString

func StructToJSONString(v interface{}, indent bool) (string, error)

StructToJSONString converts a struct into a JSON string.

func WindowsifyString

func WindowsifyString(inp string) string

WindowsifyString converts "\n" to "\r\n" in a string.

func WriteFile

func WriteFile(file string, input []byte, overwrite bool) error

WriteFile writes the contents of the input to the file. File will be overwritten if overwrite is set to true.

func WriteFileString

func WriteFileString(file, content string, overwrite bool) error

WriteFileString does the same thing that WriteFile does with a string input. I could copy WriteFile and use f.WriteString but this looks cleaner.

Types

This section is empty.

Jump to

Keyboard shortcuts

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