Skip to content

Commit e19022c

Browse files
authored
Merge pull request #1205 from AkihiroSuda/list-shorten-dir
limactl list: "/Users/<USERNAME>/.lima/..." -> "~/.lima/..."
2 parents bde7a13 + 0832d86 commit e19022c

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

cmd/limactl/list.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"encoding/json"
55
"errors"
66
"fmt"
7+
"os/user"
78
"reflect"
89
"sort"
910
"strings"
@@ -171,6 +172,12 @@ func listAction(cmd *cobra.Command, args []string) error {
171172
logrus.Warn("No instance found. Run `limactl start` to create an instance.")
172173
}
173174

175+
u, err := user.Current()
176+
if err != nil {
177+
return err
178+
}
179+
homeDir := u.HomeDir
180+
174181
for _, instName := range instances {
175182
inst, err := store.Inspect(instName)
176183
if err != nil {
@@ -180,6 +187,10 @@ func listAction(cmd *cobra.Command, args []string) error {
180187
if len(inst.Errors) > 0 {
181188
logrus.WithField("errors", inst.Errors).Warnf("instance %q has errors", instName)
182189
}
190+
dir := inst.Dir
191+
if strings.HasPrefix(dir, homeDir) {
192+
dir = strings.Replace(dir, homeDir, "~", 1)
193+
}
183194
fmt.Fprintf(w, "%s\t%s\t%s\t%s\t%s\t%d\t%s\t%s\t%s\n",
184195
inst.Name,
185196
inst.Status,
@@ -189,7 +200,7 @@ func listAction(cmd *cobra.Command, args []string) error {
189200
inst.CPUs,
190201
units.BytesSize(float64(inst.Memory)),
191202
units.BytesSize(float64(inst.Disk)),
192-
inst.Dir,
203+
dir,
193204
)
194205
}
195206

0 commit comments

Comments
 (0)