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.
This commit is contained in:
parent
8094f4d1a9
commit
baaf477d46
4 changed files with 33 additions and 1 deletions
|
@ -69,6 +69,10 @@ OPTIONS
|
|||
*-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
|
||||
|
||||
|
|
|
@ -214,6 +214,23 @@ bool FbRun::loadHistory(const char *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 @@ void FbRun::tabCompleteApps() {
|
|||
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;
|
||||
|
|
|
@ -58,6 +58,7 @@ public:
|
|||
@return true on success, else false
|
||||
*/
|
||||
bool loadHistory(const char *filename);
|
||||
bool loadCompletion(const char *filename);
|
||||
/**
|
||||
@name events
|
||||
*/
|
||||
|
|
|
@ -66,6 +66,7 @@ void showUsage(const char *progname) {
|
|||
" -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 @@ int main(int argc, char **argv) {
|
|||
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 @@ int main(int argc, char **argv) {
|
|||
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) {
|
||||
|
@ -171,6 +175,12 @@ int main(int argc, char **argv) {
|
|||
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);
|
||||
if (preselect)
|
||||
|
|
Loading…
Reference in a new issue