namespacer

package module
v0.0.0-...-12ccc1a Latest Latest
Warning

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

Go to latest
Published: May 17, 2023 License: MIT Imports: 8 Imported by: 1

README

namespacer

CLI to avoid over-writing file-sytem names which already exist.
It is insensitive to argument type (file/directory).

Installation

go install github.com/kendfss/namespacer

Or

git clone github.com/kendfss/namespacer
cd namespacer
go install

Or

git clone github.com/kendfss/namespacer
cd namespacer
make install

Usage

It accepts three arguments:

  • path: to the file/directory
  • format: string that specifies the pattern that spaced names should extend with
  • index: the first number to try if the path argument already exists
namespacer main.go 
# returns "main_2.go" if main.go already exists
namespacer -path main.go -format " (%v)" -index 3 
# "main (3).go"
namespacer main.go " v%d" 40 
# main v40.go
namespacer main.go " v%x" 40 
# main v28.go
namespacer main.go " v%b" 40 
# main v101000.go

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MustSpace

func MustSpace(path string) string

Get the spaced version of a file path

func SpacedName

func SpacedName(path string) (string, error)

Get the spaced version of a file path

func SpacedName2

func SpacedName2(path, format string) (string, error)

Get the spaced version of a file path This version allows you to specify the format string that will differentiate collisions

func SpacedName3

func SpacedName3(path, format string, index uint) (string, error)

Get the spaced version of a file path This version allows you to specify the format string that will differentiate collisions as well as the starting index

Types

type HttpFS

type HttpFS struct {
	url.URL
	// contains filtered or unexported fields
}

func (HttpFS) Open

func (self HttpFS) Open(name string) (fs.File, error)

type LocalFS

type LocalFS struct{}

func (LocalFS) Open

func (LocalFS) Open(name string) (fs.File, error)

type NameSpacer

type NameSpacer struct {
	// Handles the spacing of path names by checking for existing matches
	Format string // Pattern that spaced names should follow. "_%v" is easier to parse but " (%v)" is common to major OSs.
	Index  uint   // Starting index of duplicates. For most uses it is best to set this equal to 2
}

func (*NameSpacer) Space

func (this *NameSpacer) Space(path string) (string, error)

Apply the spacing operation on the path

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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