Skip to content

Commit 282990c

Browse files
committed
massren . to rename files in current directory
The "dot" metaphor for `cwd` (current working directory) is ubiquitous in shell usage. This commit makes the command `massren .` open an editor with file listing in the current directory. i.e. equivalent functionality to `massren`. Fixes #50
1 parent 93e8c66 commit 282990c

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

main.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ func filePathsFromArgs(args []string, includeDirectories bool) ([]string, error)
265265
var output []string
266266
var err error
267267

268-
if len(args) == 0 {
268+
if len(args) == 0 || args[0] == "." {
269269
output, err = filepath.Glob("*")
270270
if err != nil {
271271
return []string{}, err

main_test.go

+26-1
Original file line numberDiff line numberDiff line change
@@ -679,10 +679,35 @@ func Test_filePathsFromArgs(t *testing.T) {
679679
t.Error(err)
680680
}
681681

682+
// "." (current directory) as the only file path argument works the same as "*"
683+
currentDir, err := os.Getwd()
684+
if err != nil {
685+
panic(err)
686+
}
687+
688+
err = os.Chdir(tempFolder())
689+
if err != nil {
690+
panic(err)
691+
}
692+
693+
args = []string{"."}
694+
695+
filePaths, err = filePathsFromArgs(args, true)
696+
if err != nil {
697+
t.Fatal(err)
698+
}
699+
700+
err = fileListsAreEqual(filePaths, tempFiles)
701+
if err != nil {
702+
t.Error(err)
703+
}
704+
705+
os.Chdir(currentDir)
706+
682707
// If no argument is provided, the function should default to "*"
683708
// in the current dir.
684709

685-
currentDir, err := os.Getwd()
710+
currentDir, err = os.Getwd()
686711
if err != nil {
687712
panic(err)
688713
}

0 commit comments

Comments
 (0)