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
=== modified file 'src/Makefile.am'
--- src/Makefile.am 2011-03-10 11:03:15 +0000
+++ src/Makefile.am 2011-03-31 01:34:24 +0000
@@ -24,6 +24,7 @@
24unity_applications_daemon_VALAFLAGS = \24unity_applications_daemon_VALAFLAGS = \
25 -C \25 -C \
26 --vapidir=$(top_srcdir)/vapi \26 --vapidir=$(top_srcdir)/vapi \
27 --pkg posix \
27 --pkg gio-2.0 \28 --pkg gio-2.0 \
28 --pkg gio-unix-2.0 \29 --pkg gio-unix-2.0 \
29 --pkg dee-1.0 \30 --pkg dee-1.0 \
3031
=== modified file 'src/daemon.vala'
--- src/daemon.vala 2011-03-28 14:50:54 +0000
+++ src/daemon.vala 2011-03-31 01:34:24 +0000
@@ -742,7 +742,7 @@
742 return;742 return;
743 }743 }
744 }744 }
745 745
746 /**746 /**
747 * Override of the default activation handler. The apps place daemon747 * Override of the default activation handler. The apps place daemon
748 * can handle activation of installable apps using the Software Center748 * can handle activation of installable apps using the Software Center
@@ -761,9 +761,14 @@
761 }761 }
762 else if (uri.has_prefix ("unity-runner://"))762 else if (uri.has_prefix ("unity-runner://"))
763 {763 {
764 exec_or_dir = uri.offset (15);764 string orig;
765 orig = uri.offset (15);
766 exec_or_dir = Utils.subst_tilde (orig);
765 args = exec_or_dir.split (" ", 0);767 args = exec_or_dir.split (" ", 0);
766 this.runner.add_history (exec_or_dir);768 for (int i = 0; i < args.length; i++)
769 args[i] = Utils.subst_tilde (args[i]);
770
771 this.runner.add_history (orig);
767 }772 }
768 else773 else
769 {774 {
770775
=== modified file 'src/runner.vala'
--- src/runner.vala 2011-03-23 15:25:00 +0000
+++ src/runner.vala 2011-03-31 01:34:24 +0000
@@ -185,8 +185,9 @@
185 }185 }
186 186
187 /* manual seek with directory and executables result */187 /* manual seek with directory and executables result */
188 if (search_string.has_prefix ("/"))188 if (search_string.has_prefix ("/") || search_string.has_prefix ("~"))
189 {189 {
190 search_string = Utils.subst_tilde (search_string);
190 var search_dirname = Path.get_dirname (search_string);191 var search_dirname = Path.get_dirname (search_string);
191 var directory = File.new_for_path (search_dirname);192 var directory = File.new_for_path (search_dirname);
192 var search_dirname_in_path = false;193 var search_dirname_in_path = false;
193194
=== modified file 'src/utils.vala'
--- src/utils.vala 2011-03-08 15:57:37 +0000
+++ src/utils.vala 2011-03-31 01:34:24 +0000
@@ -16,6 +16,7 @@
16 * Authored by Mikkel Kamstrup Erlandsen <mikkel.kamstrup@canonical.com>16 * Authored by Mikkel Kamstrup Erlandsen <mikkel.kamstrup@canonical.com>
17 *17 *
18 */18 */
19using Posix;
19using Unity;20using Unity;
20using Gee;21using Gee;
21 22
@@ -130,5 +131,35 @@
130 return s1.strip () != s2.strip ();131 return s1.strip () != s2.strip ();
131 }132 }
132 }133 }
133 134
135 /* Substitute tilde character in @s by the home directory.
136 * Expansion of ~username also works if 'username' is found. */
137 public string subst_tilde (string s)
138 {
139 int k;
140 string name;
141 unowned Passwd? pw;
142
143 if (s[0] != '~')
144 return s;
145
146 if (s.length == 1 || s[1] == '/')
147 return Environment.get_home_dir () + s.substring (1, -1);
148
149 k = s.index_of ("/");
150 if (k == -1)
151 name = s.substring (1, -1);
152 else
153 name = s.substring (1, k-1);
154
155 pw = Posix.getpwnam (name);
156 if (pw == null)
157 return s;
158
159 if (k == -1)
160 return pw.pw_dir;
161 else
162 return pw.pw_dir + s.substring (k, -1);
163 }
164
134}165}

Subscribers

People subscribed via source and target branches