gexec/0000755000175000017500000000000010604003225011467 5ustar todsahtodsahgexec/CHANGELOG0000644000175000017500000000245310604000030012674 0ustar todsahtodsahgExec: ChangeLog ------------------------------------------------------------------------------ [0.4] ( Sun Apr 01 20:55:01 CEST 2007 ) * Applied patch by Corey Wringt. prog_ renamed to cmd_ in config writing. Fixes debian bug #413614. * Added gexec.1 manual page. Taken from Debian package. [0.3] ( Wed Oct 26 16:44:02 CEST 2005 ) * Bugfixes. * Addition of the --keepopen option which will keep gExec open after running a command. [0.2] ( Wed Oct 26 16:44:02 CEST 2005 ) * History now removes double entries. * Rewrite of cmd_run. It's Better Now(tm). * Program exit status no longer used as a means to determine if the execution was succesful. In other words: It's now correct. * Tab-completion now also completes arguments instead of only the command. * Settings file support (~/.gexec) containing termemu, su and history length. Automatically created if non-existant * Clicking the Ok button with the default command (at start-up) still active caused a segfault. Fixed. * Some memory leaks fixed. (Don't worry, plenty are still left) * GNU GPL Header added to source. [0.1] ( Tue Apr 13 23:02:46 CEST 2004 ) * Initial release. gexec/COPYING0000644000175000017500000004312710232257023012535 0ustar todsahtodsah GNU GENERAL PUBLIC LICENSE Version 2, June 1991 Copyright (C) 1989, 1991 Free Software Foundation, Inc. 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Library General Public License instead.) You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in effect making the program proprietary. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any derivative work under copyright law: that is to say, a work containing the Program or a portion of it, either verbatim or with modifications and/or translated into another language. (Hereinafter, translation is included without limitation in the term "modification".) Each licensee is addressed as "you". Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what the Program does. 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change. b) You must cause any work that you distribute or publish, that in whole or in part contains or is derived from the Program or any part thereof, to be licensed as a whole at no charge to all third parties under the terms of this License. c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the most ordinary way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Program, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Program. In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may copy and distribute the Program (or a work based on it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you also do one of the following: a) Accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, b) Accompany it with a written offer, valid for at least three years, to give any third party, for a charge no more than your cost of physically performing source distribution, a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, c) Accompany it with the information you received as to the offer to distribute corresponding source code. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form with such an offer, in accord with Subsection b above.) The source code for a work means the preferred form of the work for making modifications to it. For an executable work, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the executable. However, as a special exception, the source code distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. If distribution of executable or object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code. 4. You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 5. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Program or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Program (or any work based on the Program), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Program or works based on it. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties to this License. 7. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Program at all. For example, if a patent license would not permit royalty-free redistribution of the Program by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Program. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system, which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 8. If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 9. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of this License, you may choose any version ever published by the Free Software Foundation. 10. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) 19yy This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) 19yy name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here is a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (which makes passes at compilers) written by James Hacker. , 1 April 1989 Ty Coon, President of Vice This General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Library General Public License instead of this License. gexec/Makefile0000644000175000017500000000066110604003117013132 0ustar todsahtodsahCC = gcc LIBS = `pkg-config --libs gtk+-2.0` INCS = `pkg-config --cflags gtk+-2.0` FLAGS = -Wall -g main: gexec gexec: autocomp.o gexec.o $(CC) autocomp.o gexec.o -o gexec $(LIBS) $(INCS) $(FLAGS) strip gexec gexec.o: gexec.c $(CC) -c gexec.c $(INCS) $(FLAGS) autocomp.o: autocomp.c autocomp.h $(CC) -c autocomp.c $(INCS) $(FLAGS) clean: -rm gexec -rm *.o install: -cp gexec /usr/local/bin -cp gexec.1 /usr/local/man/man1/ gexec/README0000644000175000017500000001321210604000304012341 0ustar todsahtodsahgExec Version : 0.4 Author : Ferry Boender (please do not publish this email address) License : General Public License homepage : http://www.electricmonk.nl/index.php?page=GExec gExec is a tool for running commands from a GUI. It presents the user with an entry field into which they can type their command and some toggle buttons for specifying how the command should be run. (I.e. in a terminal). Table of contents 1. About gExec 2. Installation 2.1. Requirements 2.2. Compiling 2.3. Installation 2.4. Running 3. Configuration 4. Feedback / Contributing. 4.2. Known bugs 4.1. Credits 5. Legal stuff 6. Author 1. About gExec gExec is a tool for running commands from a GUI. It presents the user with an entry field into which they can type their command and some toggle buttons for specifying how the command should be run. (I.e. in a terminal). It features (normal, understandable, working) tab-completion, history list and options for running commands in a terminal emulator and/or the root user (via gksu). gExec was created because I mainly use GTK programs, but I do not run Gnome (or at least not the panel). Instead I use WindowMaker. WindowMaker does have it's own run dialog, but it doesn't have tab-completion nor does it have a history, which is quite annoying. There are a bunch of third-party program lauchers available, but at the moment of writing none of them do what I want. So came about gExec. 2. Installation 2.1. Requirements In order to compile gExec, you will need: * Gtk 2.0+ development headers * Glib 2.0+ development headers In order to run gExec, you will need: * Gtk 2.0+ dynamically loadable libraries. 2.2. Compiling Compiling gExec is easy. Just type 'make' at the command line in the source directory. 2.3. Installation gExec is composed of only a single binary. You can copy it to any destination on your system. May I suggest some directory that is in your path, like /usr/local/bin? Typing 'make install' at the command line in the source directory will do just that. It copies the binary to /usr/local/bin. That's it. Nothing more, nothing less. 2.4. Running From the --help output: Usage: gexec [OPTION...] - Interactive run dialog Help Options: -?, --help Show help options --help-all Show all help options --help-gtk Show GTK+ Options Application Options: -k, --keepopen Keep gExec open after executing a command --display=DISPLAY X display to use 3. Configuration gExec has a few configuration options which are stored in the file $HOME/.gexec This file will automically be created if not present the first time gExec is run. It can contain three options: cmd_termemu=STRING (default: xterm -e %s ) cmd_su=STRING (default: gksu "%s" ) history_max=INT (default: 20 ) These options should be self-evident. Including a %s in the command will replace it with the command entered by the user in the program. Please be careful about the construction of the commands for the terminal emulator and the SU program. Not all programs will work nicely together and some of the commands need to be carefully crafted taking in account quotes and other stuff. Frankly, changing any of these commands might open up a whole can of worms (which is why there isn't a configuration display). Use at your own risk. 4. Feedback / Contributing. Questions? Problems? Ideas? Mail to: or visit this gExec's project page, where you can submit bugs/feature requests/questions, at: http://projects.electricmonk.nl/ 4.1. Known bugs This program is full of known bugs. Here are some of them: * Running a command in both a terminal and as root fails (depending on the commands used). * Usage of deprecated gtk_combo. * Failure to execute a command via terminal or as root will go unnoticed. Most of these bugs have a reason for not being fixed (and not even because I'm just a lazy bastard). Mostly the reason is that the bugs don't really matter in such a small program, solving the problem opens up new problems or the problem isn't gExec's in the first place. 4.2. Credits I'd like to thank the following people for their help on gExec: * Me. * Anonymous guy who was really Mafkees! * Jose Oswaldo (--keepopen option suggestion) * Corey Wringt (config file bugfixing patch) * Johann Rudloff (Debian GNU/Linux package maintainer) 5. Legal stuff gExec is Copyright by Ferry Boender, licensed under the General Public License (GPL) Copyright (C), 2004 by Ferry Boender This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. For more information, see the COPYING file supplied with this program. 6. Author Exec created by: Ferry Boender (Please do not publish this email address) Homepage: http://www.electricmonk.nl (for address information, please email me. I can't just put my home address on the internet now, can I?) gexec/autocomp.c0000644000175000017500000001300710232257023013467 0ustar todsahtodsah/* * Name : autocomp * Description : Auto-completion library * Version : v0.5 * * Author : Ferry Boender * Copyright : (C) 2004, Ferry Boender * License : General Public License. For more information and terms, see * the COPYING file in this archive. * * Usage : To compile: * /path-to-src/$ make * To test: * /path-to-src/$ ./autocomp * Or * /path-to-src/$ ./autocomp [argument] * * where argument is a (relative/absolute) command to be * completed * Dependencies: glib * Purpose : Provide a library which can be linked against any application * and be used to perform autocompletion on file system oriented * commands. * Revisions : v0.2 [FB] First public release. * v0.3 [FB] Whoops, the .h file got deleted, * v0.4 [FB] Function names now shown in debug output, * Added ac_list_print function. * Added various sanity checks for NULL lists/etc. * Changed test cases in main(). * v0.5 [FB] Forgot to add ac_list_print to the .h file. * Removed the teststub from the main lib and placed it * in a seperate program called 'test'. * Remarks : - * Todo : - * */ #include "autocomp.h" //#define _DEBUG /* Name : ac_path_get * Params : - * Returns : A glib GList containing the broken down values in the PATH * environment variable. * Remarks : - */ GList *ac_path_get (void) { gchar *env_path = NULL; gchar **split_env_paths = NULL; gchar *path = NULL; GList *paths = NULL; int i = 0; if ((env_path = getenv("PATH")) == NULL) { return (NULL); } split_env_paths = g_strsplit (env_path, ":", -1); while ((path = split_env_paths[i]) != NULL) { paths = g_list_append (paths, strdup(path)); i++; } g_strfreev (split_env_paths); return (paths); } /* Name : ac_list_free * Params : A glib GList containing in the data section an hand-allocated * memory part. * Returns : NULL, the data and the GList itself are freed * Remarks : - */ GList *ac_list_free (GList *ac_list) { GList *cur = NULL; if (ac_list == NULL) { #ifdef _DEBUG printf ("ac_list_free: ac_list = NULL\n"); #endif return (NULL); } cur = ac_list; while (cur != NULL) { free (cur->data); cur = g_list_next(cur); } g_list_free (ac_list); return (NULL); } /* Name : ac_list_get * Params : A completion query which should be completed. Examples: * "au" (complete in current dir and path) * "/et" (complete in root dir) * "../a" (comlete in parent dir) * completionn_qry must be a pointer to a valid zero-terminated string. * Returns : A glib GList containing the possibilities for completing the qry. * Example: * completion_qry = "au", current dir has file "autocomplete.c" and * "autocomplete". List is "ocomplete.c", "ocomplete". * Remarks : Use ac_list_free to deep-free mem used by list. */ GList *ac_list_get (char *completion_qry) { GList *paths = NULL; GList *cur = NULL; GList *match = NULL; char *command; if (completion_qry == NULL) { #ifdef _DEBUG printf ("ac_list_get: completion_qry = NULL\n"); #endif return (NULL); } if (strchr(completion_qry, '/')) { /* Absolute or relative path: Search relative path */ char *path_and_file = NULL; char *path = NULL; char *file = NULL; char *last_slash = NULL; path_and_file = strdup(completion_qry); last_slash = strrchr(path_and_file, '/'); last_slash[0] = '\0'; if (completion_qry[0] == '/' && strlen(path_and_file) == 0) { path = strdup("/"); } else { path = strdup(path_and_file); /* Before last slash */ } file = strdup(++last_slash); /* After last slash */ free (path_and_file); paths = g_list_append (paths, strdup(path)); command = strdup(file); free (file); free (path); } else { /* Non-relative path: search current dir and PATH */ command = strdup(completion_qry); /* Get all paths to search in */ paths = ac_path_get(); paths = g_list_append (paths, strdup(".")); } #ifdef _DEBUG printf ("ac_list_get: command: %s\n", command); cur = g_list_first (paths); while (cur != NULL) { printf ("ac_list_get: paths: %s\n", (char *)cur->data); cur = cur->next; } cur = NULL; #endif /* Check all paths to see if they have matching commands */ cur = g_list_first(paths); while (cur != NULL) { DIR *dir = NULL; struct dirent *direntry; dir = opendir ((char *)cur->data); if (dir != NULL) { while ((direntry = readdir(dir)) != NULL) { if ((strcmp(direntry->d_name, ".") != 0) && (strcmp(direntry->d_name, "..") != 0) && (strncmp(direntry->d_name, command, strlen(command)) == 0)) { #ifdef _DEBUG printf ("ac_list_get: match: %s\n", direntry->d_name); #endif match = g_list_append (match, g_strdup(direntry->d_name+strlen(command))); } } } free (cur->data); /* Free data in list */ cur = g_list_next(cur); } g_list_free (paths); /* Free list */ free (command); return (match); } void ac_list_print (GList *ac_list, char *completion_qry) { GList *cur = NULL; if (ac_list == NULL) { return; } cur = g_list_first(ac_list); while (cur != NULL) { printf ("ac_list_print: %s%s\n", completion_qry, (char *)cur->data); cur = g_list_next(cur); } } gexec/autocomp.h0000644000175000017500000000643010232257023013476 0ustar todsahtodsah/* * Name : autocomp * Description : Auto-completion library * Version : v0.4 * * Author : Ferry Boender * Copyright : (C) 2004, Ferry Boender * License : General Public License. For more information and terms, see * the COPYING file in this archive. * * Usage : To compile: * /path-to-src/$ make * To test: * /path-to-src/$ ./autocomp * Or * /path-to-src/$ ./autocomp [argument] * * where argument is a (relative/absolute) command to be * completed * Dependencies: glib * Purpose : Provide a library which can be linked against any application * and be used to perform autocompletion on file system oriented * commands. * Revisions : v0.2 [FB] First public release. * v0.3 [FB] Whoops, the .h file got deleted, * v0.4 [FB] Function names now shown in debug output, * Added ac_list_print function. * Added various sanity checks for NULL lists/etc. * Changed test cases in main(). * v0.5 [FB] Forgot to add ac_list_print to the .h file. * Removed the teststub from the main lib and placed it * in a seperate program called 'test'. * Remarks : - * Todo : - * */ #ifndef __AUTOCOMP_H__ #define __AUTOCOMP_H__ #include #include #include #include #include //#define _DEBUG /* Name : ac_path_get * Params : - * Returns : A glib GList containing the broken down values in the PATH * environment variable. * Remarks : - */ GList *ac_path_get (void); /* Name : ac_list_free * Params : A glib GList containing in the data section an hand-allocated * memory part. * Returns : NULL, the data and the GList itself are freed * Remarks : - */ GList *ac_list_free (GList *ac_list); /* Name : ac_list_get * Params : A completion query which should be completed. Examples: * "au" (complete in current dir and path) * "/et" (complete in root dir) * "../a" (comlete in parent dir) * Returns : A glib GList containing the possibilities for completing the qry. * Example: * completion_qry = "au", current dir has file "autocomplete.c" and * "autocomplete". List is "ocomplete.c", "ocomplete". * Remarks : Use ac_list_free to deep-free mem used by list. */ GList *ac_list_get (char *completion_qry); /* Name : ac_list_print * Params : ac_list: a glib GList containing the matches for a ompletion query * completion_qry: A completion query which will only be used to * prepend it to the completion results. * Returns : - * Remarks : The matches that are printed are prepended with the command_qry, but * the matches themself do not actually contain this prefix. * Ex: ac_list_print (list, "autoc") * prints 'autocomp' where 'autoc' is the completion query and * 'omp' is the match. */ void ac_list_print (GList *ac_list, char *completion_qry); #endif /* __AUTOCOMP_H__ */ gexec/gexec.10000644000175000017500000000143210604002534012646 0ustar todsahtodsah.TH GEXEC 1 "November 2, 2006" .SH NAME gexec \- Interactive run dialog .SH SYNOPSIS .B gexec .RI [ options ] .SH DESCRIPTION This manual page documents briefly the .B gexec command. .PP \fBgexec\fP is a program that runs a small interactive command execution dialog with history and autocompletition. .SH OPTIONS These programs follow the usual GNU command line syntax, with long options starting with two dashes (`-'). A summary of options is included below. For a complete description, see the README file. .TP .B \-h, \-\-help Show summary of options. .TP .B \-k, \-\-keepopen Keep gExec open after executing a command. .SH AUTHOR gexec was written by Ferry Boender. .PP This manual page was written by Johann Rudloff , for the Debian project (but may be used by others). gexec/gexec.c0000644000175000017500000004136610576044677012770 0ustar todsahtodsah/*************************************************************************** * * gExec * * A small GTK program launcher. * * Author : Ferry Boender * License : GPL, General Public License * Todo : - Autocomplete doesn't work mid-command * - Globbing doesn't work (* and ?) * - Tons of memory leaks * - Ugly code * * Copyright (C) 2004 Ferry Boender. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA * ****************************************************************************/ #include #include #include #include #include #include #include #include #include #include #include "autocomp.h" #define OPT_TERM 1 // Run the command in a terminal #define OPT_SU 2 // Run the command as root #define DEFAULT_CMD_TERMEMU "xterm -e %s" #define DEFAULT_CMD_SU "gksu \"%s\"" #define DEFAULT_HISTORY_MAX 20 static GtkWidget *win_main; static gboolean keepopen = FALSE; struct _task { char *command; // Current command int options; // Options (OPT_) char *cmd_termemu; // Terminal emulator char *cmd_su; // Root privilege giver int history_max; // Maximum number of history items to keep char *tabcomp_command; // Command at time of autocompletion start GList *tabcomp_matches; // Possible completions for tabcomp_command GList *tabcomp_current_match; // Current match for tabcomp_command GList *history; // List of previous commands }; struct _settings { char *cmd_termemu; // Terminal emulator string to use char *cmd_su; // SuperUser program to use int history_max; // Maximum number of commands to keep in history list }; struct _task *task_new() { struct _task *ret_task = NULL; ret_task = malloc(sizeof(struct _task)); ret_task->command = NULL; ret_task->options = 0; ret_task->cmd_termemu = NULL; ret_task->cmd_su = NULL; ret_task->tabcomp_matches = NULL; ret_task->tabcomp_current_match = NULL; ret_task->history = NULL; return(ret_task); } GOptionEntry entries[] = { { "keepopen", 'k', 0, G_OPTION_ARG_NONE, &keepopen, "Keep gExec open after executing a command", NULL }, { NULL } }; void task_option_toggle(struct _task *task, int option) { task->options ^= option; } void task_command_set(struct _task *task, char *command) { assert(task != NULL); assert(command != NULL); if (task->command != NULL) { free(task->command); } task->command = strdup(command); } void task_cmd_termemu_set(struct _task *task, char *cmd_termemu) { assert(task != NULL); assert(cmd_termemu != NULL); if (task->cmd_termemu != NULL) { free(task->cmd_termemu); } task->cmd_termemu = strdup(cmd_termemu); } void task_cmd_su_set(struct _task *task, char *cmd_su) { assert(task != NULL); assert(cmd_su != NULL); if (task->cmd_su != NULL) { free(task->cmd_su); } task->cmd_su = strdup(cmd_su); } void task_dump(struct _task *task) { printf("task_dump: struct _task task(@%p):\n", task); printf("\tcommand : %s\n", task->command); printf("\toptions : %i\n", task->options); printf("\tcmd_termemu : %s\n", task->cmd_termemu); printf("\tcmd_su : %s\n", task->cmd_su); printf("\thistory_max : %i\n", task->history_max); printf("\ttabcomp_command : %s\n", task->tabcomp_command); } void settings_create() { FILE *f_out = NULL; char *filename = NULL; filename = (char *)malloc(sizeof(char) * (strlen(getenv("HOME")) + 15 + 1) ); sprintf(filename, "%s/.gexec", getenv("HOME")); f_out = fopen(filename, "w"); if (f_out != NULL) { fprintf(f_out, "cmd_termemu=%s\n", DEFAULT_CMD_TERMEMU); fprintf(f_out, "cmd_su=%s\n", DEFAULT_CMD_SU); fprintf(f_out, "history_max=%i\n", DEFAULT_HISTORY_MAX); fclose(f_out); } free(filename); return; } struct _settings *settings_read() { FILE *f_in = NULL; char *filename = NULL; struct _settings *settings = NULL; char line[4096]; settings = malloc(sizeof(struct _settings)); settings->cmd_termemu = DEFAULT_CMD_TERMEMU; settings->cmd_su = DEFAULT_CMD_SU; settings->history_max = DEFAULT_HISTORY_MAX; filename = (char *)malloc(sizeof(char) * (strlen(getenv("HOME")) + 15 + 1) ); sprintf(filename, "%s/.gexec", getenv("HOME")); f_in = fopen(filename, "r"); if (f_in != NULL) { while (fgets(line, 4096, f_in)) { char *newline_pos; char **tokens; newline_pos = strchr(line, '\n'); newline_pos[0] = '\0'; tokens = g_strsplit(line, "=", 2); if (strcmp(tokens[0], "cmd_termemu") == 0 && tokens[1] != NULL) { settings->cmd_termemu = strdup(tokens[1]); } if (strcmp(tokens[0], "cmd_su") == 0 && tokens[1] != NULL) { settings->cmd_su = strdup(tokens[1]); } if (strcmp(tokens[0], "history_max") == 0 && tokens[1] != NULL) { settings->history_max = atoi(tokens[1]); } g_strfreev(tokens); } fclose(f_in); } else { // No settings yet; create default settings settings_create(); } free(filename); return(settings); } GList *history_read() { FILE *f_in = NULL; char *filename = NULL; GList *history = NULL; char line[4096]; filename = (char *)malloc(sizeof(char) * (strlen(getenv("HOME")) + 15 + 1) ); sprintf(filename, "%s/.gexec_history", getenv("HOME")); f_in = fopen(filename, "r"); if (f_in != NULL) { while (fgets(line, 4096, f_in)) { char *newline_pos; newline_pos = strchr(line, '\n'); newline_pos[0] = '\0'; history = g_list_append(history, strdup(line)); } fclose(f_in); } free(filename); return(history); } int history_write(GList *history, int history_max) { char *filename = NULL; FILE *f_out; GList *cur = NULL; int count = 0; int err = 0; filename = (char *)malloc(sizeof(char) * (strlen(getenv("HOME")) + 15 + 1) ); sprintf(filename, "%s/.gexec_history", getenv("HOME")); cur = history; f_out = fopen(filename, "w"); if (f_out != NULL) { while (cur != NULL && count != history_max) { fprintf(f_out, "%s\n", (char *)cur->data); cur = g_list_next(cur); count++; } fclose(f_out); } else { err = -1; } free(filename); return(err); } void task_history_add(struct _task *task, char *command) { GList *new_history = NULL; GList *iter = NULL; assert(task != NULL); assert(command != NULL); new_history = g_list_append(new_history, strdup(command)); iter = task->history; while (iter != NULL) { // Skip duplicates of 'command' if (strcmp(iter->data, command) != 0) { new_history = g_list_append(new_history, strdup(iter->data)); } free(iter->data); iter = g_list_next(iter); } g_list_free(task->history); task->history = new_history; } // -1 : Invalid command syntax // -2 : Invalid termemu string syntax // -3 : Invalid su string syntax // -4 : Failure to execute command (see errormsg) // otherwise returns 0 int cmd_run(struct _task *task, char **errormsg) { char *final_command = NULL; int argc; char **argv; GError *shellparse_err = NULL; int err = 0; assert(task->command != NULL); assert(task->cmd_termemu != NULL); // Handle execution options. If any options are set, wrap the current // command in the appropriate command. final_command = strdup(task->command); if ((task->options & OPT_TERM) == OPT_TERM) { int buf_size = (strlen(final_command) + strlen(task->cmd_termemu)); char *tmp_command = malloc( sizeof(char) * (buf_size + 1) ); if (snprintf(tmp_command, buf_size, task->cmd_termemu, final_command) >= buf_size) { err = -2; // Invalid termemu string } else { free(final_command); final_command = strdup(tmp_command); } free(tmp_command); } if ((task->options & OPT_SU) == OPT_SU) { int buf_size = (strlen(final_command) + strlen(task->cmd_su)); char *tmp_command = malloc(sizeof(char) * (buf_size + 1) ); if (snprintf(tmp_command, buf_size, task->cmd_su, final_command) >= buf_size) { err = -3; // Invalid su string } else { free(final_command); final_command = strdup(tmp_command); } free(tmp_command); } // Split up commandline string for execution if (g_shell_parse_argv(final_command, &argc, &argv, &shellparse_err) == FALSE) { err = -1; // Invalid command syntax } if (err == 0) { GPid child_pid; GError *error = NULL; argv[argc] = NULL; if (!g_spawn_async (NULL, argv, NULL, G_SPAWN_SEARCH_PATH, NULL, NULL, &child_pid, &error)) { err = -4; *errormsg = strdup(error->message); g_error_free(error); } } free(final_command); return(err); } void cmd_complete_start(struct _task *task) { int argc; char **argv; GError *shellparse_err = NULL; char *last_arg = NULL; if (task->command == NULL) { return; } // Split up command to get last command for completion if (g_shell_parse_argv(task->command, &argc, &argv, &shellparse_err) == FALSE) { return; } last_arg = argv[argc-1]; task->tabcomp_command = strdup(task->command); task->tabcomp_matches = ac_list_get(last_arg); // Possible appends for tabcomp_command if (g_list_length(task->tabcomp_matches) > 0) { task->tabcomp_current_match = task->tabcomp_matches; } else { task->tabcomp_matches = ac_list_free(task->tabcomp_matches); free(task->tabcomp_command); } } void cmd_complete_next(struct _task *task) { if (task->tabcomp_matches == NULL) { return; } // Cycle forwards through the list of matches if (task->tabcomp_current_match == g_list_last(task->tabcomp_matches)) { task->tabcomp_current_match = g_list_first(task->tabcomp_matches); } else { task->tabcomp_current_match = g_list_next(task->tabcomp_current_match); } } void cmd_complete_prev(struct _task *task) { // FIXME: Not yet completed } void cmd_complete_cancel(struct _task *task) { if (task->tabcomp_matches == NULL) { return; } free(task->tabcomp_command); ac_list_free(task->tabcomp_matches); task->tabcomp_matches = NULL; } void ui_error(char *message) { GtkWidget *dialog; dialog = gtk_message_dialog_new(NULL, GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, "Error: %s", message); gtk_dialog_run(GTK_DIALOG(dialog)); gtk_widget_destroy(dialog); } void ui_cmd_run(struct _task *task) { int err = 0; char *errormsg = NULL; err = cmd_run(task, &errormsg); switch (err) { case -1: ui_error("Invalid command syntax."); break; case -2: ui_error("Possible invalid Terminal Emulator command."); break; case -3: ui_error("Possible invalid SU command."); break; case -4: ui_error(errormsg); free(errormsg); break; default: task_history_add(task, task->command); history_write(task->history, task->history_max); if (!keepopen) { gtk_main_quit(); } break; } } // Main window callbacks void ui_win_main_cb_delete_event(GtkWidget *widget, void *data) { gtk_main_quit(); } // Command callbacks void ui_combo_command_cb_activate(GtkWidget *widget, struct _task *task) { task_command_set(task, (char *)gtk_entry_get_text(GTK_ENTRY(widget))); ui_cmd_run(task); } gboolean ui_combo_command_cb_key_press_event(GtkWidget *widget, GdkEventKey *event, struct _task *task) { if (event->keyval == GDK_Escape) { // Abort gexec gtk_main_quit(); } else if (event->keyval == GDK_Tab) { // Tab completion if (task->tabcomp_matches == NULL) { cmd_complete_start(task); } else { cmd_complete_next(task); } if (task->tabcomp_matches != NULL) { char *new_entry = NULL; new_entry = malloc(sizeof(char) * (strlen(task->tabcomp_command) + strlen(task->tabcomp_current_match->data) + 1 ) ); sprintf(new_entry, "%s%s", task->tabcomp_command, (char *)task->tabcomp_current_match->data); gtk_entry_set_text(GTK_ENTRY(widget), new_entry); gtk_entry_set_position(GTK_ENTRY(widget), -1); free(new_entry); } else { } return(TRUE); // Signal has been handled, do not pass tab key further } else { // Normal keypresses // Accept/Clear tabcompletion task_command_set(task, (char *)gtk_entry_get_text(GTK_ENTRY(widget))); cmd_complete_cancel(task); } return(FALSE); } void ui_combo_command_cb_changed(GtkWidget *widget, struct _task *task) { task_command_set(task, (char *)gtk_entry_get_text(GTK_ENTRY(widget))); } // Option callbacks void ui_chk_term_cb_toggled(GtkWidget *widget, struct _task *task) { task_option_toggle(task, OPT_TERM); } void ui_chk_su_cb_toggled(GtkWidget *widget, struct _task *task) { task_option_toggle(task, OPT_SU); } // Button callbacks void ui_btn_ok_cb_clicked(GtkWidget *widget, struct _task *task) { ui_cmd_run(task); } void ui_btn_cancel_cb_clicked(GtkWidget *widget, void *data) { gtk_main_quit(); } int main(int argc, char *argv[]) { GOptionContext *context = NULL; GError *error = NULL; struct _task *task = NULL; struct _settings *settings = NULL; GtkWidget *chk_term, *chk_su; GtkWidget *lbl_command; GtkWidget *combo_command; GtkWidget *vbox_main, *hbox_command, *hbox_options, *hbox_buttons; GtkWidget *btn_ok, *btn_cancel; // Handle commandline options context = g_option_context_new ("- Interactive run dialog"); g_option_context_add_main_entries (context, entries, NULL); g_option_context_add_group (context, gtk_get_option_group (TRUE)); if (!g_option_context_parse (context, &argc, &argv, &error)) { fprintf(stderr, "%s\n", error->message); g_error_free(error); exit(1); } task = task_new(); task->history = history_read(); settings = settings_read(); task->cmd_termemu = settings->cmd_termemu; task->cmd_su = settings->cmd_su; task->history_max = settings->history_max; gtk_init(&argc, &argv); win_main = gtk_window_new(GTK_WINDOW_TOPLEVEL); gtk_window_set_title(GTK_WINDOW(win_main), "gExec"); gtk_window_set_default_size(GTK_WINDOW(win_main), 400, 77); gtk_signal_connect(GTK_OBJECT(win_main), "delete_event", GTK_SIGNAL_FUNC(ui_win_main_cb_delete_event), NULL); // Command hbox_command = gtk_hbox_new(FALSE, 0); lbl_command = gtk_label_new("Run command:"); combo_command = gtk_combo_new(); gtk_combo_disable_activate(GTK_COMBO(combo_command)); gtk_signal_connect(GTK_OBJECT(GTK_COMBO(combo_command)->entry), "activate", GTK_SIGNAL_FUNC(ui_combo_command_cb_activate), task); gtk_signal_connect(GTK_OBJECT(GTK_COMBO(combo_command)->entry), "key-press-event", GTK_SIGNAL_FUNC(ui_combo_command_cb_key_press_event), task); gtk_signal_connect(GTK_OBJECT(GTK_COMBO(combo_command)->entry), "changed", GTK_SIGNAL_FUNC(ui_combo_command_cb_changed), task); if (task->history != NULL) { gtk_combo_set_popdown_strings(GTK_COMBO(combo_command), task->history); } gtk_box_pack_start(GTK_BOX(hbox_command), lbl_command, FALSE, FALSE, 0); gtk_box_pack_start(GTK_BOX(hbox_command), combo_command, TRUE, TRUE, 0); // Options hbox_options = gtk_hbox_new(TRUE, 5); chk_term = gtk_check_button_new_with_mnemonic("Run in _terminal emulator"); gtk_signal_connect(GTK_OBJECT(chk_term), "toggled", GTK_SIGNAL_FUNC(ui_chk_term_cb_toggled), task); gtk_box_pack_start(GTK_BOX(hbox_options), chk_term, FALSE, FALSE, 0); chk_su = gtk_check_button_new_with_mnemonic("Run as _root"); gtk_signal_connect(GTK_OBJECT(chk_su), "toggled", GTK_SIGNAL_FUNC(ui_chk_su_cb_toggled), task); gtk_box_pack_start(GTK_BOX(hbox_options), chk_su, FALSE, FALSE, 0); // Buttons hbox_buttons = gtk_hbox_new(FALSE, 0); btn_ok = gtk_button_new_from_stock(GTK_STOCK_OK); btn_cancel = gtk_button_new_from_stock(GTK_STOCK_CANCEL); gtk_signal_connect(GTK_OBJECT(btn_ok), "clicked", GTK_SIGNAL_FUNC(ui_btn_ok_cb_clicked), task); gtk_signal_connect(GTK_OBJECT(btn_cancel), "clicked", GTK_SIGNAL_FUNC(ui_btn_cancel_cb_clicked), NULL); gtk_box_pack_start(GTK_BOX(hbox_buttons), btn_ok, TRUE, TRUE, 0); gtk_box_pack_start(GTK_BOX(hbox_buttons), btn_cancel, TRUE, TRUE, 0); // Main vbox_main = gtk_vbox_new(FALSE, 0); gtk_box_pack_start(GTK_BOX(vbox_main), hbox_command, TRUE, TRUE, 0); gtk_box_pack_start(GTK_BOX(vbox_main), hbox_options, TRUE, TRUE, 0); gtk_box_pack_start(GTK_BOX(vbox_main), hbox_buttons, TRUE, TRUE, 0); gtk_container_add(GTK_CONTAINER(win_main), vbox_main); gtk_container_set_border_width(GTK_CONTAINER(win_main), 5); // Booom! gtk_widget_show_all(win_main); gtk_widget_grab_focus(combo_command); gtk_main(); free(task); return(0); }