mirror of
https://gitlab.gnome.org/GNOME/gitg
synced 2024-06-30 23:29:33 +00:00
Add expand_home_dir utility
This commit is contained in:
parent
a434631272
commit
0b774ca381
|
@ -48,6 +48,32 @@ public class Utils
|
|||
|
||||
return name;
|
||||
}
|
||||
|
||||
public static string expand_home_dir(string path)
|
||||
{
|
||||
string? homedir = null;
|
||||
int pos = -1;
|
||||
|
||||
if (path.has_prefix("~/"))
|
||||
{
|
||||
homedir = PlatformSupport.get_user_home_dir();
|
||||
pos = 1;
|
||||
}
|
||||
else if (path.has_prefix("~"))
|
||||
{
|
||||
pos = path.index_of_char('/');
|
||||
var user = path[1:pos];
|
||||
|
||||
homedir = PlatformSupport.get_user_home_dir(user);
|
||||
}
|
||||
|
||||
if (homedir != null)
|
||||
{
|
||||
return Path.build_filename(homedir, path.substring(pos + 1));
|
||||
}
|
||||
|
||||
return path;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user