all repos — fluxbox @ baaf477d46e619127b91faf59be2cf2c2c95afff

custom fork of the fluxbox windowmanager

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.
Thomas Lübking thomas.luebking@gmail.com
commit

baaf477d46e619127b91faf59be2cf2c2c95afff

parent

8094f4d1a9b48c1edb8d39386e4788e0eb284ae6

4 files changed, 33 insertions(+), 1 deletions(-)

jump to
M doc/asciidoc/fbrun.txtdoc/asciidoc/fbrun.txt

@@ -69,6 +69,10 @@

*-hf* 'filename':: History file to load. The default is *~/.fluxbox/fbrun_history*. +*-cf* 'filename':: + Completion data to load. The default is empty. If no data can be loaded, + completion defaults to executables in $PATH + *-preselect*:: Select the preset text given by the *-text* parameter
M util/fbrun/FbRun.ccutil/fbrun/FbRun.cc

@@ -214,6 +214,23 @@ m_history_file = filename;

return true; } +bool FbRun::loadCompletion(const char *filename) { + if (!filename) + return false; + ifstream infile(filename); + if (!infile) + return false; + + m_apps.clear(); + string line; + while (getline(infile, line)) { + if (!line.empty()) // don't add empty lines + m_apps.push_back(line); + } + return true; +} + + bool FbRun::loadFont(const string &fontname) { if (!m_font.load(fontname.c_str())) return false;

@@ -472,7 +489,7 @@ }

tabComplete(m_files, m_current_files_item); } else { static bool first_run = true; - if (first_run) { + if (first_run && m_apps.empty()) { first_run = false; std::string path = getenv("PATH"); FbTk::Directory dir;
M util/fbrun/FbRun.hhutil/fbrun/FbRun.hh

@@ -58,6 +58,7 @@ loads history file.

@return true on success, else false */ bool loadHistory(const char *filename); + bool loadCompletion(const char *filename); /** @name events */
M util/fbrun/main.ccutil/fbrun/main.cc

@@ -66,6 +66,7 @@ " -fg [color name] Foreground text color"<<endl<<

" -bg [color name] Background color"<<endl<< " -na Disable antialias"<<endl<< " -hf [history file] History file to load (default ~/.fluxbox/fbrun_history)"<<endl<< + " -cf [completion file] Complete contents of this file instead of $PATH binaries"<<endl<< " -autocomplete Complete on typing"<<endl<< " -preselect Select preset text"<<endl<< " -help Show this help"<<endl<<endl<<

@@ -89,6 +90,7 @@ string foreground("black"); // text color

string background("white"); // text background color string display_name; // name of the display connection string history_file("~/.fluxbox/fbrun_history"); // command history file + string completion_file; // command history file // parse arguments for (int i=1; i<argc; i++) { string arg = argv[i];

@@ -124,6 +126,8 @@ } else if (strcmp(argv[i], "-bg") == 0 && i+1 < argc) {

background = argv[++i]; } else if (strcmp(argv[i], "-hf") == 0 && i+1 < argc) { history_file = argv[++i]; + } else if (strcmp(argv[i], "-cf") == 0 && i+1 < argc) { + completion_file = argv[++i]; } else if (strcmp(argv[i], "-preselect") == 0) { preselect = true; } else if (strcmp(argv[i], "-autocomplete") == 0) {

@@ -170,6 +174,12 @@ // expand and load command history

string expanded_filename = FbTk::StringUtil::expandFilename(history_file); if (!fbrun.loadHistory(expanded_filename.c_str())) cerr<<"FbRun Warning: Failed to load history file: "<<expanded_filename<<endl; + + if (!completion_file.empty()) { + expanded_filename = FbTk::StringUtil::expandFilename(completion_file); + if (!fbrun.loadCompletion(expanded_filename.c_str())) + cerr<<"FbRun Warning: Failed to load completion file: "<<expanded_filename<<endl; + } fbrun.setTitle(title); fbrun.setText(text);