Skip to content

Commit f426f68

Browse files
committed
Add quiet mode
1 parent 83a01ea commit f426f68

File tree

3 files changed

+20
-15
lines changed

3 files changed

+20
-15
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ Options:
7070
--permanent delete a file permanently
7171
-d/--directory show path to the data dir
7272
-t/--set-dir <dir> set the data dir and continue
73+
-q/--quiet enable quiet mode
7374
--disable-copy if files are on a different fs, don't rename by copy
7475
-h/--help print this help message
7576
-v/--version print Rem version

go.sum

-11
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,20 @@
1-
github.com/fatih/color v1.10.0 h1:s36xzo75JdqLaaWoiEHk767eHiwo0598uUxyfiPkDsg=
2-
github.com/fatih/color v1.10.0/go.mod h1:ELkj/draVOlAH/xkhN6mQ50Qd0MPOk5AAr3maGEBuJM=
31
github.com/fatih/color v1.13.0 h1:8LOYc1KYPPmyKMuN8QV2DNRWNbLo6LZ0iLs8+mlH53w=
42
github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYFFOfk=
5-
github.com/mattn/go-colorable v0.1.8 h1:c1ghPdyEDarC70ftn0y+A/Ee++9zz8ljHG1b13eJ0s8=
6-
github.com/mattn/go-colorable v0.1.8/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc=
73
github.com/mattn/go-colorable v0.1.9/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc=
84
github.com/mattn/go-colorable v0.1.12 h1:jF+Du6AlPIjs2BiUiQlKOX0rt3SujHxPnksPKZbaA40=
95
github.com/mattn/go-colorable v0.1.12/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4=
10-
github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY=
116
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
127
github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y=
138
github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94=
14-
github.com/otiai10/copy v1.5.0 h1:SoXDGnlTUZoqB/wSuj/Y5L6T5i6iN4YRAcMCd+JnLNU=
15-
github.com/otiai10/copy v1.5.0/go.mod h1:XWfuS3CrI0R6IE0FbgHsEazaXO8G0LpMp9o8tos0x4E=
169
github.com/otiai10/copy v1.7.0 h1:hVoPiN+t+7d2nzzwMiDHPSOogsWAStewq3TwU05+clE=
1710
github.com/otiai10/copy v1.7.0/go.mod h1:rmRl6QPdJj6EiUqXQ/4Nn2lLXoNQjFCQbbNrxgc/t3U=
1811
github.com/otiai10/curr v0.0.0-20150429015615-9b4961190c95/go.mod h1:9qAhocn7zKJG+0mI8eUu6xqkFDYS2kb2saOteoSB3cE=
1912
github.com/otiai10/curr v1.0.0/go.mod h1:LskTG5wDwr8Rs+nNQ+1LlxRjAtTZZjtJW4rMXl6j4vs=
2013
github.com/otiai10/mint v1.3.0/go.mod h1:F5AjcsTsWUqX+Na9fpHb52P8pcRX2CI6A3ctIT91xUo=
21-
github.com/otiai10/mint v1.3.2 h1:VYWnrP5fXmz1MXvjuUvcBrXSjGE6xjON+axB/UrpO3E=
22-
github.com/otiai10/mint v1.3.2/go.mod h1:/yxELlJQ0ufhjUwhshSj+wFjZ78CnZ48/1wtmBH1OTc=
2314
github.com/otiai10/mint v1.3.3 h1:7JgpsBaN0uMkyju4tbYHu0mnM55hNKVYLsXmwr15NQI=
2415
github.com/otiai10/mint v1.3.3/go.mod h1:/yxELlJQ0ufhjUwhshSj+wFjZ78CnZ48/1wtmBH1OTc=
2516
golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
2617
golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
27-
golang.org/x/sys v0.0.0-20210309074719-68d13333faf2 h1:46ULzRKLh1CwgRq2dC5SlBzEqqNCi8rreOZnNrbqcIY=
28-
golang.org/x/sys v0.0.0-20210309074719-68d13333faf2/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
2918
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
3019
golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
3120
golang.org/x/sys v0.0.0-20220412211240-33da011f77ad h1:ntjMns5wyP/fN65tdBD4g8J5w8n015+iIIs9rtjXkY0=

rem.go

+19-4
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,16 @@ Options:
2828
--permanent delete a file permanently
2929
-d/--directory show path to the data dir
3030
-t/--set-dir <dir> set the data dir and continue
31+
-q/--quiet enable quiet mode
3132
--disable-copy if files are on a different fs, don't rename by copy
3233
-h/--help print this help message
3334
-v/--version print Rem version`
3435
dataDir string
3536
logFileName = ".trash.log"
3637
logFile map[string]string
3738
renameByCopyIsAllowed = true
38-
//logSeparator = "\t==>\t"
39+
40+
quietMode = false
3941
)
4042

4143
// TODO: Multiple Rem instances could clobber log file. Fix using either file locks or tcp port locks.
@@ -84,6 +86,13 @@ func main() {
8486
return
8587
}
8688

89+
if hasOption, i := argsHaveOption("quiet", "q"); hasOption {
90+
quietMode = true
91+
os.Args = removeElemFromSlice(os.Args, i)
92+
main()
93+
return
94+
}
95+
8796
if hasOption, _ := argsHaveOption("directory", "d"); hasOption {
8897
fmt.Println(dataDir)
8998
return
@@ -144,7 +153,7 @@ func restore(path string) {
144153
}
145154
delete(logFile, absPath)
146155
setLogFile(logFile) // we deleted an entry so save the edited logFile
147-
fmt.Println(color.YellowString(path) + " restored")
156+
printIfNotQuiet(color.YellowString(path) + " restored")
148157
}
149158

150159
func trashFile(path string) {
@@ -177,7 +186,7 @@ func trashFile(path string) {
177186
setLogFile(m)
178187
// if we've reached here, trashing is complete and successful
179188
// TODO: Print with quotes only if it contains spaces
180-
fmt.Println("Trashed " + color.YellowString(path) + "\nUndo using " + color.YellowString("rem --undo \""+path+"\""))
189+
printIfNotQuiet("Trashed " + color.YellowString(path) + "\nUndo using " + color.YellowString("rem --undo \""+path+"\""))
181190
}
182191

183192
func renameByCopyAllowed(src, dst string) error {
@@ -216,7 +225,7 @@ func getTimestampedPath(path string, existsFunc func(string) bool) string {
216225
}
217226
}
218227
if i != 0 {
219-
fmt.Println("To avoid conflicts, " + color.YellowString(oldPath) + " will now be called " + color.YellowString(path))
228+
printIfNotQuiet("To avoid conflicts, " + color.YellowString(oldPath) + " will now be called " + color.YellowString(path))
220229
}
221230
return path
222231
}
@@ -383,3 +392,9 @@ func printFormattedList(a []string) {
383392
fmt.Println(color.CyanString(strconv.Itoa(i+1)+":"), elem)
384393
}
385394
}
395+
396+
func printIfNotQuiet(a ...interface{}) {
397+
if !quietMode {
398+
fmt.Println(a...)
399+
}
400+
}

0 commit comments

Comments
 (0)