dropbox / dbxcli

A command line client for Dropbox built using the Go SDK
Other
1.05k stars 100 forks source link

Question: Howto change format of file size and timestamp output by ls -l? #110

Closed boskamp closed 5 years ago

boskamp commented 5 years ago

Is it possible to customize the format of file size and timestamp output by ls -l? I would like to display file size in bytes, and timestamps in some canonical format like ISO8601.

My use case is that I have a local -presumably outdated- revision of my Dropbox tree. I can inspect the files and folder of that local revision using Linux ls -lR, of course. What I would like to have is the exact same information for my remote Dropbox tree, so I can canonicalize and diff local vs. remote using a script I will write for that purpose.

dbxcli ls -lR provides close to what I need, just the timestamps and file sizes from both tools are not really comparable.

mpr90 commented 5 years ago

Looks like a code change would be required to match the "ls -l" timestamp behaviour. Currently time is "humanized" by the code. Suggest maybe only doing this when a new "-h" option is given and otherwise following ls behaviour as suggested here.

boskamp commented 5 years ago

Thanks, I was able to implement the behavior I need by patching cmd/ls.go.

The changes needed, as far as I remember, were one additional import "time" and a change to func printFileMetadata(w io.Writer, e *files.FileMetadata, longFormat bool), replacing

humanize.Time(e.ServerModified)

with

e.ServerModified.UTC().Format(time.RFC3339)