diff --git a/src/Converters/PathConverters.cs b/src/Converters/PathConverters.cs index 6f10b66d..95da6c79 100644 --- a/src/Converters/PathConverters.cs +++ b/src/Converters/PathConverters.cs @@ -1,4 +1,5 @@ -using System.IO; +using System; +using System.IO; using Avalonia.Data.Converters; @@ -7,9 +8,23 @@ namespace SourceGit.Converters public static class PathConverters { public static readonly FuncValueConverter PureFileName = - new FuncValueConverter(fullpath => Path.GetFileName(fullpath) ?? ""); + new(v => Path.GetFileName(v) ?? ""); public static readonly FuncValueConverter PureDirectoryName = - new FuncValueConverter(fullpath => Path.GetDirectoryName(fullpath) ?? ""); + new(v => Path.GetDirectoryName(v) ?? ""); + + public static readonly FuncValueConverter RelativeToHome = + new(v => + { + if (OperatingSystem.IsWindows()) + return v; + + var home = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile); + var prefixLen = home.EndsWith('/') ? home.Length - 1 : home.Length; + if (v.StartsWith(home, StringComparison.Ordinal)) + return "~" + v.Substring(prefixLen); + + return v; + }); } } diff --git a/src/Views/Welcome.axaml b/src/Views/Welcome.axaml index 6bd735ea..6d79948a 100644 --- a/src/Views/Welcome.axaml +++ b/src/Views/Welcome.axaml @@ -140,7 +140,7 @@ Margin="8,0" HorizontalAlignment="Right" VerticalAlignment="Center" Foreground="{DynamicResource Brush.FG2}" - Text="{Binding Id}" + Text="{Binding Id, Converter={x:Static c:PathConverters.RelativeToHome}}" IsVisible="{Binding IsRepository}"/>