aboutsummaryrefslogblamecommitdiffstatshomepage
path: root/utils.vala
blob: 0c5bd35a76b4b6c7ee597a6449f907ec2e86b115 (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
             













                                                                         

























                                                                                                    
class Utils {
	public static string get_shell() {
		var env_shell = Environment.get_variable("SHELL");
		if (env_shell != null && env_shell.length > 0){
			return env_shell;
		}

		unowned Posix.Passwd pw = Posix.getpwuid(Posix.getuid());
		if (pw != null && pw.pw_shell.length > 0) {
			return pw.pw_shell;
		}

		return "/bin/sh";
	}

	public static string? normalize_uri(string? uri) {
		if (uri == null)
			return null;

		string? u = Uri.unescape_string(uri, null);

		if (u == null)
			u = uri;

		if (u.has_prefix("ftp://") || u.has_prefix("http://") || u.has_prefix("https://")) {
			int a = u.index_of("/", 0) + 2; // character after second slash
			int b = u.index_of("/", a); // next slash after hostname...
			if (b < 0)
				b = u.length; // ... or end of string

			string hostname = u.slice(a, b);
			string? canon = Hostname.to_unicode(hostname);

			if (canon != null && hostname != canon) {
				u = u.splice(a, b, canon);
			}
		}

		return u;
	}
}