[gitg] Add expand_home_dir utility
- From: Jesse van den Kieboom <jessevdk src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gitg] Add expand_home_dir utility
- Date: Tue, 22 Dec 2015 08:58:00 +0000 (UTC)
commit 0b774ca3813f5d3422293b077cbc6a2a2b25cd2c
Author: Jesse van den Kieboom <jessevdk gnome org>
Date: Tue Dec 22 09:56:58 2015 +0100
Add expand_home_dir utility
libgitg/gitg-utils.vala | 26 ++++++++++++++++++++++++++
1 files changed, 26 insertions(+), 0 deletions(-)
---
diff --git a/libgitg/gitg-utils.vala b/libgitg/gitg-utils.vala
index 48d3576..d29888f 100644
--- a/libgitg/gitg-utils.vala
+++ b/libgitg/gitg-utils.vala
@@ -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;
+ }
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]