diff options
author | Thomas Lübking <thomas.luebking@gmail.com> | 2016-07-23 14:39:44 (GMT) |
---|---|---|
committer | Thomas Lübking <thomas.luebking@gmail.com> | 2016-07-23 14:58:04 (GMT) |
commit | baaf477d46e619127b91faf59be2cf2c2c95afff (patch) | |
tree | 002803a3f3b270591fb9fb0a157f95552d536b4f /util | |
parent | 8094f4d1a9b48c1edb8d39386e4788e0eb284ae6 (diff) | |
download | fluxbox-baaf477d46e619127b91faf59be2cf2c2c95afff.zip fluxbox-baaf477d46e619127b91faf59be2cf2c2c95afff.tar.bz2 |
add support for dedicated completion data
This allows to complete random things, useful along the -print flag but
also to limit the commands to those found my menumaker etc.
Diffstat (limited to 'util')
-rw-r--r-- | util/fbrun/FbRun.cc | 19 | ||||
-rw-r--r-- | util/fbrun/FbRun.hh | 1 | ||||
-rw-r--r-- | util/fbrun/main.cc | 10 |
3 files changed, 29 insertions, 1 deletions
diff --git a/util/fbrun/FbRun.cc b/util/fbrun/FbRun.cc index 321959e..b697187 100644 --- a/util/fbrun/FbRun.cc +++ b/util/fbrun/FbRun.cc | |||
@@ -214,6 +214,23 @@ bool FbRun::loadHistory(const char *filename) { | |||
214 | return true; | 214 | return true; |
215 | } | 215 | } |
216 | 216 | ||
217 | bool FbRun::loadCompletion(const char *filename) { | ||
218 | if (!filename) | ||
219 | return false; | ||
220 | ifstream infile(filename); | ||
221 | if (!infile) | ||
222 | return false; | ||
223 | |||
224 | m_apps.clear(); | ||
225 | string line; | ||
226 | while (getline(infile, line)) { | ||
227 | if (!line.empty()) // don't add empty lines | ||
228 | m_apps.push_back(line); | ||
229 | } | ||
230 | return true; | ||
231 | } | ||
232 | |||
233 | |||
217 | bool FbRun::loadFont(const string &fontname) { | 234 | bool FbRun::loadFont(const string &fontname) { |
218 | if (!m_font.load(fontname.c_str())) | 235 | if (!m_font.load(fontname.c_str())) |
219 | return false; | 236 | return false; |
@@ -472,7 +489,7 @@ void FbRun::tabCompleteApps() { | |||
472 | tabComplete(m_files, m_current_files_item); | 489 | tabComplete(m_files, m_current_files_item); |
473 | } else { | 490 | } else { |
474 | static bool first_run = true; | 491 | static bool first_run = true; |
475 | if (first_run) { | 492 | if (first_run && m_apps.empty()) { |
476 | first_run = false; | 493 | first_run = false; |
477 | std::string path = getenv("PATH"); | 494 | std::string path = getenv("PATH"); |
478 | FbTk::Directory dir; | 495 | FbTk::Directory dir; |
diff --git a/util/fbrun/FbRun.hh b/util/fbrun/FbRun.hh index f0915b0..e351d28 100644 --- a/util/fbrun/FbRun.hh +++ b/util/fbrun/FbRun.hh | |||
@@ -58,6 +58,7 @@ public: | |||
58 | @return true on success, else false | 58 | @return true on success, else false |
59 | */ | 59 | */ |
60 | bool loadHistory(const char *filename); | 60 | bool loadHistory(const char *filename); |
61 | bool loadCompletion(const char *filename); | ||
61 | /** | 62 | /** |
62 | @name events | 63 | @name events |
63 | */ | 64 | */ |
diff --git a/util/fbrun/main.cc b/util/fbrun/main.cc index 4022ef6..a8655ab 100644 --- a/util/fbrun/main.cc +++ b/util/fbrun/main.cc | |||
@@ -66,6 +66,7 @@ void showUsage(const char *progname) { | |||
66 | " -bg [color name] Background color"<<endl<< | 66 | " -bg [color name] Background color"<<endl<< |
67 | " -na Disable antialias"<<endl<< | 67 | " -na Disable antialias"<<endl<< |
68 | " -hf [history file] History file to load (default ~/.fluxbox/fbrun_history)"<<endl<< | 68 | " -hf [history file] History file to load (default ~/.fluxbox/fbrun_history)"<<endl<< |
69 | " -cf [completion file] Complete contents of this file instead of $PATH binaries"<<endl<< | ||
69 | " -autocomplete Complete on typing"<<endl<< | 70 | " -autocomplete Complete on typing"<<endl<< |
70 | " -preselect Select preset text"<<endl<< | 71 | " -preselect Select preset text"<<endl<< |
71 | " -help Show this help"<<endl<<endl<< | 72 | " -help Show this help"<<endl<<endl<< |
@@ -89,6 +90,7 @@ int main(int argc, char **argv) { | |||
89 | string background("white"); // text background color | 90 | string background("white"); // text background color |
90 | string display_name; // name of the display connection | 91 | string display_name; // name of the display connection |
91 | string history_file("~/.fluxbox/fbrun_history"); // command history file | 92 | string history_file("~/.fluxbox/fbrun_history"); // command history file |
93 | string completion_file; // command history file | ||
92 | // parse arguments | 94 | // parse arguments |
93 | for (int i=1; i<argc; i++) { | 95 | for (int i=1; i<argc; i++) { |
94 | string arg = argv[i]; | 96 | string arg = argv[i]; |
@@ -124,6 +126,8 @@ int main(int argc, char **argv) { | |||
124 | background = argv[++i]; | 126 | background = argv[++i]; |
125 | } else if (strcmp(argv[i], "-hf") == 0 && i+1 < argc) { | 127 | } else if (strcmp(argv[i], "-hf") == 0 && i+1 < argc) { |
126 | history_file = argv[++i]; | 128 | history_file = argv[++i]; |
129 | } else if (strcmp(argv[i], "-cf") == 0 && i+1 < argc) { | ||
130 | completion_file = argv[++i]; | ||
127 | } else if (strcmp(argv[i], "-preselect") == 0) { | 131 | } else if (strcmp(argv[i], "-preselect") == 0) { |
128 | preselect = true; | 132 | preselect = true; |
129 | } else if (strcmp(argv[i], "-autocomplete") == 0) { | 133 | } else if (strcmp(argv[i], "-autocomplete") == 0) { |
@@ -171,6 +175,12 @@ int main(int argc, char **argv) { | |||
171 | if (!fbrun.loadHistory(expanded_filename.c_str())) | 175 | if (!fbrun.loadHistory(expanded_filename.c_str())) |
172 | cerr<<"FbRun Warning: Failed to load history file: "<<expanded_filename<<endl; | 176 | cerr<<"FbRun Warning: Failed to load history file: "<<expanded_filename<<endl; |
173 | 177 | ||
178 | if (!completion_file.empty()) { | ||
179 | expanded_filename = FbTk::StringUtil::expandFilename(completion_file); | ||
180 | if (!fbrun.loadCompletion(expanded_filename.c_str())) | ||
181 | cerr<<"FbRun Warning: Failed to load completion file: "<<expanded_filename<<endl; | ||
182 | } | ||
183 | |||
174 | fbrun.setTitle(title); | 184 | fbrun.setTitle(title); |
175 | fbrun.setText(text); | 185 | fbrun.setText(text); |
176 | if (preselect) | 186 | if (preselect) |