Skip to content

Commit 81b72f7

Browse files
committed
enhance: use ~ to represent the home dir of current user
1 parent 0b6ecc0 commit 81b72f7

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

src/Converters/PathConverters.cs

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.IO;
1+
using System;
2+
using System.IO;
23

34
using Avalonia.Data.Converters;
45

@@ -7,9 +8,23 @@ namespace SourceGit.Converters
78
public static class PathConverters
89
{
910
public static readonly FuncValueConverter<string, string> PureFileName =
10-
new FuncValueConverter<string, string>(fullpath => Path.GetFileName(fullpath) ?? "");
11+
new(v => Path.GetFileName(v) ?? "");
1112

1213
public static readonly FuncValueConverter<string, string> PureDirectoryName =
13-
new FuncValueConverter<string, string>(fullpath => Path.GetDirectoryName(fullpath) ?? "");
14+
new(v => Path.GetDirectoryName(v) ?? "");
15+
16+
public static readonly FuncValueConverter<string, string> RelativeToHome =
17+
new(v =>
18+
{
19+
if (OperatingSystem.IsWindows())
20+
return v;
21+
22+
var home = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
23+
var prefixLen = home.EndsWith('/') ? home.Length - 1 : home.Length;
24+
if (v.StartsWith(home, StringComparison.Ordinal))
25+
return "~" + v.Substring(prefixLen);
26+
27+
return v;
28+
});
1429
}
1530
}

src/Views/Welcome.axaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@
140140
Margin="8,0"
141141
HorizontalAlignment="Right" VerticalAlignment="Center"
142142
Foreground="{DynamicResource Brush.FG2}"
143-
Text="{Binding Id}"
143+
Text="{Binding Id, Converter={x:Static c:PathConverters.RelativeToHome}}"
144144
IsVisible="{Binding IsRepository}"/>
145145
</Grid>
146146
</DataTemplate>

0 commit comments

Comments
 (0)