Merge lp:~ian-liu88/unity-lens-applications/fix-for-bug-734762 into lp:unity-lens-applications

Proposed by Ian Liu Rodrigues
Status: Merged
Merged at revision: 198
Proposed branch: lp:~ian-liu88/unity-lens-applications/fix-for-bug-734762
Merge into: lp:unity-lens-applications
Diff against target: 105 lines (+43/-5)
4 files modified
src/Makefile.am (+1/-0)
src/daemon.vala (+8/-3)
src/runner.vala (+2/-1)
src/utils.vala (+32/-1)
To merge this branch: bzr merge lp:~ian-liu88/unity-lens-applications/fix-for-bug-734762
Reviewer Review Type Date Requested Status
Didier Roche-Tolomelli Approve
Review via email: mp+55457@code.launchpad.net

Description of the change

The intent of this branch is to interpret the tilde character as the home directory before executing commands. Substitution of ~user also works.

To post a comment you must log in.
Revision history for this message
Didier Roche-Tolomelli (didrocks) wrote :

Excellent Ian! Working as advertised and the code looks good :)

I wondering if you want to do the final polish on that, I mean:
Type Alt + F2:
- enter ~foo/bar
-> the directories matching in instance: /home/foo/bar* as we have with direct typing in /home/foo/bar*

For that, I would:
- move subst_tilde to src/utils.vala
- in update_search for runner.vala, in addition to if (search_string.has_prefix ("/")), add a or "~" in search_string and call the subst_tilde function to introspect in it.

Anyway, just tell me if you want to finish this or not, I can do it, you've already made most of the hard work and thanks for this! :)

Revision history for this message
Ian Liu Rodrigues (ian-liu88) wrote :

> Excellent Ian! Working as advertised and the code looks good :)
[...]
> Anyway, just tell me if you want to finish this or not, I can do it,
> you've already made most of the hard work and thanks for this! :)

Thanks!
I would love to do it and I can finish it today at night (in Brazil GMT -3)

198. By Ian Liu Rodrigues

Expands tilde character before listing directories

Revision history for this message
Didier Roche-Tolomelli (didrocks) wrote :

Code looks good and works as advertised.

Thanks for doing the change and for this awesome contribution! :-)
Approved and merging

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/Makefile.am'
2--- src/Makefile.am 2011-03-10 11:03:15 +0000
3+++ src/Makefile.am 2011-03-31 01:34:24 +0000
4@@ -24,6 +24,7 @@
5 unity_applications_daemon_VALAFLAGS = \
6 -C \
7 --vapidir=$(top_srcdir)/vapi \
8+ --pkg posix \
9 --pkg gio-2.0 \
10 --pkg gio-unix-2.0 \
11 --pkg dee-1.0 \
12
13=== modified file 'src/daemon.vala'
14--- src/daemon.vala 2011-03-28 14:50:54 +0000
15+++ src/daemon.vala 2011-03-31 01:34:24 +0000
16@@ -742,7 +742,7 @@
17 return;
18 }
19 }
20-
21+
22 /**
23 * Override of the default activation handler. The apps place daemon
24 * can handle activation of installable apps using the Software Center
25@@ -761,9 +761,14 @@
26 }
27 else if (uri.has_prefix ("unity-runner://"))
28 {
29- exec_or_dir = uri.offset (15);
30+ string orig;
31+ orig = uri.offset (15);
32+ exec_or_dir = Utils.subst_tilde (orig);
33 args = exec_or_dir.split (" ", 0);
34- this.runner.add_history (exec_or_dir);
35+ for (int i = 0; i < args.length; i++)
36+ args[i] = Utils.subst_tilde (args[i]);
37+
38+ this.runner.add_history (orig);
39 }
40 else
41 {
42
43=== modified file 'src/runner.vala'
44--- src/runner.vala 2011-03-23 15:25:00 +0000
45+++ src/runner.vala 2011-03-31 01:34:24 +0000
46@@ -185,8 +185,9 @@
47 }
48
49 /* manual seek with directory and executables result */
50- if (search_string.has_prefix ("/"))
51+ if (search_string.has_prefix ("/") || search_string.has_prefix ("~"))
52 {
53+ search_string = Utils.subst_tilde (search_string);
54 var search_dirname = Path.get_dirname (search_string);
55 var directory = File.new_for_path (search_dirname);
56 var search_dirname_in_path = false;
57
58=== modified file 'src/utils.vala'
59--- src/utils.vala 2011-03-08 15:57:37 +0000
60+++ src/utils.vala 2011-03-31 01:34:24 +0000
61@@ -16,6 +16,7 @@
62 * Authored by Mikkel Kamstrup Erlandsen <mikkel.kamstrup@canonical.com>
63 *
64 */
65+using Posix;
66 using Unity;
67 using Gee;
68
69@@ -130,5 +131,35 @@
70 return s1.strip () != s2.strip ();
71 }
72 }
73-
74+
75+ /* Substitute tilde character in @s by the home directory.
76+ * Expansion of ~username also works if 'username' is found. */
77+ public string subst_tilde (string s)
78+ {
79+ int k;
80+ string name;
81+ unowned Passwd? pw;
82+
83+ if (s[0] != '~')
84+ return s;
85+
86+ if (s.length == 1 || s[1] == '/')
87+ return Environment.get_home_dir () + s.substring (1, -1);
88+
89+ k = s.index_of ("/");
90+ if (k == -1)
91+ name = s.substring (1, -1);
92+ else
93+ name = s.substring (1, k-1);
94+
95+ pw = Posix.getpwnam (name);
96+ if (pw == null)
97+ return s;
98+
99+ if (k == -1)
100+ return pw.pw_dir;
101+ else
102+ return pw.pw_dir + s.substring (k, -1);
103+ }
104+
105 }

Subscribers

People subscribed via source and target branches