[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-core-devel
Subject:    Expanding environment variables in minicli
From:       Frerich Raabe <frerichraabe () gmx ! de>
Date:       2001-10-28 14:37:05
[Download RAW message or body]

Hi,

the attached patch expands environment variables, if possible, automatically 
in strings entered via minicli. I for one find that pretty convenient since 
I'm used to typing stuff like 'cd $KDEDIR/include' or similar at the console. 

I'm not quite sure whether the '== QChar::Letter_Uppercase' check is correct 
(no idea which characters in particular may appear in an environment 
variable's name), but it's obviously very easy to fix that.

Perhaps this functionality is worth to be added to KRun itself, although 
somebody on IRC mentioned that it is too complicated (or too much overhead or 
something, cannot remember really).

Anyway, would be cool if you'd give it a shot and me some feedback. :-)

- Frerich

["minicli.diff" (text/x-diff)]

Index: minicli.cpp
===================================================================
RCS file: /home/kde/kdebase/kdesktop/minicli.cpp,v
retrieving revision 1.94
diff -u -3 -p -r1.94 minicli.cpp
--- minicli.cpp	2001/10/20 00:18:32	1.94
+++ minicli.cpp	2001/10/28 14:25:34
@@ -11,6 +11,7 @@
 #include <pwd.h>
 #include <string.h>
 #include <errno.h>
+#include <stdlib.h>
 
 #include <qvbox.h>
 #include <qlabel.h>
@@ -220,6 +221,20 @@ int Minicli::run_command()
     }
 
     QString cmd = (m_filterData->uri().isLocalFile() ? \
m_filterData->uri().path():m_filterData->uri().url()); +    
+    // Expand environment variables.
+    while (cmd.contains("$"))
+    {
+        QString name;
+        unsigned nameStart = cmd.find("$") + 1;
+        unsigned nameEnd = nameStart;
+        while (nameEnd < cmd.length() && cmd[nameEnd].category() == \
QChar::Letter_Uppercase) +            name += cmd[nameEnd++];
+        QString value = QString::fromLatin1(::getenv(name.latin1()));
+        if (!value.isNull())
+		    cmd.replace(nameStart - 1, nameStart - nameEnd, value);
+    }
+        
     if ( m_runCombo->currentText().isEmpty() )
     {
         return 1;  // Ignore



[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic