Compare commits

..

No commits in common. "master" and "v1" have entirely different histories.
master ... v1

3 changed files with 8 additions and 90 deletions

2
go.mod
View file

@ -1,3 +1,3 @@
module github.com/js0ny/renamedit
module renamedit
go 1.24.1

44
main.go
View file

@ -2,7 +2,6 @@ package main
import (
"bufio"
"flag"
"fmt"
"os"
"os/exec"
@ -10,27 +9,14 @@ import (
"strings"
)
var ignoreExt bool
func init() {
const ignoreExtDesc = "Ignore file extensions when renaming"
flag.BoolVar(&ignoreExt, "ignore-ext", false, ignoreExtDesc)
flag.BoolVar(&ignoreExt, "i", false, ignoreExtDesc+" (shorthand)")
}
func main() {
flag.Parse()
// Check command line arguments
args := flag.Args()
if len(args) != 1 {
fmt.Println("Usage: renamedit [options] <directory path>")
fmt.Println("Options:")
flag.PrintDefaults()
if len(os.Args) != 2 {
fmt.Println("Usage: renamedit <directory path>")
os.Exit(1)
}
dirPath := args[0]
dirPath := os.Args[1]
// Check if directory exists
info, err := os.Stat(dirPath)
@ -60,30 +46,11 @@ func main() {
// Write filenames to temporary file
fileNames := make([]string, 0)
fileExts := make([]string, 0)
for _, file := range files {
if !file.IsDir() {
fileName := file.Name()
fileNames = append(fileNames, fileName)
// If ignoring extensions, split filename and extension
if ignoreExt {
baseName := fileName
ext := ""
// Get extension only if there is one
if dotIndex := strings.LastIndex(fileName, "."); dotIndex > 0 {
baseName = fileName[:dotIndex]
ext = fileName[dotIndex:]
}
fileExts = append(fileExts, ext)
tmpFile.WriteString(baseName + "\n")
} else {
tmpFile.WriteString(fileName + "\n")
fileExts = append(fileExts, "") // Empty placeholder
}
}
}
tmpFile.Close()
@ -145,12 +112,7 @@ func main() {
// Perform renaming
for i, oldName := range fileNames {
// Re-add extension if we were ignoring it
newName := newFileNames[i]
if ignoreExt {
newName = newName + fileExts[i]
}
if oldName != newName {
oldPath := filepath.Join(dirPath, oldName)
newPath := filepath.Join(dirPath, newName)

View file

@ -2,56 +2,12 @@
Rename files with your favourite editor
## Installation
Build from source:
```bash
git clone https://github.com/js0ny/renamedit.git
git clone git@github.com:js0ny/renamedit.git
cd renamedit
go build
```
## Usage
```bash
renamedit [options] <directory>
renamedit <dir>
```
### Options
- `-ignore-ext`: Ignore file extensions when renaming files. This will preserve the original extensions.
### Examples
Basic usage:
```bash
renamedit /path/to/directory
```
Ignore file extensions (useful for batch renaming while preserving extensions):
```bash
renamedit -i /path/to/directory
renamedit --ignore-ext /path/to/directory
```
## How It Works
1. The program opens a temporary file in your preferred text editor
2. Edit the file names as needed
3. Save and exit the editor
4. The program will rename the files according to your edits
## Environment Variables
- `EDITOR`: Set this to your preferred text editor (defaults to vim)
## Supported Editors
The following editors are explicitly supported with wait flags:
- Visual Studio Code (code)
- Sublime Text (subl)
- Zed Editor (zeditor)
- Atom (atom)
- Gedit (gedit)
- And most terminal editors (vim, nano, etc.)