lazygit icon indicating copy to clipboard operation
lazygit copied to clipboard

Add date in stash panel like in local branches panel

Open guildem opened this issue 2 years ago • 1 comments

Some projects can be messy, and stashes may accumulate. Sometimes old stashes stay in the stash list. If they are too old I may want to remove them. But I don't get the date information on lazygit.

Local branches panel has a "2d" / "3m" short information to show the last modifications. This could be nice to have the same presentation in the stash panel.

We also can show the date in the right detail view as a header, but it is less visible than into the stash panel.

FYI to get the stash date, we can add an option to the command like that : git stash list --date=local.

Not a Go developer and already checked lazygit code by curiosity, I won't be able to make a patch infortunately.

Thanks !

guildem avatar Feb 16 '23 09:02 guildem

I had a time to looks through this and here is what I found

In stash_loader.go if we change the format how stashes are listed to something like this to include the age (at line 36 and 69 respectively)

rawString, _ := self.cmd.New("git stash list -z --pretty='%gs date@{%ct}'").DontLog().RunWithOutput()` 
rawString, err := self.cmd.New("git stash list --name-only --pretty='%gd: %gs date@{%ct}'").DontLog().RunWithOutput()

we can get the age information and its just matter of displaying it by getting the age from the line

func (c *StashLoader) stashEntryFromLine(line string, index int) *models.StashEntry {
	regular := regexp.MustCompile(`(?P<line>.*?) date@\{(?P<age>.*?)\}`)
	match := regular.FindStringSubmatch(line)
	if match != nil {
		date, _ := strconv.Atoi(match[2])
		recency := utils.UnixToTimeAgo(int64(date))
		line =  recency + " " + match[1]
	}
	return &models.StashEntry{
		Name:  line,
		Index: index,
	}
}

Output would look something like this lg filtered_lg

let me know if I am in the right direction, I will be more than happy to create a PR!

glendsoza avatar Feb 16 '23 17:02 glendsoza

@glendsoza This seems to be a good way to show it, did you try to make a PR on this ?

guildem avatar Jun 16 '23 13:06 guildem