├── .gitignore ├── mv_docs.sh ├── docs ├── data │ ├── xstarter_1.png │ ├── xstarter_2.png │ └── helm_xstarter.png ├── static │ └── styles.css ├── screenshots-and-videos.html ├── downloads.html ├── version-0-8-1-released.html ├── emacs-interface.html ├── emacs-interface-available.html ├── posts.xml ├── version-0-7-0-released.html ├── version-0-8-0-released.html └── index.html ├── docs_source └── xstarter │ ├── source │ ├── data │ │ ├── xstarter_1.png │ │ ├── xstarter_2.png │ │ └── helm_xstarter.png │ ├── pages │ │ ├── screenshots-and-videos.md │ │ ├── downloads.md │ │ └── emacs-interface.md │ ├── posts │ │ ├── version-0-8-1-released.md │ │ ├── emacs-interface-available-for-xstarter.md │ │ ├── version-0-7-0-released.md │ │ └── version-0-8-0-released.md │ └── index.md │ ├── scipio.toml │ └── themes │ └── default │ ├── static │ └── styles.css │ ├── page.html │ ├── post.html │ └── index.html ├── src ├── term.h ├── scan.h ├── list.h ├── utils_string.h ├── settings.h ├── main.c ├── utils.h ├── list.c ├── utils_string.c ├── settings.c ├── scan.c ├── term.c └── utils.c ├── .clang-format ├── .bumpversion.cfg ├── tests ├── test.h ├── test_strings.h ├── test_xs_dirname.h ├── test_expand_tilde.h ├── test.c ├── test_settings.h └── test_str_array.h ├── clean.sh ├── PKGBUILD ├── cmake ├── cmake_uninstall.cmake.in ├── FindGlib.cmake └── LibFindMacros.cmake ├── INSTALL.md ├── CHANGELOG ├── CMakeLists.txt ├── xstarter.conf ├── .travis.yml ├── xstarter.1 ├── README.md ├── external └── inih │ ├── ini.h │ └── ini.c └── LICENSE /.gitignore: -------------------------------------------------------------------------------- 1 | *~ -------------------------------------------------------------------------------- /mv_docs.sh: -------------------------------------------------------------------------------- 1 | rm -r docs/ 2 | 3 | mv ./docs_source/xstarter/build/ ./docs/ 4 | -------------------------------------------------------------------------------- /docs/data/xstarter_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lchsk/xstarter/HEAD/docs/data/xstarter_1.png -------------------------------------------------------------------------------- /docs/data/xstarter_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lchsk/xstarter/HEAD/docs/data/xstarter_2.png -------------------------------------------------------------------------------- /docs/data/helm_xstarter.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lchsk/xstarter/HEAD/docs/data/helm_xstarter.png -------------------------------------------------------------------------------- /docs_source/xstarter/source/data/xstarter_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lchsk/xstarter/HEAD/docs_source/xstarter/source/data/xstarter_1.png -------------------------------------------------------------------------------- /docs_source/xstarter/source/data/xstarter_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lchsk/xstarter/HEAD/docs_source/xstarter/source/data/xstarter_2.png -------------------------------------------------------------------------------- /docs_source/xstarter/source/data/helm_xstarter.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lchsk/xstarter/HEAD/docs_source/xstarter/source/data/helm_xstarter.png -------------------------------------------------------------------------------- /src/term.h: -------------------------------------------------------------------------------- 1 | #ifndef XSTARTER_TERM_H 2 | #define XSTARTER_TERM_H 3 | 4 | void init_term_gui(void); 5 | void run_term(void); 6 | void cache_loaded(void); 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /.clang-format: -------------------------------------------------------------------------------- 1 | --- 2 | AllowShortFunctionsOnASingleLine: None 3 | BreakBeforeBraces: Linux 4 | ColumnLimit: '80' 5 | IndentWidth: '4' 6 | Language: Cpp 7 | PointerAlignment: Right 8 | SortIncludes: 'true' 9 | SpaceAfterLogicalNot: 'false' 10 | TabWidth: '0' 11 | -------------------------------------------------------------------------------- /.bumpversion.cfg: -------------------------------------------------------------------------------- 1 | [bumpversion] 2 | current_version = 0.8.1 3 | commit = False 4 | tag = False 5 | 6 | [bumpversion:file:CMakeLists.txt] 7 | 8 | [bumpversion:file:xstarter.1] 9 | 10 | [bumpversion:file:src/settings.h] 11 | 12 | [bumpversion:file:PKGBUILD] 13 | 14 | [bumpversion:file:README.md] 15 | -------------------------------------------------------------------------------- /docs_source/xstarter/scipio.toml: -------------------------------------------------------------------------------- 1 | # Base URL of the website 2 | url = "https://lchsk.com/xstarter" 3 | 4 | [rss] 5 | # Settings for the RSS feed 6 | generate_rss = true 7 | title = "xstarter - GNU/Linux terminal application launcher" 8 | description = "xstarter - terminal application launcher for GNU/Linux" 9 | author_name = "Maciej Lechowski" 10 | author_email = "" -------------------------------------------------------------------------------- /docs/static/styles.css: -------------------------------------------------------------------------------- 1 | body { 2 | font-family: "Georgia", serif; 3 | font-size: 1.2em; 4 | line-height: 120%; 5 | } 6 | 7 | a:link { 8 | color: #bd4f6c; 9 | } 10 | 11 | ul { 12 | list-style-type: none; 13 | margin: 0; 14 | padding: 0; 15 | } 16 | 17 | ul li.float { 18 | display: inline-block; 19 | } 20 | 21 | h1, h2, h3, h4, h5, h6 { 22 | line-height: 110%; 23 | } 24 | 25 | h2, h3, h4, h5, h6 { 26 | font-style: italic; 27 | } 28 | -------------------------------------------------------------------------------- /docs_source/xstarter/themes/default/static/styles.css: -------------------------------------------------------------------------------- 1 | body { 2 | font-family: "Georgia", serif; 3 | font-size: 1.2em; 4 | line-height: 120%; 5 | } 6 | 7 | a:link { 8 | color: #bd4f6c; 9 | } 10 | 11 | ul { 12 | list-style-type: none; 13 | margin: 0; 14 | padding: 0; 15 | } 16 | 17 | ul li.float { 18 | display: inline-block; 19 | } 20 | 21 | h1, h2, h3, h4, h5, h6 { 22 | line-height: 110%; 23 | } 24 | 25 | h2, h3, h4, h5, h6 { 26 | font-style: italic; 27 | } 28 | -------------------------------------------------------------------------------- /src/scan.h: -------------------------------------------------------------------------------- 1 | #ifndef XSTARTER_SCAN_H 2 | #define XSTARTER_SCAN_H 3 | 4 | #include "list.h" 5 | #include "settings.h" 6 | #include "utils.h" 7 | 8 | void init_search(void); 9 | void free_search(void); 10 | bool search(const char *query, unsigned query_len); 11 | extern List *results; 12 | 13 | void load_cache(CmdLine *cmdline, bool extra_thread); 14 | void print_cache_apps(void); 15 | void free_cache(void); 16 | void kill_scan(void); 17 | bool is_cache_ready(void); 18 | 19 | #endif 20 | -------------------------------------------------------------------------------- /docs_source/xstarter/source/pages/screenshots-and-videos.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Screenshots and videos 3 | created: 2018-03-26T00:00:00Z 4 | description: xstarter screenshots and videos 5 | keywords: screenshots, videos, xstarter, c, application launcher, linux, open source, gui, terminal 6 | --- 7 | 8 | [See the asciinema video](https://asciinema.org/a/45bfamrd5zkz7uv3x6rrasra7) 9 | 10 | ![xstarter screenshot](./data/xstarter_2.png) 11 | 12 | ![xstarter screenshot](./data/xstarter_1.png) 13 | -------------------------------------------------------------------------------- /src/list.h: -------------------------------------------------------------------------------- 1 | #ifndef LIST_H 2 | #define LIST_H 3 | 4 | #include 5 | 6 | typedef struct { 7 | size_t size; 8 | size_t cap; 9 | void **data; 10 | } List; 11 | 12 | List *list_new(size_t initial_size); 13 | void list_free(List *list); 14 | void list_append(List *list, void *value); 15 | void *list_get(List *list, size_t index); 16 | size_t list_size(List *list); 17 | void list_del(List *list, size_t index); 18 | size_t list_in(List *list, void *value); 19 | 20 | #endif /* LIST_H */ -------------------------------------------------------------------------------- /tests/test.h: -------------------------------------------------------------------------------- 1 | #define mu_assert(message, test) do { \ 2 | if (!(test)) { \ 3 | printf("Failure in test: %s\n", __func__); \ 4 | return message; \ 5 | } \ 6 | } while (0) 7 | 8 | #define mu_test(name) \ 9 | char* name() 10 | 11 | 12 | #define mu_run_test(test) do { char *message = test(); tests_run++; \ 13 | if (message) return message; } while (0) 14 | extern int tests_run; 15 | -------------------------------------------------------------------------------- /docs_source/xstarter/source/pages/downloads.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Downloads 3 | created: 2018-03-26T00:00:00Z 4 | description: Downloads page for xstarter application launcher 5 | keywords: downloads, deb packages, xstarter, c, application launcher, linux, open source 6 | --- 7 | 8 | It is available on [AUR](https://aur.archlinux.org/packages/xstarter) 9 | 10 | You can also get get [DEB and RPM packages](https://github.com/lchsk/xstarter/releases) 11 | 12 | Alternatively, it can be easily compiled from [source code](https://github.com/lchsk/xstarter) 13 | -------------------------------------------------------------------------------- /clean.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | echo "Cleaning xstarter directory..." 4 | rm -f Makefile 5 | rm -f CMakeCache.txt 6 | rm -f cmake_install.cmake 7 | rm -f cmake_uninstall.cmake 8 | rm -f install_manifest.txt 9 | rm -f nohup.out 10 | rm -rf CMakeFiles 11 | rm -rf ./bin 12 | rm -rf _CPack_Packages 13 | rm -f xstarter-*.deb 14 | rm -f xstarter-*.tar.gz 15 | rm -f xstarter-*.zip 16 | rm -f CPackSourceConfig.cmake CPackConfig.cmake 17 | 18 | echo "Cleaning tests..." 19 | 20 | cd tests; \ 21 | rm -f Makefile; \ 22 | rm -f CMakeCache.txt; \ 23 | rm -rf CMakeFiles; \ 24 | rm -rf cmake_install.cmake; \ 25 | rm -rf xstarter_tests 26 | -------------------------------------------------------------------------------- /docs_source/xstarter/source/posts/version-0-8-1-released.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Version 0.8.1 released 3 | created: 2020-05-25T00:00:00Z 4 | description: It's a tiny release but it contains necessary fixes for xstarter to compile with gcc 10. 5 | keywords: new release, xstarter, c, application launcher, linux, open source, external programs, blog 6 | 7 | --- 8 | 9 | New version of **xstarter** (v0.8.1) was released today. 10 | 11 | It's a tiny release but it contains necessary fixes for xstarter to compile with gcc 10. 12 | 13 | ## How to get it? 14 | 15 | - [See releases](https://github.com/lchsk/xstarter/releases) 16 | 17 | - [Source code](https://github.com/lchsk/xstarter) 18 | -------------------------------------------------------------------------------- /docs_source/xstarter/source/pages/emacs-interface.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Emacs interface 3 | created: 2018-03-27T00:00:00Z 4 | description: Emacs interface for xstarter 5 | keywords: emacs, interface, helm, helm-xstarter, helm interface, xstarter, application launcher emacs 6 | --- 7 | 8 | [Emacs package `helm-xstarter`](https://github.com/lchsk/helm-xstarter) offers an intuitive interface to launch applications via Emacs. 9 | 10 | It loads a list of installed applications and lets a user select one to launch. 11 | 12 | It also records recently open programs and shows them on top. 13 | 14 | ![`helm-xstarter` session](data/helm_xstarter.png) 15 | 16 | **See [github page for installation instructions](https://github.com/lchsk/helm-xstarter)**! 17 | -------------------------------------------------------------------------------- /docs_source/xstarter/source/posts/emacs-interface-available-for-xstarter.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Emacs interface available 3 | created: 2018-08-28T00:00:00Z 4 | description: New Emacs package allows to launch application with xstarter directly from Emacs! 5 | keywords: xstarter, emacs, helm, application launcher, linux launcher 6 | --- 7 | 8 | There's [Emacs interface](https://github.com/lchsk/helm-xstarter) available for xstarter! 9 | 10 | ![`helm-xstarter` session](data/helm_xstarter.png) 11 | 12 | It uses Helm interface that many Emacs users are familiar with. 13 | 14 | It loads a list of installed applications and lets a user select one to launch. It also records recently open programs and shows them on top. 15 | 16 | **See [github page for installation instructions](https://github.com/lchsk/helm-xstarter)**! 17 | -------------------------------------------------------------------------------- /src/utils_string.h: -------------------------------------------------------------------------------- 1 | #ifndef XSTARTER_UTILS_STRING_H 2 | #define XSTARTER_UTILS_STRING_H 3 | 4 | #include 5 | #include 6 | 7 | typedef struct StrArray { 8 | char **data; 9 | char *base_str; 10 | int length; 11 | } StrArray; 12 | 13 | char *xs_strdup(const char *str); 14 | 15 | StrArray *str_array_new(char *input_str, char const *delimiters); 16 | void str_array_strip(StrArray *str_array); 17 | void str_array_free(StrArray *str_array); 18 | 19 | /* Replace tilde with a home directory */ 20 | char *expand_tilde(char *str, const char *home); 21 | 22 | /* Return a newly allocated dirname */ 23 | char *xs_dirname(char *str); 24 | 25 | /* Return basename of path */ 26 | char *xs_basename(const char *path); 27 | 28 | /* Copy string from src to destination */ 29 | void str_copy(char *dest, const char *src, size_t dest_size); 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /tests/test_strings.h: -------------------------------------------------------------------------------- 1 | #include "../src/utils_string.h" 2 | 3 | mu_test(test_str_copy_smaller_than_max_str_length) { 4 | char dest[5]; 5 | char src[5]; 6 | 7 | memcpy(dest, "", sizeof(dest)); 8 | memcpy(src, "", sizeof(src)); 9 | 10 | str_copy(src, "test", sizeof(src)); 11 | str_copy(dest, src, sizeof(dest)); 12 | 13 | mu_assert("not equal", strcmp(dest, "test") == 0); 14 | mu_assert("not valid", src[4] == '\0'); 15 | mu_assert("not valid", dest[4] == '\0'); 16 | 17 | return 0; 18 | } 19 | 20 | mu_test(test_str_copy_equal_to_max) { 21 | char dest[4]; 22 | char src[4]; 23 | 24 | memcpy(dest, "", sizeof(dest)); 25 | memcpy(src, "", sizeof(src)); 26 | 27 | str_copy(src, "test", sizeof(src)); 28 | str_copy(dest, src, sizeof(dest)); 29 | 30 | mu_assert("", strcmp(src, "tes") == 0); 31 | mu_assert("", strcmp(dest, "tes") == 0); 32 | 33 | return 0; 34 | } 35 | -------------------------------------------------------------------------------- /PKGBUILD: -------------------------------------------------------------------------------- 1 | # Maintainer: Maciej Lechowski 2 | pkgname=xstarter 3 | pkgver=0.8.2 4 | _gitname=xstarter 5 | pkgrel=1 6 | epoch= 7 | pkgdesc="Application launcher for Linux" 8 | arch=('any') 9 | url="https://github.com/lchsk/xstarter" 10 | license=('GPL') 11 | groups=() 12 | depends=('ncurses' 'glib2') 13 | makedepends=('git' 'cmake') 14 | checkdepends=() 15 | optdepends=() 16 | provides=('xstarter') 17 | conflicts=('xstarter') 18 | replaces=() 19 | backup=() 20 | options=() 21 | install= 22 | changelog= 23 | source=(https://github.com/lchsk/xstarter/releases/download/v0.8.2/xstarter-0.8.2-Linux.tar.gz) 24 | noextract=() 25 | md5sums=(e478ff94bd7cc9ca2e483c18fb260174) 26 | validpgpkeys=() 27 | 28 | package() { 29 | cd "$srcdir" 30 | 31 | install -Dm755 "$srcdir"/xstarter-"$pkgver"-Linux/bin/xstarter "$pkgdir"/usr/bin/xstarter 32 | install -Dm644 "$srcdir"/xstarter-"$pkgver"-Linux/share/man/man1/xstarter.1 "$pkgdir"/usr/share/man/man1/xstarter.1 33 | } 34 | -------------------------------------------------------------------------------- /docs_source/xstarter/themes/default/page.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 13 | 14 | 15 | 16 | 17 | 18 | {{title}} 19 | 20 | 21 | 22 | 23 |
{{@index}}
24 |
25 |

{{title}}

26 | {{body}} 27 |
28 | 29 | 30 | -------------------------------------------------------------------------------- /docs_source/xstarter/themes/default/post.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 13 | 14 | 15 | 16 | 17 | 18 | {{title}} 19 | 20 | 21 | 22 | 23 |
{{@index}}
24 |
25 |

{{title}}

26 | {{date}} 27 | {{body}} 28 |
29 | 30 | 31 | -------------------------------------------------------------------------------- /cmake/cmake_uninstall.cmake.in: -------------------------------------------------------------------------------- 1 | if(NOT EXISTS "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt") 2 | message(FATAL_ERROR "Cannot find install manifest: @CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt") 3 | endif(NOT EXISTS "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt") 4 | 5 | file(READ "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt" files) 6 | string(REGEX REPLACE "\n" ";" files "${files}") 7 | foreach(file ${files}) 8 | message(STATUS "Uninstalling $ENV{DESTDIR}${file}") 9 | if(IS_SYMLINK "$ENV{DESTDIR}${file}" OR EXISTS "$ENV{DESTDIR}${file}") 10 | exec_program( 11 | "@CMAKE_COMMAND@" ARGS "-E remove \"$ENV{DESTDIR}${file}\"" 12 | OUTPUT_VARIABLE rm_out 13 | RETURN_VALUE rm_retval 14 | ) 15 | if(NOT "${rm_retval}" STREQUAL 0) 16 | message(FATAL_ERROR "Problem when removing $ENV{DESTDIR}${file}") 17 | endif(NOT "${rm_retval}" STREQUAL 0) 18 | else(IS_SYMLINK "$ENV{DESTDIR}${file}" OR EXISTS "$ENV{DESTDIR}${file}") 19 | message(STATUS "File $ENV{DESTDIR}${file} does not exist.") 20 | endif(IS_SYMLINK "$ENV{DESTDIR}${file}" OR EXISTS "$ENV{DESTDIR}${file}") 21 | endforeach(file) -------------------------------------------------------------------------------- /INSTALL.md: -------------------------------------------------------------------------------- 1 | # Installation 2 | 3 | ## Arch Linux (AUR) 4 | 5 | Use AUR to install it: 6 | 7 | `git clone https://aur.archlinux.org/xstarter.git` 8 | 9 | `cd xstarter && makepkg -is` 10 | 11 | See xstarter in Arch Linux AUR: https://aur.archlinux.org/packages/xstarter/ 12 | 13 | ## DEB package 14 | 15 | Download `.deb` package from https://github.com/lchsk/xstarter/releases 16 | 17 | `apt install -f xstarter-*.deb` 18 | 19 | ## RPM package 20 | 21 | Download `.rpm` package from https://github.com/lchsk/xstarter/releases 22 | 23 | `dnf install xstarter-*.rpm` 24 | 25 | ## From source 26 | 27 | ``` 28 | git clone https://github.com/lchsk/xstarter/ 29 | cd xstarter && cmake . && make && sudo make install 30 | ``` 31 | 32 | In order to compile it, you need development versions of the following libraries installed: 33 | 34 | * ncurses e.g. 5.9, 6.0 35 | * glib2 36 | 37 | ## Using archives 38 | 39 | Download `.tar.gz` or `.zip` archive from https://github.com/lchsk/xstarter/releases 40 | 41 | Extract it 42 | 43 | Run `./bin/xstarter` to open the application in the terminal. You can manually copy it to a directory included in your `$PATH`. 44 | -------------------------------------------------------------------------------- /cmake/FindGlib.cmake: -------------------------------------------------------------------------------- 1 | # - Try to find Glib-2.0 (with gobject) 2 | # Once done, this will define 3 | # 4 | # Glib_FOUND - system has Glib 5 | # Glib_INCLUDE_DIRS - the Glib include directories 6 | # Glib_LIBRARIES - link these to use Glib 7 | 8 | include(LibFindMacros) 9 | 10 | # Use pkg-config to get hints about paths 11 | libfind_pkg_check_modules(Glib_PKGCONF glib-2.0>=2.16) 12 | 13 | # Main include dir 14 | find_path(Glib_INCLUDE_DIR 15 | NAMES glib.h 16 | PATHS ${Glib_PKGCONF_INCLUDE_DIRS} 17 | PATH_SUFFIXES glib-2.0 18 | ) 19 | 20 | # Glib-related libraries also use a separate config header, which is in lib dir 21 | find_path(GlibConfig_INCLUDE_DIR 22 | NAMES glibconfig.h 23 | PATHS ${Glib_PKGCONF_INCLUDE_DIRS} /usr 24 | PATH_SUFFIXES lib/glib-2.0/include 25 | ) 26 | 27 | # Finally the library itself 28 | find_library(Glib_LIBRARY 29 | NAMES glib-2.0 30 | PATHS ${Glib_PKGCONF_LIBRARY_DIRS} 31 | ) 32 | 33 | # Set the include dir variables and the libraries and let libfind_process do the rest. 34 | # NOTE: Singular variables for this library, plural for libraries this this lib depends on. 35 | set(Glib_PROCESS_INCLUDES Glib_INCLUDE_DIR GlibConfig_INCLUDE_DIR) 36 | set(Glib_PROCESS_LIBS Glib_LIBRARY) 37 | libfind_process(Glib) 38 | 39 | -------------------------------------------------------------------------------- /src/settings.h: -------------------------------------------------------------------------------- 1 | #ifndef XSTARTER_SETTINGS_H 2 | #define XSTARTER_SETTINGS_H 3 | 4 | #include "utils.h" 5 | #include "utils_string.h" 6 | 7 | /* Name of the configuration file that 8 | should be in a $HOME/.xstarter.d directory */ 9 | 10 | #define CONFIG_FILE "xstarter.conf" 11 | 12 | #define PROGRAM_NAME "xstarter" 13 | #define XSTARTER_VERSION "0.8.2" 14 | 15 | typedef struct { 16 | bool verbose; 17 | char *config_path; 18 | bool force_cache_refresh; 19 | 20 | // Print a list of cache applications 21 | // Can be used by external programs 22 | bool print_list_of_cache_apps; 23 | } CmdLine; 24 | 25 | typedef struct { 26 | StrArray *dirs; 27 | char *terminal; 28 | bool emacs_bindings; 29 | bool recent_apps_first; 30 | int min_query_len; 31 | bool allow_spaces; 32 | bool numeric_shortcuts; 33 | bool use_cache; 34 | bool auto_cache_refresh; 35 | } ConfigMain; 36 | 37 | typedef struct { 38 | char *selected; 39 | } ConfigColors; 40 | 41 | typedef struct { 42 | ConfigMain *section_main; 43 | ConfigColors *section_colors; 44 | } Config; 45 | 46 | Config *config_load(CmdLine *cmdline); 47 | void config_free(Config *config); 48 | const Config *config_get(); 49 | 50 | int cmdline_read(CmdLine *cmdline, int argc, char **argv); 51 | void cmdline_free(CmdLine *cmdline); 52 | 53 | #endif 54 | -------------------------------------------------------------------------------- /docs_source/xstarter/source/posts/version-0-7-0-released.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Version 0.7.0 released 3 | created: 2018-03-26T00:00:00Z 4 | description: New version of xstarter is available (v0.7.0). It adds one useful feature: you can now provide arguments to the application. It works for GUI and terminal programs alike. 5 | keywords: xstarter, c, application launcher, linux, open source, gui, terminal 6 | --- 7 | 8 | New version of **xstarter** is available (v0.7.0). It adds one useful feature: you can now provide arguments to the application. It works for GUI and terminal programs alike. This allows to start a program like this: `surf gnu.org` (GUI) or e.g. `emacs -nw -Q`. 9 | 10 | ## How to use it? 11 | If the number of search results is equal to 1, you can provide arguments the selected application should be started with, e.g. `surf gnu.org`. You can provide multiple arguments, e.g. `emacs -nw -Q`. You can select the application you want to provide arguments for by pressing `Tab` key 12 | This feature works both with GUI (press Enter to start) and terminal applications (press C-o to start) 13 | 14 | ## How to get it? 15 | 16 | - It is available on [AUR](https://aur.archlinux.org/packages/xstarter) 17 | 18 | - You can also get get [DEB and RPM packages](https://github.com/lchsk/xstarter/releases) 19 | 20 | - Alternatively, it can be easily compiled from [source code](https://github.com/lchsk/xstarter) 21 | -------------------------------------------------------------------------------- /docs_source/xstarter/source/posts/version-0-8-0-released.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Version 0.8.0 released 3 | created: 2018-08-27T00:00:00Z 4 | description: New version of xstarter is available (v0.8.0). It adds one useful feature: you can now provide arguments to the application. It works for GUI and terminal programs alike. 5 | keywords: new release, xstarter, c, application launcher, linux, open source, external programs, blog 6 | 7 | --- 8 | 9 | New version of **xstarter** (v0.8.0) was released today. 10 | 11 | Main intention of this release was to enable xstarter to work with external programs. I want to be able to use xstarter via Emacs and I'm working on a small package that will handle that. With this release xstarter is able to print a list of programs that it stored in cache (it can be tested by running `xstarter -P`). External applications can use it load the list of available programs and show it to users. In order to start a program, e.g. Firefox, use command `xstarter -e firefox`. It can be used on its own to start and detach applications from terminal as well by other software. 12 | 13 | In this release I've also fixed an interesting bug that broke xstarter if it was built without compiler optimisation. I wrote about that bug [on my blog](https://lchsk.com/when-the-compiler-fixes-your-mistakes.html). 14 | 15 | ## How to get it? 16 | 17 | - [See releases](https://github.com/lchsk/xstarter/releases) 18 | 19 | - [Source code](https://github.com/lchsk/xstarter) 20 | -------------------------------------------------------------------------------- /docs/screenshots-and-videos.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 13 | 14 | 15 | 16 | 17 | 18 | Screenshots and videos 19 | 20 | 21 | 22 | 23 |
xstarter - GNU/Linux terminal application launcher
24 |
25 |

Screenshots and videos

26 |

See the asciinema video

27 | 28 |

xstarter screenshot

29 | 30 |

xstarter screenshot

31 | 32 |
33 | 34 | 35 | -------------------------------------------------------------------------------- /tests/test_xs_dirname.h: -------------------------------------------------------------------------------- 1 | #include "../src/utils_string.h" 2 | #include "../src/utils.h" 3 | 4 | mu_test(xs_dirname_null) 5 | { 6 | char *result = xs_dirname(NULL); 7 | 8 | mu_assert("", strcmp(result, ".") == 0); 9 | 10 | free(result); 11 | 12 | return 0; 13 | } 14 | 15 | mu_test(xs_dirname_full_path) 16 | { 17 | char *result = xs_dirname("/usr/lib"); 18 | 19 | mu_assert(result, strcmp(result, "/usr") == 0); 20 | 21 | free(result); 22 | 23 | return 0; 24 | } 25 | 26 | mu_test(xs_dirname_slash_not_found) 27 | { 28 | char *result = xs_dirname("usr"); 29 | 30 | mu_assert("", strcmp(result, ".") == 0); 31 | 32 | free(result); 33 | 34 | return 0; 35 | } 36 | 37 | mu_test(xs_dirname_trailing_slash) 38 | { 39 | char *result = xs_dirname("/usr/"); 40 | 41 | mu_assert("", strcmp(result, "/") == 0); 42 | 43 | free(result); 44 | 45 | return 0; 46 | } 47 | 48 | mu_test(xs_dirname_slash_only) 49 | { 50 | char *result = xs_dirname("/"); 51 | 52 | mu_assert("", strcmp(result, "/") == 0); 53 | 54 | free(result); 55 | 56 | return 0; 57 | } 58 | 59 | mu_test(xs_dirname_double_slash) 60 | { 61 | char *result = xs_dirname("//"); 62 | 63 | mu_assert("", strcmp(result, "/") == 0); 64 | 65 | free(result); 66 | 67 | return 0; 68 | } 69 | 70 | mu_test(xs_dirname_empty) 71 | { 72 | char *result = xs_dirname(""); 73 | 74 | mu_assert("", strcmp(result, ".") == 0); 75 | 76 | free(result); 77 | 78 | return 0; 79 | } 80 | -------------------------------------------------------------------------------- /docs/downloads.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 13 | 14 | 15 | 16 | 17 | 18 | Downloads 19 | 20 | 21 | 22 | 23 |
xstarter - GNU/Linux terminal application launcher
24 |
25 |

Downloads

26 |

It is available on AUR

27 | 28 |

You can also get get DEB and RPM packages

29 | 30 |

Alternatively, it can be easily compiled from source code

31 | 32 |
33 | 34 | 35 | -------------------------------------------------------------------------------- /src/main.c: -------------------------------------------------------------------------------- 1 | #define _GNU_SOURCE // execvpe 2 | #include 3 | #include 4 | #include 5 | #include // umask 6 | #include // execvpe, readlink 7 | 8 | #include "scan.h" 9 | #include "settings.h" 10 | #include "term.h" 11 | #include "utils.h" 12 | 13 | int main(int argc, char **argv) 14 | { 15 | set_err(NO_ERR); 16 | xstarter_directory(); 17 | init_search(); 18 | 19 | CmdLine *cmdline = smalloc(sizeof(CmdLine)); 20 | 21 | if (cmdline_read(cmdline, argc, argv)) 22 | exit(EXIT_FAILURE); 23 | 24 | config_load(cmdline); 25 | 26 | if (cmdline->print_list_of_cache_apps) { 27 | // Print applications from cache; to be used by external programs 28 | load_cache(cmdline, /* extra_thread */ false); 29 | print_cache_apps(); 30 | 31 | exit(EXIT_SUCCESS); 32 | } 33 | 34 | const Config *conf = config_get(); 35 | 36 | str_copy(exec_term, conf->section_main->terminal, sizeof(exec_term)); 37 | 38 | if (!in_terminal()) { 39 | cmdline_free(cmdline); 40 | config_free(config_get()); 41 | 42 | open_itself(argc, argv); 43 | } 44 | 45 | init_term_gui(); 46 | 47 | load_cache(cmdline, /* extra_thread */ true); 48 | 49 | run_term(); 50 | 51 | kill_scan(); 52 | free_cache(); 53 | free_search(); 54 | config_free(config_get()); 55 | 56 | if (cmdline->verbose) { 57 | print_err(); 58 | } 59 | 60 | cmdline_free(cmdline); 61 | 62 | return get_err(); 63 | } 64 | -------------------------------------------------------------------------------- /docs_source/xstarter/themes/default/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 13 | 14 | 15 | 16 | 17 | 18 | {{title}} 19 | 20 | 21 | 22 | 23 |
24 |

{{title}}

25 |
26 |
27 |
    28 |
  • {{@downloads}}
  • 29 |
  • {{@screenshots-and-videos}}
  • 30 |
  • {{@emacs-interface}}
  • 31 |
  • xstarter on github
  • 32 |
33 |
34 |
35 |
36 |

News

37 |
    38 | {{posts-begin}} 39 |
  • {{post_link}}
  • 40 | {{posts-end}} 41 |
      42 |
43 |
44 | {{body}} 45 |
46 |
47 | 48 | 49 | -------------------------------------------------------------------------------- /CHANGELOG: -------------------------------------------------------------------------------- 1 | xstarter change log 2 | 3 | 0.8.2 4 | 13/09/2022 5 | * Remove glib dependency 6 | 7 | 0.8.1 8 | 25/05/2020 9 | * Make xstarter compile with gcc 10 10 | * Fix buggy item highlighting 11 | * Improve build script 12 | 13 | 0.8.0 14 | 27/08/2018 15 | * Add -e option: execute an application and detach it from terminal 16 | * Print a list of applications from cache (-P param) 17 | * Include recently open apps in the printed list 18 | * Fix bug that breaks the application if it's built without compiler optimisation 19 | * Save last open app when open with -e option 20 | * Remove some compiler warnings 21 | 22 | 0.7.0 23 | 26/03/2018 24 | * Add ability to provide arguments to applications 25 | 26 | 0.6.0 27 | 14/01/2018 28 | * Add ability to open an application in terminal 29 | * When calling chdir, change to user's home directory 30 | * Remove compiler warnings 31 | * Update deb package 32 | * Add rpm package 33 | 34 | 0.5.2 35 | 27/05/2017 36 | * Change name of internal function which conflicted with the builtin function. 37 | Required to build xstarter on arch. 38 | 39 | 0.5.1 40 | 26/05/2017 41 | 42 | * Fix a bug that appeared on Arch that caused problems with "open_itself" function. 43 | * When attempting to find a path to the xstarter, try to find it in $PATH which 44 | should work as long as xstarter is installed. 45 | * Add missing -r option to the help screen and readme file. 46 | * Add man page: man xstarter 47 | -------------------------------------------------------------------------------- /docs/version-0-8-1-released.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 13 | 14 | 15 | 16 | 17 | 18 | Version 0.8.1 released 19 | 20 | 21 | 22 | 23 | 24 |
25 |

Version 0.8.1 released

26 | 2020-05-25 27 |

New version of xstarter (v0.8.1) was released today.

28 | 29 |

It’s a tiny release but it contains necessary fixes for xstarter to compile with gcc 10.

30 | 31 |

How to get it?

32 | 33 | 38 | 39 |
40 | 41 | 42 | -------------------------------------------------------------------------------- /docs/emacs-interface.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 13 | 14 | 15 | 16 | 17 | 18 | Emacs interface 19 | 20 | 21 | 22 | 23 | 24 |
25 |

Emacs interface

26 |

Emacs package helm-xstarter offers an intuitive interface to launch applications via Emacs.

27 | 28 |

It loads a list of installed applications and lets a user select one to launch.

29 | 30 |

It also records recently open programs and shows them on top.

31 | 32 |

`helm-xstarter` session

33 | 34 |

See github page for installation instructions!

35 | 36 |
37 | 38 | 39 | -------------------------------------------------------------------------------- /docs/emacs-interface-available.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 13 | 14 | 15 | 16 | 17 | 18 | Emacs interface available 19 | 20 | 21 | 22 | 23 | 24 |
25 |

Emacs interface available

26 | 2018-08-28 27 |

There’s Emacs interface available for xstarter!

28 | 29 |

`helm-xstarter` session

30 | 31 |

It uses Helm interface that many Emacs users are familiar with.

32 | 33 |

It loads a list of installed applications and lets a user select one to launch. It also records recently open programs and shows them on top.

34 | 35 |

See github page for installation instructions!

36 | 37 |
38 | 39 | 40 | -------------------------------------------------------------------------------- /tests/test_expand_tilde.h: -------------------------------------------------------------------------------- 1 | #include "../src/utils_string.h" 2 | #include "../src/utils.h" 3 | 4 | static const char *mock_home = "/xstarter"; 5 | 6 | mu_test(tilde_expansion_empty) 7 | { 8 | char *result = expand_tilde("", NULL); 9 | 10 | mu_assert("not equal tilde_expansion_empty", strcmp(result, "") == 0); 11 | 12 | return 0; 13 | } 14 | 15 | mu_test(tilde_expansion_in_the_middle) 16 | { 17 | char *result = expand_tilde( 18 | "xstarter, ~/xstarter, xstarter", 19 | mock_home 20 | ); 21 | 22 | mu_assert("not equal tilde_expansion_in_the_middle", strcmp(result, "xstarter, /xstarter/xstarter, xstarter") == 0); 23 | 24 | return 0; 25 | } 26 | 27 | mu_test(tilde_expansion_nothing_to_expand) 28 | { 29 | char *result = expand_tilde("xstarter", mock_home); 30 | 31 | mu_assert("tilde_expansion_nothing_to_expand", strcmp(result, "xstarter") == 0); 32 | 33 | return 0; 34 | } 35 | 36 | mu_test(tilde_expansion_single_expansion) 37 | { 38 | char *result = expand_tilde("~/xstarter", mock_home); 39 | 40 | mu_assert("tilde_expansion_single_expansion", strcmp(result, "/xstarter/xstarter") == 0); 41 | 42 | return 0; 43 | } 44 | 45 | mu_test(tilde_expansion_two_expansions) 46 | { 47 | char *result = expand_tilde( 48 | "~/xstarter, $PATH, ~/xstarter", 49 | mock_home 50 | ); 51 | 52 | mu_assert("tilde_expansion_single_expansion", strcmp(result, "/xstarter/xstarter, $PATH, /xstarter/xstarter") == 0); 53 | 54 | return 0; 55 | } 56 | 57 | mu_test(tilde_expansion_multiple_expansions) 58 | { 59 | char *result = expand_tilde( 60 | "~/xs1, $PATH, ~/xs2, ~/xs3, xs", 61 | mock_home 62 | ); 63 | 64 | mu_assert("tilde_expansion_single_expansion", strcmp(result, "/xstarter/xs1, $PATH, /xstarter/xs2, /xstarter/xs3, xs") == 0); 65 | 66 | return 0; 67 | } 68 | -------------------------------------------------------------------------------- /tests/test.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "test.h" 4 | 5 | #include "test_settings.h" 6 | #include "test_strings.h" 7 | #include "test_expand_tilde.h" 8 | #include "test_str_array.h" 9 | #include "test_xs_dirname.h" 10 | 11 | int tests_run; 12 | 13 | static char* all_tests() { 14 | // Settings 15 | mu_run_test(test_settings_default_file); 16 | mu_run_test(test_settings_no_file); 17 | 18 | // Strings 19 | mu_run_test(test_str_copy_smaller_than_max_str_length); 20 | mu_run_test(test_str_copy_equal_to_max); 21 | 22 | // Tilde 23 | mu_run_test(tilde_expansion_empty); 24 | mu_run_test(tilde_expansion_in_the_middle); 25 | mu_run_test(tilde_expansion_nothing_to_expand); 26 | mu_run_test(tilde_expansion_single_expansion); 27 | mu_run_test(tilde_expansion_two_expansions); 28 | mu_run_test(tilde_expansion_multiple_expansions); 29 | 30 | // StrArray 31 | mu_run_test(str_array_empty); 32 | mu_run_test(str_array_no_delimiter); 33 | mu_run_test(str_array_simple); 34 | mu_run_test(str_array_whitespace); 35 | mu_run_test(str_array_newline); 36 | mu_run_test(str_array_different_delimiters); 37 | mu_run_test(str_array_several); 38 | mu_run_test(str_array_strip_semicolons); 39 | 40 | // XS dirname 41 | mu_run_test(xs_dirname_null); 42 | mu_run_test(xs_dirname_full_path); 43 | mu_run_test(xs_dirname_slash_not_found); 44 | mu_run_test(xs_dirname_trailing_slash); 45 | mu_run_test(xs_dirname_slash_only); 46 | mu_run_test(xs_dirname_double_slash); 47 | mu_run_test(xs_dirname_empty); 48 | 49 | return 0; 50 | } 51 | 52 | int main() { 53 | char *result = all_tests(); 54 | if (result != 0) { 55 | printf("%s\n", result); 56 | } 57 | else { 58 | printf("ALL TESTS PASSED\n"); 59 | } 60 | printf("Tests run: %d\n", tests_run); 61 | 62 | return result != 0; 63 | } 64 | -------------------------------------------------------------------------------- /src/utils.h: -------------------------------------------------------------------------------- 1 | #ifndef XSTARTER_UTILS_H 2 | #define XSTARTER_UTILS_H 3 | 4 | #include 5 | 6 | #define PRINTS(x) \ 7 | { \ 8 | printf("%s\n", x); \ 9 | } 10 | 11 | #define RECENT_APPS_REMEMBERED (100) 12 | 13 | #define ASCII_0 (48) 14 | #define ASCII_1 (49) 15 | #define ASCII_9 (57) 16 | 17 | /* Errors */ 18 | 19 | typedef enum { 20 | NO_ERR, 21 | ERR_NO_XSTARTER_PATH, 22 | ERR_NO_XSTARTER_DIR, 23 | ERR_DIRS_TOO_LONG, 24 | ERR_XSTARTER_MKDIR_FAILED, 25 | ERR_FORK_FAILED, 26 | ERR_SETSID_FAILED, 27 | ERR_CHDIR_FAILED, 28 | ERR_DUMP_DEBUG_FAILED, 29 | ERR_REDIRECTING_TO_DEV_NULL_FAILED, 30 | } error_code_t; 31 | 32 | typedef enum { APP_LAUNCH_MODE_GUI, APP_LAUNCH_MODE_TERM } app_launch_mode_t; 33 | 34 | #define MAX_LEN (2048) 35 | 36 | void open_app(const char *path, const char *query, app_launch_mode_t mode, 37 | bool save_open_file); 38 | 39 | /* Error code */ 40 | extern int err; 41 | 42 | extern char xstarter_dir[1024]; 43 | extern int xstarter_dir_avail; 44 | 45 | extern char recent_apps[100][1024]; 46 | extern int recent_apps_cnt; 47 | 48 | extern char exec_term[32]; 49 | 50 | typedef struct { 51 | double r, g, b; 52 | } colour_t; 53 | 54 | void get_rgb(colour_t *dest, char *src); 55 | 56 | void app_to_open(char *path); 57 | 58 | void dump_debug(const char *str); 59 | void dump_debug_ptr(const char *str); 60 | void dump_debug_int(int d); 61 | void dump_debug_char(const char); 62 | 63 | void xstarter_directory(); 64 | void read_recently_open_list(); 65 | 66 | bool in_terminal(); 67 | void open_itself(int argc, char **argv); 68 | 69 | void set_err(int err_code); 70 | int get_err(); 71 | void print_err(); 72 | 73 | void *safe_malloc(size_t n, unsigned long line); 74 | #define smalloc(n) safe_malloc(n, __LINE__); 75 | 76 | #endif 77 | -------------------------------------------------------------------------------- /docs/posts.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | xstarter - GNU/Linux terminal application launcher 4 | https://lchsk.com/xstarter 5 | xstarter - terminal application launcher for GNU/Linux 6 | (Maciej Lechowski) 7 | Mon, 25 May 2020 13:53:42 +0100 8 | 9 | Version 0.8.1 released 10 | https://lchsk.com/xstarter/version-0-8-1-released.html 11 | It's a tiny release but it contains necessary fixes for xstarter to compile with gcc 10. 12 | Mon, 25 May 2020 00:00:00 +0000 13 | 14 | 15 | Emacs interface available 16 | https://lchsk.com/xstarter/emacs-interface-available.html 17 | New Emacs package allows to launch application with xstarter directly from Emacs! 18 | Tue, 28 Aug 2018 00:00:00 +0000 19 | 20 | 21 | Version 0.8.0 released 22 | https://lchsk.com/xstarter/version-0-8-0-released.html 23 | New version of xstarter is available (v0.8.0). It adds one useful feature: you can now provide arguments to the application. It works for GUI and terminal programs alike. 24 | Mon, 27 Aug 2018 00:00:00 +0000 25 | 26 | 27 | Version 0.7.0 released 28 | https://lchsk.com/xstarter/version-0-7-0-released.html 29 | New version of xstarter is available (v0.7.0). It adds one useful feature: you can now provide arguments to the application. It works for GUI and terminal programs alike. 30 | Mon, 26 Mar 2018 00:00:00 +0000 31 | 32 | 33 | -------------------------------------------------------------------------------- /tests/test_settings.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "../src/settings.h" 4 | 5 | mu_test(test_settings_default_file) { 6 | config_free(config_get()); 7 | 8 | char* path = "../xstarter.conf"; 9 | CmdLine cmdline = (CmdLine) { 10 | .config_path = path, 11 | }; 12 | 13 | Config* conf = config_load(&cmdline); 14 | 15 | mu_assert("terminal", strcmp(conf->section_main->terminal, "xterm") == 0); 16 | mu_assert("dirs", strcmp(conf->section_main->dirs->base_str, "$PATH") == 0); 17 | mu_assert("emacs_bindings", conf->section_main->emacs_bindings == true); 18 | mu_assert("recent_apps_first", conf->section_main->recent_apps_first == true); 19 | mu_assert("numeric_shortcuts", conf->section_main->numeric_shortcuts == true); 20 | mu_assert("use_cache", conf->section_main->use_cache == true); 21 | mu_assert("auto_cache_refresh", conf->section_main->auto_cache_refresh == true); 22 | mu_assert("allow_spaces", conf->section_main->allow_spaces == true); 23 | mu_assert("min_query_len", conf->section_main->min_query_len == 1); 24 | 25 | mu_assert("selected color", strcmp(conf->section_colors->selected, "f44336") == 0); 26 | 27 | return 0; 28 | } 29 | 30 | mu_test(test_settings_no_file) { 31 | config_free(config_get()); 32 | 33 | char* path = "../doesnt_exist"; 34 | CmdLine cmdline = (CmdLine) { 35 | .config_path = path, 36 | }; 37 | 38 | Config* conf = config_load(&cmdline); 39 | 40 | mu_assert("terminal", strcmp(conf->section_main->terminal, "xterm") == 0); 41 | mu_assert("dirs", strcmp(conf->section_main->dirs->base_str, "$PATH") == 0); 42 | mu_assert("emacs_bindings", conf->section_main->emacs_bindings == true); 43 | mu_assert("recent_apps_first", conf->section_main->recent_apps_first == true); 44 | mu_assert("numeric_shortcuts", conf->section_main->numeric_shortcuts == true); 45 | mu_assert("use_cache", conf->section_main->use_cache == true); 46 | mu_assert("auto_cache_refresh", conf->section_main->auto_cache_refresh == true); 47 | mu_assert("allow_spaces", conf->section_main->allow_spaces == true); 48 | mu_assert("min_query_len", conf->section_main->min_query_len == 1); 49 | 50 | mu_assert("selected color", strcmp(conf->section_colors->selected, "f44336") == 0); 51 | 52 | return 0; 53 | } 54 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | CMAKE_MINIMUM_REQUIRED(VERSION 3.0) 2 | 3 | project(xstarter) 4 | 5 | if (NOT CMAKE_BUILD_TYPE) 6 | set(CMAKE_BUILD_TYPE Debug CACHE STRING "Choose the type of build (Debug or Release)" FORCE) 7 | endif() 8 | 9 | set (CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/../cmake") 10 | 11 | set(PROJECT_VERSION "0.8.2") 12 | if (CMAKE_BUILD_TYPE STREQUAL Debug) 13 | set(CMAKE_C_FLAGS "-g -Wall -pedantic") 14 | else() 15 | set(CMAKE_C_FLAGS "-Wall -pedantic -O3") 16 | endif() 17 | 18 | # cpack 19 | set(CPACK_PACKAGE_CONTACT "Maciej Lechowski") 20 | set(CPACK_GENERATOR "DEB;RPM;ZIP;TGZ") 21 | set(CPACK_PACKAGE_DESCRIPTION, "Application launcher for Linux") 22 | set(CPACK_PACKAGE_VERSION ${PROJECT_VERSION}) 23 | 24 | # deb stuff 25 | set(CPACK_DEBIAN_PACKAGE_HOMEPAGE "https://lchsk.com/xstarter.html") 26 | set(CPACK_DEBIAN_PACKAGE_DEPENDS "libncurses5 (>= 5.0)") 27 | 28 | # rpm stuff 29 | set(CPACK_RPM_PACKAGE_LICENSE "GPL") 30 | set(CPACK_RPM_PACKAGE_URL "https://lchsk.com/xstarter.html") 31 | set(CPACK_RPM_PACKAGE_DESCRIPTION "Application launcher for Linux") 32 | set(CPACK_RPM_PACKAGE_REQUIRES "ncurses >= 5.0") 33 | 34 | include(CPack) 35 | 36 | # end cpack 37 | 38 | add_definitions(-std=c99) 39 | 40 | find_package(PkgConfig REQUIRED) 41 | 42 | message(STATUS "Cmake build type: " ${CMAKE_BUILD_TYPE}) 43 | message(STATUS "Curses include directory: " ${CURSES_INCLUDE_DIR}) 44 | 45 | pkg_check_modules(CURSES REQUIRED ncurses) 46 | 47 | add_library(lib-inih STATIC 48 | external/inih/ini.c 49 | external/inih/ini.h 50 | ) 51 | set_target_properties(lib-inih PROPERTIES LINKER_LANGUAGE C) 52 | 53 | include_directories( 54 | ${CURSES_INCLUDE_DIRS} 55 | external/ 56 | ) 57 | 58 | add_executable(xstarter 59 | src/main.c 60 | src/scan.c 61 | src/settings.c 62 | src/term.c 63 | src/utils.c 64 | src/utils_string.c 65 | src/list.c 66 | xstarter.1 67 | ) 68 | 69 | target_link_libraries(xstarter 70 | ${CURSES_LIBRARIES} 71 | -pthread 72 | -linih 73 | ) 74 | 75 | install(TARGETS xstarter DESTINATION bin) 76 | install(FILES xstarter.1 DESTINATION share/man/man1) 77 | 78 | add_executable(xstarter_tests 79 | src/utils.c 80 | src/utils_string.c 81 | src/settings.c 82 | 83 | tests/test.c 84 | ) 85 | 86 | target_link_libraries(xstarter_tests 87 | -linih 88 | ) 89 | -------------------------------------------------------------------------------- /src/list.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "list.h" 5 | 6 | static void resize(List *list); 7 | 8 | // How full the map must be in order to trigger resize 9 | static const float LIST_RESIZE_TRIGGER = 0.6; 10 | 11 | // By what factor we're enlarging the list 12 | static const size_t LIST_RESIZE_FACTOR = 2; 13 | 14 | size_t list_in(List *list, void *value) 15 | { 16 | assert(list != NULL); 17 | 18 | for (int i = 0; i < list->size; i++) { 19 | if (list->data[i] == value) { 20 | return 1; 21 | } 22 | } 23 | 24 | return 0; 25 | } 26 | 27 | List *list_new(size_t initial_size) 28 | { 29 | List *list = calloc(1, sizeof(List)); 30 | 31 | list->data = calloc(initial_size, sizeof(void *)); 32 | list->cap = initial_size; 33 | list->size = 0; 34 | 35 | return list; 36 | } 37 | 38 | void list_free(List *list) 39 | { 40 | if (!list) { 41 | return; 42 | } 43 | 44 | if (list->data) { 45 | free(list->data); 46 | } 47 | 48 | free(list); 49 | } 50 | 51 | void list_append(List *list, void *value) 52 | { 53 | assert(list != NULL); 54 | 55 | resize(list); 56 | 57 | list->data[list->size] = value; 58 | list->size++; 59 | } 60 | 61 | void *list_get(List *list, size_t index) 62 | { 63 | if (index >= list->size) { 64 | return NULL; 65 | } 66 | 67 | return list->data[index]; 68 | } 69 | 70 | size_t list_size(List *list) 71 | { 72 | assert(list != NULL); 73 | 74 | return list->size; 75 | } 76 | 77 | void list_del(List *list, size_t index) 78 | { 79 | assert(list != NULL); 80 | 81 | list->data[index] = NULL; 82 | 83 | for (int i = index; i < list->size - 1; i++) { 84 | list->data[i] = list->data[i + 1]; 85 | } 86 | 87 | list->size--; 88 | } 89 | 90 | static void resize(List *list) 91 | { 92 | assert(list != NULL); 93 | 94 | if (list->size < list->cap * LIST_RESIZE_TRIGGER) { 95 | return; 96 | } 97 | 98 | list->cap = list->cap * LIST_RESIZE_FACTOR; 99 | 100 | void **data = calloc(list->cap, sizeof(void *)); 101 | 102 | for (int i = 0; i < list->cap / LIST_RESIZE_FACTOR; i++) { 103 | void *value = list->data[i]; 104 | 105 | if (value) { 106 | data[i] = value; 107 | } 108 | } 109 | 110 | free(list->data); 111 | 112 | list->data = data; 113 | } 114 | -------------------------------------------------------------------------------- /xstarter.conf: -------------------------------------------------------------------------------- 1 | ############################################################ 2 | # # 3 | # Configuration file for xstarter # 4 | # # 5 | ############################################################ 6 | 7 | [Main] 8 | 9 | # List of paths that should be visited by xstarter when 10 | # searching for executables. 11 | # Use , (comma) to separate items. 12 | # You can use environment variables, e.g. $PATH 13 | # ~ (tilde) can be used as a shortcut for the user's home directory. 14 | # Default value: $PATH 15 | dirs = $PATH 16 | 17 | # Name of the terminal emulator used by xstarter when not run 18 | # from the terminal. 19 | # Default value: xterm 20 | terminal = xterm 21 | 22 | # Use Emacs-like bindings to control xstarter 23 | # C-n Move down the list 24 | # C-p Move up the list 25 | # C-g Quit 26 | # C-d Delete entered character 27 | # C-w Delete entire query 28 | # C-o Open selected application in terminal (defined by "terminal" variable above) 29 | # Default value: true 30 | emacs_bindings = true 31 | 32 | # If set to true, applications that were recently 33 | # opened, will be favoured and may appear at 34 | # the top of the results. 35 | # Default value: true 36 | recent_apps_first = true 37 | 38 | # Number of characters that need to be entered 39 | # in order to trigger search. 40 | # Default value: 1 41 | min_query_len = 1 42 | 43 | # If set to true, keys 1-9 can be used to run 44 | # an application from the list. 45 | # Default value: true 46 | numeric_shortcuts = true 47 | 48 | # If true, xstarter will cache application paths to a file. 49 | # The cache file will speed up the startup of xstarter. 50 | # Default value: true 51 | use_cache = true 52 | 53 | # If "use_cache" variable is set to true, a cache file is used. 54 | # "auto_cache_refresh" set to true forces cache to be automatically 55 | # refreshed when it becomes stale (i.e. when any of the directories 56 | # specified in the "dirs" variable is newer than the cache). 57 | # Default value: true 58 | auto_cache_refresh = true 59 | 60 | # Allow splitting search query into multiple chunks separated by spaces. 61 | # Default value: true 62 | allow_spaces = true 63 | 64 | [Colors] 65 | # All colors should be provided in hex format. Whether those colors work 66 | # might depend on system settings and will only work on some terminals 67 | # (e.g. urxvt). 68 | 69 | # Background color of the selected item. 70 | # Default value: f44336 71 | selected = f44336 72 | -------------------------------------------------------------------------------- /docs/version-0-7-0-released.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 13 | 14 | 15 | 16 | 17 | 18 | Version 0.7.0 released 19 | 20 | 21 | 22 | 23 | 24 |
25 |

Version 0.7.0 released

26 | 2018-03-26 27 |

New version of xstarter is available (v0.7.0). It adds one useful feature: you can now provide arguments to the application. It works for GUI and terminal programs alike. This allows to start a program like this: surf gnu.org (GUI) or e.g. emacs -nw -Q.

28 | 29 |

How to use it?

30 | 31 |

If the number of search results is equal to 1, you can provide arguments the selected application should be started with, e.g. surf gnu.org. You can provide multiple arguments, e.g. emacs -nw -Q. You can select the application you want to provide arguments for by pressing Tab key 32 | This feature works both with GUI (press Enter to start) and terminal applications (press C-o to start)

33 | 34 |

How to get it?

35 | 36 | 43 | 44 |
45 | 46 | 47 | -------------------------------------------------------------------------------- /docs/version-0-8-0-released.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 13 | 14 | 15 | 16 | 17 | 18 | Version 0.8.0 released 19 | 20 | 21 | 22 | 23 | 24 |
25 |

Version 0.8.0 released

26 | 2018-08-27 27 |

New version of xstarter (v0.8.0) was released today.

28 | 29 |

Main intention of this release was to enable xstarter to work with external programs. I want to be able to use xstarter via Emacs and I’m working on a small package that will handle that. With this release xstarter is able to print a list of programs that it stored in cache (it can be tested by running xstarter -P). External applications can use it load the list of available programs and show it to users. In order to start a program, e.g. Firefox, use command xstarter -e firefox. It can be used on its own to start and detach applications from terminal as well by other software.

30 | 31 |

In this release I’ve also fixed an interesting bug that broke xstarter if it was built without compiler optimisation. I wrote about that bug on my blog.

32 | 33 |

How to get it?

34 | 35 | 40 | 41 |
42 | 43 | 44 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: c 2 | sudo: true 3 | 4 | before_install: 5 | - sudo apt-get install valgrind cppcheck 6 | - git clone https://github.com/Snaipe/Criterion.git 7 | - cd Criterion && git checkout master && mkdir build && cd build 8 | - CC=gcc cmake .. 9 | - CC=gcc cmake --build . 10 | - sudo make install 11 | - cd ../../ 12 | 13 | matrix: 14 | include: 15 | - os: linux 16 | addons: 17 | apt: 18 | sources: 19 | - ubuntu-toolchain-r-test 20 | packages: 21 | - gcc-4.9 22 | env: 23 | - COMPILER=gcc-4.9 24 | 25 | - os: linux 26 | addons: 27 | apt: 28 | sources: 29 | - ubuntu-toolchain-r-test 30 | packages: 31 | - gcc-5 32 | env: 33 | - COMPILER=gcc-5 34 | 35 | - os: linux 36 | addons: 37 | apt: 38 | sources: 39 | - ubuntu-toolchain-r-test 40 | packages: 41 | - gcc-6 42 | env: 43 | - COMPILER=gcc-6 44 | 45 | - os: linux 46 | addons: 47 | apt: 48 | sources: 49 | - ubuntu-toolchain-r-test 50 | packages: 51 | - gcc-7 52 | env: 53 | - COMPILER=gcc-7 54 | 55 | - os: linux 56 | addons: 57 | apt: 58 | sources: 59 | - ubuntu-toolchain-r-test 60 | - llvm-toolchain-precise-3.6 61 | packages: 62 | - clang-3.6 63 | env: 64 | - COMPILER=clang-3.6 65 | 66 | - os: linux 67 | addons: 68 | apt: 69 | sources: 70 | - ubuntu-toolchain-r-test 71 | - llvm-toolchain-precise-3.7 72 | packages: 73 | - clang-3.7 74 | env: 75 | - COMPILER=clang-3.7 76 | 77 | - os: linux 78 | addons: 79 | apt: 80 | sources: 81 | - llvm-toolchain-trusty-3.9 82 | packages: 83 | - clang-3.9 84 | env: 85 | - COMPILER=clang-3.9 86 | 87 | - os: linux 88 | addons: 89 | apt: 90 | sources: 91 | - llvm-toolchain-trusty-4.0 92 | packages: 93 | - clang-4.0 94 | env: 95 | - COMPILER=clang-4.0 96 | 97 | # - os: linux 98 | # addons: 99 | # apt: 100 | # sources: 101 | # - llvm-toolchain-trusty-5.0 102 | # packages: 103 | # - clang-5.0 104 | # env: 105 | # - COMPILER=clang-5.0 106 | 107 | script: 108 | - uname -a 109 | - $COMPILER --version 110 | - CC=$COMPILER cmake . && make 111 | - cppcheck --verbose ./src 112 | - cd tests 113 | - cmake . && make 114 | - ./xstarter_tests --verbose=1 115 | - valgrind --leak-check=full ./xstarter_tests --no-early-exit --verbose=1 116 | -------------------------------------------------------------------------------- /docs_source/xstarter/source/index.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: xstarter - GNU/Linux terminal application launcher 3 | description: xstarter - terminal application launcher for GNU/Linux 4 | keywords: xstarter, c, gnu gpl, linux, gnu, terminal, urxvt, gnome, xterm, konsole, emacs, vim 5 | --- 6 | 7 | xstarter is an application launcher for Linux 8 | 9 | It lives in terminal and works well with tiling window managers (e.g. xmonad, i3 etc). 10 | 11 | ![xstarter screenshot](./data/xstarter_1.png) 12 | 13 | ## Features 14 | - a clean, simple interface that works on various terminals 15 | 16 | - able to search for applications using environment variables (e.g. $PATH) and user-provided list of directories 17 | 18 | - can be configured to launch via a key-binding 19 | 20 | - can optionally open an application in terminal (see key shortcuts) 21 | 22 | - allows to provide arguments to applications (see key shortcuts) 23 | 24 | - remembers previously launched applications allowing to find them more quickly 25 | 26 | - allows fuzzy search (parts of the query can be separated with a space) 27 | 28 | - applications can be launched with 1, 2, ..., 0 keys, depending on their position in the search results 29 | 30 | - fast, uses cache by default 31 | 32 | - easy to configure via a single text file 33 | 34 | ## Running xstarter 35 | xstarter needs to be launched from a terminal (`$ xstarter`). It is useful to run it using a key binding, preferably by binding your preferred key to a command starting xstarter from a terminal of your choice, e.g. xterm -e xstarter. Alternatively, you can simply bind it to xstarter in which case xstarter will open itself in a terminal. 36 | 37 | You can also create an alias in your shell (e.g. bash, zsh): `alias xs=xstarter`. 38 | 39 | It should run on any modern terminal. It is tested on: `xterm, rxvt, gnome-terminal, xfce4-terminal, konsole`. In case of any problems please report it. 40 | 41 | ## Configuration 42 | Configuration file is available and includes comments that explain configuration variables. It is located in the `~/.xstarter.d/` directory. 43 | 44 | ## Providing arguments to applications 45 | You can provide arguments to applications you wish to open. 46 | 47 | If the number of search results is equal to 1, you can provide arguments the selected application should be started with, e.g. `surf gnu.org` 48 | 49 | You can provide multiple arguments, e.g. `emacs -nw -Q` 50 | 51 | You can select the application you want to provide arguments for by pressing Tab key 52 | 53 | This feature works both with GUI (press Enter to start) and terminal applications (press C-o to start) 54 | 55 | 56 | ## Key shortcuts 57 | 58 | Use numbers 1..9 and 0 to open an application from the list. 59 | 60 | By default, the following shortcuts are available: 61 | 62 | - Return (enter) Open selected application 63 | 64 | - C-o Open selected application in terminal (defined by "terminal" variable in the config file, xterm by default) 65 | 66 | - C-n Move down the list 67 | 68 | - C-p Move up the list 69 | 70 | - C-g Quit 71 | 72 | - C-d Delete entered character 73 | 74 | - C-w Delete entire query 75 | 76 | - Tab Auto-complete using current selection; allow to provide arguments 77 | 78 | [source code](https://github.com/lchsk/xstarter) 79 | 80 | See also: [personal website](https://lchsk.com) | [twitter](https://twitter.com/lchsk) | [postgres linux desktop client](https://lchsk.com/sanchosql) 81 | -------------------------------------------------------------------------------- /xstarter.1: -------------------------------------------------------------------------------- 1 | .\" Manpage for xstarter. 2 | .TH xstarter 1 "13 Sep 2022" "0.8.2" "xstarter man page" 3 | .SH NAME 4 | xstarter \- application launcher 5 | .SH SYNOPSIS 6 | xstarter 7 | .SH DESCRIPTION 8 | .LP 9 | xstarter is a free (GPL) ncurses-based terminal launcher for Linux 10 | 11 | .SH FEATURES 12 | .TP 13 | * a clean, simple interface that works on various terminals 14 | .TP 15 | * able to search for applications using environment variables (e.g. `$PATH`) and user-provided list of directories 16 | .TP 17 | * can be configured to launch via a key-binding 18 | .TP 19 | * can optionally open an application in terminal (see key shortcuts) 20 | .TP 21 | * allows to provide arguments to applications (see key shortcuts) 22 | .TP 23 | * remembers previously launched applications allowing to find them more quickly 24 | .TP 25 | * allows fuzzy search (parts of the query can be separated with a space) 26 | .TP 27 | * applications can be launched with 1, 2, ..., 0 keys, depending on their position in the search results 28 | .TP 29 | * fast, uses cache by default 30 | .TP 31 | * easy to configure via a single text file 32 | .TP 33 | * is able to run an application and detach it from terminal (e.g. xstarter -e firefox) 34 | .TP 35 | * can provide contents of the cache to outside programs (xstarter -P) 36 | 37 | .SH USAGE 38 | .TP 39 | xstarter needs to be launched from a terminal. It is useful to run it using a key binding, preferably by binding your preferred key to a command starting xstarter from a terminal of your choice, e.g. xterm -e xstarter. Alternatively, you can simply bind it to xstarter in which case xstarter will open itself in a terminal. 40 | 41 | .TP 42 | You can also create an alias in your shell (e.g. bash, zsh): alias xs=xstarter. 43 | 44 | .TP 45 | It should run on any modern terminal. It is tested on: xterm, rxvt, gnome-terminal, xfce4-terminal, konsole. In case of any problems please report it: (https://github.com/lchsk/xstarter/issues/new). 46 | 47 | .SH CONFIGURATION 48 | Configuration file "xstarter.conf" is available in the main repository and includes comments that explain configuration variables. By default, it should be placed in the ~/.xstarter.d/ directory. 49 | 50 | .SH KEY SHORTCUTS 51 | 52 | Use numbers 1..9 and 0 to open an application from the list. 53 | 54 | By default, the following shortcuts are available: 55 | 56 | .TP 57 | Return (enter) 58 | Open selected application 59 | .TP 60 | C-o 61 | Open selected application in terminal (defined by "terminal" variable in the config file, xterm by default) 62 | .TP 63 | C-n / Down 64 | Move down the list 65 | .TP 66 | C-p / Up 67 | Move up the list 68 | .TP 69 | C-g / Esc 70 | Quit 71 | .TP 72 | C-d / Backspace 73 | Delete entered character 74 | .TP 75 | C-w 76 | Delete entire query 77 | .TP 78 | Tab 79 | Auto-complete using current selection; allow to provide arguments 80 | 81 | .SH UPDATE 82 | See https://lchsk.com/xstarter.html or https://github.com/lchsk/xstarter to get the latest version. 83 | .SH OPTIONS 84 | .LP 85 | .TP 86 | \fB\-h\fR 87 | Show help screen 88 | .TP 89 | \fB\-v\fR 90 | Show xstarter version 91 | .TP 92 | \fB\-V\fR 93 | Be verbose 94 | .TP 95 | \fB\-r\fR 96 | Refresh cache 97 | .TP 98 | \fB\-c\fR 99 | Path to the configuration file 100 | .SH BUGS 101 | No known bugs. 102 | .SH AUTHOR 103 | Maciej Lechowski (https://github.com/lchsk https://lchsk.com) 104 | -------------------------------------------------------------------------------- /tests/test_str_array.h: -------------------------------------------------------------------------------- 1 | #include "../src/utils_string.h" 2 | #include "../src/utils.h" 3 | 4 | mu_test(str_array_empty) 5 | { 6 | char *test = xs_strdup(""); 7 | StrArray *result = str_array_new(test, ","); 8 | 9 | mu_assert("str_array_empty", result->length == 0); 10 | 11 | str_array_free(result); 12 | 13 | return 0; 14 | } 15 | 16 | mu_test(str_array_no_delimiter) 17 | { 18 | char *test = xs_strdup("abc def"); 19 | StrArray *result = str_array_new(test, ","); 20 | 21 | mu_assert("str_array_no_delimiter", result->length == 1); 22 | mu_assert("str_array_no_delimiter", strcmp(result->data[0], "abc def") == 0); 23 | 24 | str_array_free(result); 25 | 26 | return 0; 27 | } 28 | 29 | mu_test(str_array_simple) 30 | { 31 | char *test = xs_strdup("a,b"); 32 | StrArray *result = str_array_new(test, ","); 33 | 34 | mu_assert("str_array_simple", result->length == 2); 35 | mu_assert("str_array_simple", strcmp(result->data[0], "a") == 0); 36 | mu_assert("str_array_simple", strcmp(result->data[1], "b") == 0); 37 | 38 | str_array_free(result); 39 | 40 | return 0; 41 | } 42 | 43 | mu_test(str_array_whitespace) 44 | { 45 | char *test = xs_strdup("abc def"); 46 | StrArray *result = str_array_new(test, " "); 47 | 48 | mu_assert("", result->length == 2); 49 | mu_assert("", strcmp(result->data[0], "abc") == 0); 50 | mu_assert("", strcmp(result->data[1], "def") == 0); 51 | 52 | str_array_free(result); 53 | 54 | return 0; 55 | } 56 | 57 | mu_test(str_array_newline) 58 | { 59 | char *test = xs_strdup("abc\ndef"); 60 | StrArray *result = str_array_new(test, "\n"); 61 | 62 | mu_assert("", result->length == 2); 63 | mu_assert("", strcmp(result->data[0], "abc") == 0); 64 | mu_assert("", strcmp(result->data[1], "def") == 0); 65 | 66 | str_array_free(result); 67 | 68 | return 0; 69 | } 70 | 71 | mu_test(str_array_different_delimiters) 72 | { 73 | char *test = xs_strdup("a,b;c,d"); 74 | StrArray *result = str_array_new(test, ",;"); 75 | 76 | mu_assert("", result->length == 4); 77 | mu_assert("", strcmp(result->data[0], "a") == 0); 78 | mu_assert("", strcmp(result->data[1], "b") == 0); 79 | mu_assert("", strcmp(result->data[2], "c") == 0); 80 | mu_assert("", strcmp(result->data[3], "d") == 0); 81 | 82 | str_array_free(result); 83 | 84 | return 0; 85 | } 86 | 87 | mu_test(str_array_several) 88 | { 89 | char *test = xs_strdup("a;b;c;d;"); 90 | StrArray *result = str_array_new(test, ";"); 91 | 92 | mu_assert("", result->length == 4); 93 | mu_assert("", strcmp(result->data[0], "a") == 0); 94 | mu_assert("", strcmp(result->data[1], "b") == 0); 95 | mu_assert("", strcmp(result->data[2], "c") == 0); 96 | mu_assert("", strcmp(result->data[3], "d") == 0); 97 | 98 | str_array_free(result); 99 | 100 | return 0; 101 | } 102 | 103 | mu_test(str_array_strip_semicolons) 104 | { 105 | char *test = xs_strdup("a: b: c: "); 106 | StrArray *result = str_array_new(test, ":"); 107 | 108 | str_array_strip(result); 109 | 110 | mu_assert("", result->length == 4); 111 | mu_assert("", strcmp(result->data[0], "a") == 0); 112 | mu_assert("", strcmp(result->data[1], "b") == 0); 113 | mu_assert("", strcmp(result->data[2], "c") == 0); 114 | mu_assert("", strcmp(result->data[3], "") == 0); 115 | 116 | str_array_free(result); 117 | 118 | return 0; 119 | } 120 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # xstarter 2 | 3 | **xstarter is an application launcher for Linux** 4 | 5 | It lives in terminal and works well with tiling window managers (e.g. xmonad, i3 etc). 6 | 7 | Current version: 0.8.2 8 | 9 | | Branch | Build | 10 | | --- | --- | 11 | |`master`|[![Build Status](https://travis-ci.org/lchsk/xstarter.svg?branch=master)](https://travis-ci.org/lchsk/xstarter)| 12 | |`dev`|[![Build Status](https://travis-ci.org/lchsk/xstarter.svg?branch=dev)](https://travis-ci.org/lchsk/xstarter)| 13 | 14 | **Check out [Emacs interface](https://github.com/lchsk/helm-xstarter) for xstarter** 15 | 16 | ![xstarter screenshot](./docs_source/xstarter/source/data/xstarter_2.png "xstarter application launcher") 17 | 18 | ## Installation 19 | 20 | See [installation guide](INSTALL.md) 21 | 22 | ## Features 23 | 24 | * a clean, simple interface that works on various terminals 25 | * able to search for applications using environment variables (e.g. `$PATH`) and user-provided list of directories 26 | * can be configured to launch via a key-binding 27 | * can optionally open an application in terminal (see key shortcuts) 28 | * allows to provide arguments to applications (see key shortcuts) 29 | * remembers previously launched applications allowing to find them more quickly 30 | * allows fuzzy search (parts of the query can be separated with a space) 31 | * applications can be launched with 1, 2, ..., 0 keys, depending on their position in the search results 32 | * fast, uses cache by default 33 | * easy to configure via a single text file 34 | * is able to run an application and detach it from terminal (e.g. `xstarter -e firefox`) 35 | * can provide contents of the cache to outside programs (`xstarter -P`) 36 | 37 | ## Running xstarter 38 | 39 | **xstarter** needs to be launched from a terminal (`$ xstarter`). It is useful to run it using a key binding, preferably by binding your preferred key to a command starting **xstarter** from a terminal of your choice, e.g. `xterm -e xstarter`. Alternatively, you can simply bind it to `xstarter` in which case xstarter will open itself in a terminal. 40 | 41 | You can also create an alias in your shell (e.g. bash, zsh): `alias xs=xstarter`. 42 | 43 | It should run on any modern terminal. It is tested on: `xterm`, `rxvt`, `gnome-terminal`, `xfce4-terminal`, `konsole`. In case of any problems please [report it](https://github.com/lchsk/xstarter/issues/new). 44 | 45 | ## Configuration 46 | 47 | [Configuration file](./xstarter.conf) is available and includes comments that explain configuration variables. It is located in the `~/.xstarter.d/` directory. 48 | 49 | ## Providing arguments to applications 50 | 51 | You can provide arguments to applications you wish to open. 52 | 53 | * If the number of search results is equal to 1, you can provide arguments the selected application should be started with, e.g. `surf gnu.org` 54 | * You can provide multiple arguments, e.g. `emacs -nw -Q` 55 | * You can select the application you want to provide arguments for by pressing Tab key 56 | * This feature works both with GUI (press Enter to start) and terminal applications (press C-o to start) 57 | 58 | ## Key shortcuts 59 | 60 | Use numbers 1..9 and 0 to open an application from the list. 61 | 62 | By default, the following shortcuts are available: 63 | 64 | | Shortcut | Action | 65 | | --- | --- | 66 | |Return (enter)|Open selected application| 67 | |C-o|Open selected application in terminal (defined by "terminal" variable in the config file, xterm by default)| 68 | |C-n|Move down the list| 69 | |C-p|Move up the list| 70 | |C-g|Quit| 71 | |C-d|Delete entered character| 72 | |C-w|Delete entire query| 73 | |Tab|Auto-complete using current selection; allow to provide arguments| 74 | 75 | 76 | ## License 77 | 78 | GPL 79 | -------------------------------------------------------------------------------- /cmake/LibFindMacros.cmake: -------------------------------------------------------------------------------- 1 | # Works the same as find_package, but forwards the "REQUIRED" and "QUIET" arguments 2 | # used for the current package. For this to work, the first parameter must be the 3 | # prefix of the current package, then the prefix of the new package etc, which are 4 | # passed to find_package. 5 | macro (libfind_package PREFIX) 6 | set (LIBFIND_PACKAGE_ARGS ${ARGN}) 7 | if (${PREFIX}_FIND_QUIETLY) 8 | set (LIBFIND_PACKAGE_ARGS ${LIBFIND_PACKAGE_ARGS} QUIET) 9 | endif (${PREFIX}_FIND_QUIETLY) 10 | if (${PREFIX}_FIND_REQUIRED) 11 | set (LIBFIND_PACKAGE_ARGS ${LIBFIND_PACKAGE_ARGS} REQUIRED) 12 | endif (${PREFIX}_FIND_REQUIRED) 13 | find_package(${LIBFIND_PACKAGE_ARGS}) 14 | endmacro (libfind_package) 15 | 16 | # CMake developers made the UsePkgConfig system deprecated in the same release (2.6) 17 | # where they added pkg_check_modules. Consequently I need to support both in my scripts 18 | # to avoid those deprecated warnings. Here's a helper that does just that. 19 | # Works identically to pkg_check_modules, except that no checks are needed prior to use. 20 | macro (libfind_pkg_check_modules PREFIX PKGNAME) 21 | if (${CMAKE_MAJOR_VERSION} EQUAL 2 AND ${CMAKE_MINOR_VERSION} EQUAL 4) 22 | include(UsePkgConfig) 23 | pkgconfig(${PKGNAME} ${PREFIX}_INCLUDE_DIRS ${PREFIX}_LIBRARY_DIRS ${PREFIX}_LDFLAGS ${PREFIX}_CFLAGS) 24 | else (${CMAKE_MAJOR_VERSION} EQUAL 2 AND ${CMAKE_MINOR_VERSION} EQUAL 4) 25 | find_package(PkgConfig) 26 | if (PKG_CONFIG_FOUND) 27 | pkg_check_modules(${PREFIX} ${PKGNAME}) 28 | endif (PKG_CONFIG_FOUND) 29 | endif (${CMAKE_MAJOR_VERSION} EQUAL 2 AND ${CMAKE_MINOR_VERSION} EQUAL 4) 30 | endmacro (libfind_pkg_check_modules) 31 | 32 | # Do the final processing once the paths have been detected. 33 | # If include dirs are needed, ${PREFIX}_PROCESS_INCLUDES should be set to contain 34 | # all the variables, each of which contain one include directory. 35 | # Ditto for ${PREFIX}_PROCESS_LIBS and library files. 36 | # Will set ${PREFIX}_FOUND, ${PREFIX}_INCLUDE_DIRS and ${PREFIX}_LIBRARIES. 37 | # Also handles errors in case library detection was required, etc. 38 | macro (libfind_process PREFIX) 39 | # Skip processing if already processed during this run 40 | if (NOT ${PREFIX}_FOUND) 41 | # Start with the assumption that the library was found 42 | set (${PREFIX}_FOUND TRUE) 43 | 44 | # Process all includes and set _FOUND to false if any are missing 45 | foreach (i ${${PREFIX}_PROCESS_INCLUDES}) 46 | if (${i}) 47 | set (${PREFIX}_INCLUDE_DIRS ${${PREFIX}_INCLUDE_DIRS} ${${i}}) 48 | mark_as_advanced(${i}) 49 | else (${i}) 50 | set (${PREFIX}_FOUND FALSE) 51 | endif (${i}) 52 | endforeach (i) 53 | 54 | # Process all libraries and set _FOUND to false if any are missing 55 | foreach (i ${${PREFIX}_PROCESS_LIBS}) 56 | if (${i}) 57 | set (${PREFIX}_LIBRARIES ${${PREFIX}_LIBRARIES} ${${i}}) 58 | mark_as_advanced(${i}) 59 | else (${i}) 60 | set (${PREFIX}_FOUND FALSE) 61 | endif (${i}) 62 | endforeach (i) 63 | 64 | # Print message and/or exit on fatal error 65 | if (${PREFIX}_FOUND) 66 | if (NOT ${PREFIX}_FIND_QUIETLY) 67 | message (STATUS "Found ${PREFIX} ${${PREFIX}_VERSION}") 68 | endif (NOT ${PREFIX}_FIND_QUIETLY) 69 | else (${PREFIX}_FOUND) 70 | if (${PREFIX}_FIND_REQUIRED) 71 | foreach (i ${${PREFIX}_PROCESS_INCLUDES} ${${PREFIX}_PROCESS_LIBS}) 72 | message("${i}=${${i}}") 73 | endforeach (i) 74 | message (FATAL_ERROR "Required library ${PREFIX} NOT FOUND.\nInstall the library (dev version) and try again. If the library is already installed, use ccmake to set the missing variables manually.") 75 | endif (${PREFIX}_FIND_REQUIRED) 76 | endif (${PREFIX}_FOUND) 77 | endif (NOT ${PREFIX}_FOUND) 78 | endmacro (libfind_process) 79 | 80 | macro(libfind_library PREFIX basename) 81 | set(TMP "") 82 | if(MSVC80) 83 | set(TMP -vc80) 84 | endif(MSVC80) 85 | if(MSVC90) 86 | set(TMP -vc90) 87 | endif(MSVC90) 88 | set(${PREFIX}_LIBNAMES ${basename}${TMP}) 89 | if(${ARGC} GREATER 2) 90 | set(${PREFIX}_LIBNAMES ${basename}${TMP}-${ARGV2}) 91 | string(REGEX REPLACE "\\." "_" TMP ${${PREFIX}_LIBNAMES}) 92 | set(${PREFIX}_LIBNAMES ${${PREFIX}_LIBNAMES} ${TMP}) 93 | endif(${ARGC} GREATER 2) 94 | find_library(${PREFIX}_LIBRARY 95 | NAMES ${${PREFIX}_LIBNAMES} 96 | PATHS ${${PREFIX}_PKGCONF_LIBRARY_DIRS} 97 | ) 98 | endmacro(libfind_library) 99 | -------------------------------------------------------------------------------- /src/utils_string.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #include "utils.h" 10 | #include "utils_string.h" 11 | 12 | StrArray *str_array_new(char *input_str, char const *delimiters) 13 | { 14 | StrArray *out = smalloc(sizeof(StrArray)); 15 | 16 | *out = (StrArray){.length = 0, .base_str = input_str}; 17 | 18 | char *txt = strtok(input_str, delimiters); 19 | 20 | if (!txt) { 21 | return out; 22 | } 23 | 24 | while (txt) { 25 | out->data = realloc(out->data, sizeof(char *) * ++(out->length)); 26 | out->data[out->length - 1] = txt; 27 | txt = strtok(NULL, delimiters); 28 | } 29 | 30 | return out; 31 | } 32 | 33 | void str_array_free(StrArray *str_array) 34 | { 35 | if (str_array == NULL) 36 | return; 37 | 38 | free(str_array->base_str); 39 | free(str_array->data); 40 | free(str_array); 41 | } 42 | 43 | char *strip(char *str) 44 | { 45 | char *end; 46 | 47 | // Trim leading space 48 | while (isspace(*str)) 49 | str++; 50 | 51 | if (*str == 0) // All spaces? 52 | return str; 53 | 54 | // Trim trailing space 55 | end = str + strlen(str) - 1; 56 | while (end > str && isspace(*end)) 57 | end--; 58 | 59 | // Write new null terminator 60 | *(end + 1) = 0; 61 | 62 | return str; 63 | } 64 | 65 | void str_array_strip(StrArray *str_array) 66 | { 67 | for (int i = 0; i < str_array->length; i++) { 68 | str_array->data[i] = strip(str_array->data[i]); 69 | } 70 | } 71 | 72 | char *expand_tilde(char *str, const char *home) 73 | { 74 | if (str == NULL || home == NULL) 75 | return str; 76 | 77 | static char dest[MAX_LEN]; 78 | memcpy(dest, "", MAX_LEN); 79 | 80 | char *from = str; 81 | 82 | for (int i = 0; str[i]; i++) { 83 | if (i >= (MAX_LEN - 1)) { 84 | set_err(ERR_DIRS_TOO_LONG); 85 | str_copy(dest, str, MAX_LEN - 1); 86 | 87 | return dest; 88 | } 89 | 90 | if (str[i] == '~') { 91 | strncat(dest, from, &str[i] - from); 92 | strcat(dest, home); 93 | 94 | from = str + i + 1; 95 | } 96 | } 97 | 98 | strcat(dest, from); 99 | 100 | return dest; 101 | } 102 | 103 | char *xs_dirname(char *str) 104 | { 105 | char *result; 106 | 107 | /* Special cases */ 108 | 109 | if (str == NULL || strcmp(str, ".") == 0 || strcmp(str, "..") == 0 || 110 | strcmp(str, "") == 0) { 111 | result = smalloc(2); 112 | strcpy(result, "."); 113 | 114 | return result; 115 | } 116 | 117 | int i = strlen(str); 118 | 119 | if (str[i - 1] == '/') { 120 | result = smalloc(2); 121 | strcpy(result, "/"); 122 | 123 | return result; 124 | } 125 | 126 | bool found = false; 127 | 128 | while (--i) { 129 | if (str[i] == '/') { 130 | found = true; 131 | break; 132 | } 133 | } 134 | 135 | if (found) { 136 | result = smalloc(i + 1); 137 | str_copy(result, str, i + 1); 138 | result[i] = '\0'; 139 | } else { 140 | result = smalloc(2); 141 | strcpy(result, "."); 142 | } 143 | 144 | return result; 145 | } 146 | 147 | char *xs_basename(const char *path) 148 | { 149 | if (path[0] == '\0') 150 | return xs_strdup("."); 151 | 152 | size_t last_nonslash = strlen(path) - 1; 153 | 154 | while (last_nonslash >= 0 && (path[last_nonslash] == '/')) 155 | last_nonslash--; 156 | 157 | if (last_nonslash == -1) 158 | return xs_strdup("/"); 159 | 160 | size_t base = last_nonslash; 161 | 162 | while (base >= 0 && (path[base] != '/')) 163 | base--; 164 | 165 | size_t len = last_nonslash - base; 166 | char *basename = malloc(len + 1); 167 | memcpy(basename, path + (base + 1), len); 168 | basename[len] = '\0'; 169 | 170 | return basename; 171 | } 172 | 173 | char *xs_strdup(const char *str) 174 | { 175 | size_t len = 1 + strlen(str); 176 | char *ptr = smalloc(len); 177 | 178 | return ptr ? memcpy(ptr, str, len) : NULL; 179 | } 180 | 181 | void str_copy(char *dest, const char *src, size_t dest_size) 182 | { 183 | const size_t size = strlen(src); 184 | 185 | if (dest_size > size) { 186 | memcpy(dest, src, size); 187 | dest[size] = '\0'; 188 | } else { 189 | memcpy(dest, src, dest_size - 1); 190 | dest[dest_size - 1] = '\0'; 191 | } 192 | } 193 | -------------------------------------------------------------------------------- /external/inih/ini.h: -------------------------------------------------------------------------------- 1 | /* inih -- simple .INI file parser 2 | 3 | SPDX-License-Identifier: BSD-3-Clause 4 | 5 | Copyright (C) 2009-2020, Ben Hoyt 6 | 7 | inih is released under the New BSD license (see LICENSE.txt). Go to the project 8 | home page for more info: 9 | 10 | https://github.com/benhoyt/inih 11 | 12 | */ 13 | 14 | #ifndef INI_H 15 | #define INI_H 16 | 17 | /* Make this header file easier to include in C++ code */ 18 | #ifdef __cplusplus 19 | extern "C" { 20 | #endif 21 | 22 | #include 23 | 24 | /* Nonzero if ini_handler callback should accept lineno parameter. */ 25 | #ifndef INI_HANDLER_LINENO 26 | #define INI_HANDLER_LINENO 0 27 | #endif 28 | 29 | /* Typedef for prototype of handler function. */ 30 | #if INI_HANDLER_LINENO 31 | typedef int (*ini_handler)(void* user, const char* section, 32 | const char* name, const char* value, 33 | int lineno); 34 | #else 35 | typedef int (*ini_handler)(void* user, const char* section, 36 | const char* name, const char* value); 37 | #endif 38 | 39 | /* Typedef for prototype of fgets-style reader function. */ 40 | typedef char* (*ini_reader)(char* str, int num, void* stream); 41 | 42 | /* Parse given INI-style file. May have [section]s, name=value pairs 43 | (whitespace stripped), and comments starting with ';' (semicolon). Section 44 | is "" if name=value pair parsed before any section heading. name:value 45 | pairs are also supported as a concession to Python's configparser. 46 | 47 | For each name=value pair parsed, call handler function with given user 48 | pointer as well as section, name, and value (data only valid for duration 49 | of handler call). Handler should return nonzero on success, zero on error. 50 | 51 | Returns 0 on success, line number of first error on parse error (doesn't 52 | stop on first error), -1 on file open error, or -2 on memory allocation 53 | error (only when INI_USE_STACK is zero). 54 | */ 55 | int ini_parse(const char* filename, ini_handler handler, void* user); 56 | 57 | /* Same as ini_parse(), but takes a FILE* instead of filename. This doesn't 58 | close the file when it's finished -- the caller must do that. */ 59 | int ini_parse_file(FILE* file, ini_handler handler, void* user); 60 | 61 | /* Same as ini_parse(), but takes an ini_reader function pointer instead of 62 | filename. Used for implementing custom or string-based I/O (see also 63 | ini_parse_string). */ 64 | int ini_parse_stream(ini_reader reader, void* stream, ini_handler handler, 65 | void* user); 66 | 67 | /* Same as ini_parse(), but takes a zero-terminated string with the INI data 68 | instead of a file. Useful for parsing INI data from a network socket or 69 | already in memory. */ 70 | int ini_parse_string(const char* string, ini_handler handler, void* user); 71 | 72 | /* Nonzero to allow multi-line value parsing, in the style of Python's 73 | configparser. If allowed, ini_parse() will call the handler with the same 74 | name for each subsequent line parsed. */ 75 | #ifndef INI_ALLOW_MULTILINE 76 | #define INI_ALLOW_MULTILINE 1 77 | #endif 78 | 79 | /* Nonzero to allow a UTF-8 BOM sequence (0xEF 0xBB 0xBF) at the start of 80 | the file. See https://github.com/benhoyt/inih/issues/21 */ 81 | #ifndef INI_ALLOW_BOM 82 | #define INI_ALLOW_BOM 1 83 | #endif 84 | 85 | /* Chars that begin a start-of-line comment. Per Python configparser, allow 86 | both ; and # comments at the start of a line by default. */ 87 | #ifndef INI_START_COMMENT_PREFIXES 88 | #define INI_START_COMMENT_PREFIXES ";#" 89 | #endif 90 | 91 | /* Nonzero to allow inline comments (with valid inline comment characters 92 | specified by INI_INLINE_COMMENT_PREFIXES). Set to 0 to turn off and match 93 | Python 3.2+ configparser behaviour. */ 94 | #ifndef INI_ALLOW_INLINE_COMMENTS 95 | #define INI_ALLOW_INLINE_COMMENTS 1 96 | #endif 97 | #ifndef INI_INLINE_COMMENT_PREFIXES 98 | #define INI_INLINE_COMMENT_PREFIXES ";" 99 | #endif 100 | 101 | /* Nonzero to use stack for line buffer, zero to use heap (malloc/free). */ 102 | #ifndef INI_USE_STACK 103 | #define INI_USE_STACK 1 104 | #endif 105 | 106 | /* Maximum line length for any line in INI file (stack or heap). Note that 107 | this must be 3 more than the longest line (due to '\r', '\n', and '\0'). */ 108 | #ifndef INI_MAX_LINE 109 | #define INI_MAX_LINE 200 110 | #endif 111 | 112 | /* Nonzero to allow heap line buffer to grow via realloc(), zero for a 113 | fixed-size buffer of INI_MAX_LINE bytes. Only applies if INI_USE_STACK is 114 | zero. */ 115 | #ifndef INI_ALLOW_REALLOC 116 | #define INI_ALLOW_REALLOC 0 117 | #endif 118 | 119 | /* Initial size in bytes for heap line buffer. Only applies if INI_USE_STACK 120 | is zero. */ 121 | #ifndef INI_INITIAL_ALLOC 122 | #define INI_INITIAL_ALLOC 200 123 | #endif 124 | 125 | /* Stop parsing on first error (default is to keep parsing). */ 126 | #ifndef INI_STOP_ON_FIRST_ERROR 127 | #define INI_STOP_ON_FIRST_ERROR 0 128 | #endif 129 | 130 | /* Nonzero to call the handler at the start of each new section (with 131 | name and value NULL). Default is to only call the handler on 132 | each name=value pair. */ 133 | #ifndef INI_CALL_HANDLER_ON_NEW_SECTION 134 | #define INI_CALL_HANDLER_ON_NEW_SECTION 0 135 | #endif 136 | 137 | /* Nonzero to allow a name without a value (no '=' or ':' on the line) and 138 | call the handler with value NULL in this case. Default is to treat 139 | no-value lines as an error. */ 140 | #ifndef INI_ALLOW_NO_VALUE 141 | #define INI_ALLOW_NO_VALUE 0 142 | #endif 143 | 144 | /* Nonzero to use custom ini_malloc, ini_free, and ini_realloc memory 145 | allocation functions (INI_USE_STACK must also be 0). These functions must 146 | have the same signatures as malloc/free/realloc and behave in a similar 147 | way. ini_realloc is only needed if INI_ALLOW_REALLOC is set. */ 148 | #ifndef INI_CUSTOM_ALLOCATOR 149 | #define INI_CUSTOM_ALLOCATOR 0 150 | #endif 151 | 152 | 153 | #ifdef __cplusplus 154 | } 155 | #endif 156 | 157 | #endif /* INI_H */ 158 | -------------------------------------------------------------------------------- /docs/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 13 | 14 | 15 | 16 | 17 | 18 | xstarter - GNU/Linux terminal application launcher 19 | 20 | 21 | 22 | 23 |
24 |

xstarter - GNU/Linux terminal application launcher

25 |
26 | 34 |
35 |
36 |

News

37 |
49 |
50 |

xstarter is an application launcher for Linux

51 | 52 |

It lives in terminal and works well with tiling window managers (e.g. xmonad, i3 etc).

53 | 54 |

xstarter screenshot

55 | 56 |

Features

57 | 58 |
    59 |
  • a clean, simple interface that works on various terminals

  • 60 | 61 |
  • able to search for applications using environment variables (e.g. $PATH) and user-provided list of directories

  • 62 | 63 |
  • can be configured to launch via a key-binding

  • 64 | 65 |
  • can optionally open an application in terminal (see key shortcuts)

  • 66 | 67 |
  • allows to provide arguments to applications (see key shortcuts)

  • 68 | 69 |
  • remembers previously launched applications allowing to find them more quickly

  • 70 | 71 |
  • allows fuzzy search (parts of the query can be separated with a space)

  • 72 | 73 |
  • applications can be launched with 1, 2, …, 0 keys, depending on their position in the search results

  • 74 | 75 |
  • fast, uses cache by default

  • 76 | 77 |
  • easy to configure via a single text file

  • 78 |
79 | 80 |

Running xstarter

81 | 82 |

xstarter needs to be launched from a terminal ($ xstarter). It is useful to run it using a key binding, preferably by binding your preferred key to a command starting xstarter from a terminal of your choice, e.g. xterm -e xstarter. Alternatively, you can simply bind it to xstarter in which case xstarter will open itself in a terminal.

83 | 84 |

You can also create an alias in your shell (e.g. bash, zsh): alias xs=xstarter.

85 | 86 |

It should run on any modern terminal. It is tested on: xterm, rxvt, gnome-terminal, xfce4-terminal, konsole. In case of any problems please report it.

87 | 88 |

Configuration

89 | 90 |

Configuration file is available and includes comments that explain configuration variables. It is located in the ~/.xstarter.d/ directory.

91 | 92 |

Providing arguments to applications

93 | 94 |

You can provide arguments to applications you wish to open.

95 | 96 |

If the number of search results is equal to 1, you can provide arguments the selected application should be started with, e.g. surf gnu.org

97 | 98 |

You can provide multiple arguments, e.g. emacs -nw -Q

99 | 100 |

You can select the application you want to provide arguments for by pressing Tab key

101 | 102 |

This feature works both with GUI (press Enter to start) and terminal applications (press C-o to start)

103 | 104 |

Key shortcuts

105 | 106 |

Use numbers 1..9 and 0 to open an application from the list.

107 | 108 |

By default, the following shortcuts are available:

109 | 110 |
    111 |
  • Return (enter) Open selected application

  • 112 | 113 |
  • C-o Open selected application in terminal (defined by “terminal” variable in the config file, xterm by default)

  • 114 | 115 |
  • C-n Move down the list

  • 116 | 117 |
  • C-p Move up the list

  • 118 | 119 |
  • C-g Quit

  • 120 | 121 |
  • C-d Delete entered character

  • 122 | 123 |
  • C-w Delete entire query

  • 124 | 125 |
  • Tab Auto-complete using current selection; allow to provide arguments

  • 126 |
127 | 128 |

source code

129 | 130 |

See also: personal website | twitter | postgres linux desktop client

131 | 132 |
133 |
134 | 135 | 136 | -------------------------------------------------------------------------------- /src/settings.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include 5 | 6 | #include "settings.h" 7 | #include "utils.h" 8 | #include "utils_string.h" 9 | 10 | #define MATCH(s, n) (strcmp(section, s) == 0 && strcmp(name, n) == 0) 11 | 12 | static Config *_config = NULL; 13 | 14 | static void set_default_dirs(Config *conf) 15 | { 16 | conf->section_main->dirs = str_array_new(xs_strdup("$PATH"), ","); 17 | } 18 | 19 | static void set_default_terminal(Config *conf) 20 | { 21 | conf->section_main->terminal = xs_strdup("xterm"); 22 | } 23 | 24 | static void set_default_emacs_bindings(Config *conf) 25 | { 26 | conf->section_main->emacs_bindings = true; 27 | } 28 | 29 | static void set_recent_apps_first(Config *conf) 30 | { 31 | conf->section_main->recent_apps_first = true; 32 | } 33 | 34 | static void set_min_query_len(Config *conf) 35 | { 36 | conf->section_main->min_query_len = 1; 37 | } 38 | 39 | static void set_allow_spaces(Config *conf) 40 | { 41 | conf->section_main->allow_spaces = true; 42 | } 43 | 44 | static void set_numeric_shortcuts(Config *conf) 45 | { 46 | conf->section_main->numeric_shortcuts = true; 47 | } 48 | 49 | static void set_use_cache(Config *conf) 50 | { 51 | conf->section_main->use_cache = true; 52 | } 53 | 54 | static void set_auto_cache_refresh(Config *conf) 55 | { 56 | conf->section_main->auto_cache_refresh = true; 57 | } 58 | 59 | static void set_default_color_selected(Config *conf) 60 | { 61 | conf->section_colors->selected = xs_strdup("f44336"); 62 | } 63 | 64 | static void set_default_configuration(Config *conf) 65 | { 66 | // Main 67 | set_default_dirs(conf); 68 | set_default_terminal(conf); 69 | set_default_emacs_bindings(conf); 70 | set_recent_apps_first(conf); 71 | set_min_query_len(conf); 72 | set_allow_spaces(conf); 73 | set_numeric_shortcuts(conf); 74 | set_use_cache(conf); 75 | set_auto_cache_refresh(conf); 76 | 77 | // Colors 78 | set_default_color_selected(conf); 79 | } 80 | 81 | static int parse_bool(const char *value, bool *b) 82 | { 83 | if (strcmp(value, "true") == 0) { 84 | *b = true; 85 | return 1; 86 | } else if (strcmp(value, "false") == 0) { 87 | *b = false; 88 | return 1; 89 | } 90 | 91 | return 0; 92 | } 93 | 94 | static int config_read(void *data, const char *section, const char *name, 95 | const char *value) 96 | { 97 | Config *conf = (Config *)data; 98 | 99 | if (MATCH("Main", "dirs")) { 100 | char *raw_dirs = expand_tilde(value, getenv("HOME")); 101 | 102 | if (raw_dirs == NULL || strcmp(raw_dirs, "") == 0) { 103 | set_default_dirs(conf); 104 | } else { 105 | conf->section_main->dirs = str_array_new(xs_strdup(raw_dirs), ","); 106 | 107 | if (conf->section_main->dirs == NULL) { 108 | set_default_dirs(conf); 109 | } 110 | } 111 | 112 | /* Strip trailing spaces */ 113 | str_array_strip(conf->section_main->dirs); 114 | } else if (MATCH("Main", "terminal")) { 115 | conf->section_main->terminal = xs_strdup(value); 116 | 117 | if (strcmp(conf->section_main->terminal, "") == 0) { 118 | set_default_terminal(conf); 119 | } 120 | } else if (MATCH("Main", "emacs_bindings")) { 121 | if (!parse_bool(value, &conf->section_main->emacs_bindings)) { 122 | set_default_emacs_bindings(conf); 123 | } 124 | } else if (MATCH("Main", "recent_apps_first")) { 125 | if (!parse_bool(value, &conf->section_main->recent_apps_first)) { 126 | set_recent_apps_first(conf); 127 | } 128 | } else if (MATCH("Main", "min_query_len")) { 129 | conf->section_main->min_query_len = atoi(value); 130 | } else if (MATCH("Main", "numeric_shortcuts")) { 131 | if (!parse_bool(value, &conf->section_main->numeric_shortcuts)) { 132 | set_numeric_shortcuts(conf); 133 | } 134 | } else if (MATCH("Main", "use_cache")) { 135 | if (!parse_bool(value, &conf->section_main->use_cache)) { 136 | set_use_cache(conf); 137 | } 138 | } else if (MATCH("Main", "auto_cache_refresh")) { 139 | if (!parse_bool(value, &conf->section_main->auto_cache_refresh)) { 140 | set_auto_cache_refresh(conf); 141 | } 142 | } else if (MATCH("Main", "allow_spaces")) { 143 | if (!parse_bool(value, &conf->section_main->allow_spaces)) { 144 | set_allow_spaces(conf); 145 | } 146 | } else if (MATCH("Colours", "selected") || MATCH("Colors", "selected")) { 147 | conf->section_colors->selected = xs_strdup(value); 148 | } else { 149 | return 0; 150 | } 151 | 152 | return 1; 153 | } 154 | 155 | static Config *config_new() 156 | { 157 | ConfigMain *section_main = smalloc(sizeof(ConfigMain)); 158 | ConfigColors *section_colors = smalloc(sizeof(ConfigColors)); 159 | 160 | Config *c = smalloc(sizeof(Config)); 161 | 162 | *c = (Config){.section_main = section_main, 163 | .section_colors = section_colors}; 164 | 165 | return c; 166 | } 167 | 168 | Config *config_load(CmdLine *cmdline) 169 | { 170 | char path[1024]; 171 | Config *config = config_new(); 172 | 173 | if (cmdline->config_path) { 174 | if (snprintf(path, sizeof(path), "%s", cmdline->config_path) < 0) { 175 | return config; 176 | } 177 | } else if (xstarter_dir_avail) { 178 | if (snprintf(path, sizeof(path), "%s/%s", xstarter_dir, CONFIG_FILE) < 179 | 0) { 180 | return config; 181 | } 182 | } else { 183 | set_err(ERR_NO_XSTARTER_DIR); 184 | } 185 | 186 | if (ini_parse(path, config_read, config) < 0) { 187 | set_default_configuration(config); 188 | } 189 | 190 | _config = config; 191 | 192 | return config; 193 | } 194 | 195 | void config_free(Config *config) 196 | { 197 | if (!config) { 198 | return; 199 | } 200 | 201 | if (config->section_main) { 202 | str_array_free(config->section_main->dirs); 203 | free(config->section_main->terminal); 204 | free(config->section_main); 205 | } 206 | 207 | if (config->section_colors) { 208 | free(config->section_colors->selected); 209 | free(config->section_colors); 210 | } 211 | 212 | free(config); 213 | config = NULL; 214 | _config = NULL; 215 | } 216 | 217 | const Config *config_get() 218 | { 219 | return _config; 220 | } 221 | 222 | static void usage() 223 | { 224 | printf("Usage: xstarter\n\n"); 225 | printf("Optional arguments:\n"); 226 | printf(" -h Show help screen\n"); 227 | printf(" -v Show xstarter version\n"); 228 | printf(" -V Be verbose\n"); 229 | printf(" -e Execute application and detach it from terminal\n"); 230 | printf(" -r Refresh cache\n"); 231 | printf(" -c Path to the configuration file\n"); 232 | printf(" -P Print a list of applications from cache\n"); 233 | } 234 | 235 | static void print_version() 236 | { 237 | printf("%s %s\n", PROGRAM_NAME, XSTARTER_VERSION); 238 | } 239 | 240 | int cmdline_read(CmdLine *cmdline, int argc, char **argv) 241 | { 242 | int c; 243 | bool quit = false; 244 | 245 | /* Default settings: */ 246 | cmdline->config_path = NULL; 247 | cmdline->verbose = false; 248 | cmdline->force_cache_refresh = false; 249 | cmdline->print_list_of_cache_apps = false; 250 | 251 | while ((c = getopt(argc, argv, "hvre:VPc:")) != -1) { 252 | switch (c) { 253 | case 'c': 254 | cmdline->config_path = optarg; 255 | break; 256 | case 'e': 257 | open_app(optarg, "", APP_LAUNCH_MODE_GUI, 258 | /* save_open_file */ true); 259 | quit = true; 260 | break; 261 | case 'v': 262 | print_version(); 263 | quit = true; 264 | break; 265 | case 'V': 266 | cmdline->verbose = true; 267 | break; 268 | case 'r': 269 | cmdline->force_cache_refresh = true; 270 | break; 271 | case 'P': 272 | cmdline->print_list_of_cache_apps = true; 273 | break; 274 | case 'h': 275 | default: 276 | usage(); 277 | quit = true; 278 | } 279 | } 280 | 281 | return quit; 282 | } 283 | 284 | void cmdline_free(CmdLine *cmdline) 285 | { 286 | if (cmdline) { 287 | if (cmdline->config_path) 288 | free(cmdline->config_path); 289 | 290 | free(cmdline); 291 | } 292 | } 293 | -------------------------------------------------------------------------------- /external/inih/ini.c: -------------------------------------------------------------------------------- 1 | /* inih -- simple .INI file parser 2 | 3 | SPDX-License-Identifier: BSD-3-Clause 4 | 5 | Copyright (C) 2009-2020, Ben Hoyt 6 | 7 | inih is released under the New BSD license (see LICENSE.txt). Go to the project 8 | home page for more info: 9 | 10 | https://github.com/benhoyt/inih 11 | 12 | */ 13 | 14 | #if defined(_MSC_VER) && !defined(_CRT_SECURE_NO_WARNINGS) 15 | #define _CRT_SECURE_NO_WARNINGS 16 | #endif 17 | 18 | #include 19 | #include 20 | #include 21 | 22 | #include "ini.h" 23 | 24 | #if !INI_USE_STACK 25 | #if INI_CUSTOM_ALLOCATOR 26 | #include 27 | void* ini_malloc(size_t size); 28 | void ini_free(void* ptr); 29 | void* ini_realloc(void* ptr, size_t size); 30 | #else 31 | #include 32 | #define ini_malloc malloc 33 | #define ini_free free 34 | #define ini_realloc realloc 35 | #endif 36 | #endif 37 | 38 | #define MAX_SECTION 50 39 | #define MAX_NAME 50 40 | 41 | /* Used by ini_parse_string() to keep track of string parsing state. */ 42 | typedef struct { 43 | const char* ptr; 44 | size_t num_left; 45 | } ini_parse_string_ctx; 46 | 47 | /* Strip whitespace chars off end of given string, in place. Return s. */ 48 | static char* rstrip(char* s) 49 | { 50 | char* p = s + strlen(s); 51 | while (p > s && isspace((unsigned char)(*--p))) 52 | *p = '\0'; 53 | return s; 54 | } 55 | 56 | /* Return pointer to first non-whitespace char in given string. */ 57 | static char* lskip(const char* s) 58 | { 59 | while (*s && isspace((unsigned char)(*s))) 60 | s++; 61 | return (char*)s; 62 | } 63 | 64 | /* Return pointer to first char (of chars) or inline comment in given string, 65 | or pointer to NUL at end of string if neither found. Inline comment must 66 | be prefixed by a whitespace character to register as a comment. */ 67 | static char* find_chars_or_comment(const char* s, const char* chars) 68 | { 69 | #if INI_ALLOW_INLINE_COMMENTS 70 | int was_space = 0; 71 | while (*s && (!chars || !strchr(chars, *s)) && 72 | !(was_space && strchr(INI_INLINE_COMMENT_PREFIXES, *s))) { 73 | was_space = isspace((unsigned char)(*s)); 74 | s++; 75 | } 76 | #else 77 | while (*s && (!chars || !strchr(chars, *s))) { 78 | s++; 79 | } 80 | #endif 81 | return (char*)s; 82 | } 83 | 84 | /* Similar to strncpy, but ensures dest (size bytes) is 85 | NUL-terminated, and doesn't pad with NULs. */ 86 | static char* strncpy0(char* dest, const char* src, size_t size) 87 | { 88 | /* Could use strncpy internally, but it causes gcc warnings (see issue #91) */ 89 | size_t i; 90 | for (i = 0; i < size - 1 && src[i]; i++) 91 | dest[i] = src[i]; 92 | dest[i] = '\0'; 93 | return dest; 94 | } 95 | 96 | /* See documentation in header file. */ 97 | int ini_parse_stream(ini_reader reader, void* stream, ini_handler handler, 98 | void* user) 99 | { 100 | /* Uses a fair bit of stack (use heap instead if you need to) */ 101 | #if INI_USE_STACK 102 | char line[INI_MAX_LINE]; 103 | int max_line = INI_MAX_LINE; 104 | #else 105 | char* line; 106 | size_t max_line = INI_INITIAL_ALLOC; 107 | #endif 108 | #if INI_ALLOW_REALLOC && !INI_USE_STACK 109 | char* new_line; 110 | size_t offset; 111 | #endif 112 | char section[MAX_SECTION] = ""; 113 | char prev_name[MAX_NAME] = ""; 114 | 115 | char* start; 116 | char* end; 117 | char* name; 118 | char* value; 119 | int lineno = 0; 120 | int error = 0; 121 | 122 | #if !INI_USE_STACK 123 | line = (char*)ini_malloc(INI_INITIAL_ALLOC); 124 | if (!line) { 125 | return -2; 126 | } 127 | #endif 128 | 129 | #if INI_HANDLER_LINENO 130 | #define HANDLER(u, s, n, v) handler(u, s, n, v, lineno) 131 | #else 132 | #define HANDLER(u, s, n, v) handler(u, s, n, v) 133 | #endif 134 | 135 | /* Scan through stream line by line */ 136 | while (reader(line, (int)max_line, stream) != NULL) { 137 | #if INI_ALLOW_REALLOC && !INI_USE_STACK 138 | offset = strlen(line); 139 | while (offset == max_line - 1 && line[offset - 1] != '\n') { 140 | max_line *= 2; 141 | if (max_line > INI_MAX_LINE) 142 | max_line = INI_MAX_LINE; 143 | new_line = ini_realloc(line, max_line); 144 | if (!new_line) { 145 | ini_free(line); 146 | return -2; 147 | } 148 | line = new_line; 149 | if (reader(line + offset, (int)(max_line - offset), stream) == NULL) 150 | break; 151 | if (max_line >= INI_MAX_LINE) 152 | break; 153 | offset += strlen(line + offset); 154 | } 155 | #endif 156 | 157 | lineno++; 158 | 159 | start = line; 160 | #if INI_ALLOW_BOM 161 | if (lineno == 1 && (unsigned char)start[0] == 0xEF && 162 | (unsigned char)start[1] == 0xBB && 163 | (unsigned char)start[2] == 0xBF) { 164 | start += 3; 165 | } 166 | #endif 167 | start = lskip(rstrip(start)); 168 | 169 | if (strchr(INI_START_COMMENT_PREFIXES, *start)) { 170 | /* Start-of-line comment */ 171 | } 172 | #if INI_ALLOW_MULTILINE 173 | else if (*prev_name && *start && start > line) { 174 | /* Non-blank line with leading whitespace, treat as continuation 175 | of previous name's value (as per Python configparser). */ 176 | if (!HANDLER(user, section, prev_name, start) && !error) 177 | error = lineno; 178 | } 179 | #endif 180 | else if (*start == '[') { 181 | /* A "[section]" line */ 182 | end = find_chars_or_comment(start + 1, "]"); 183 | if (*end == ']') { 184 | *end = '\0'; 185 | strncpy0(section, start + 1, sizeof(section)); 186 | *prev_name = '\0'; 187 | #if INI_CALL_HANDLER_ON_NEW_SECTION 188 | if (!HANDLER(user, section, NULL, NULL) && !error) 189 | error = lineno; 190 | #endif 191 | } 192 | else if (!error) { 193 | /* No ']' found on section line */ 194 | error = lineno; 195 | } 196 | } 197 | else if (*start) { 198 | /* Not a comment, must be a name[=:]value pair */ 199 | end = find_chars_or_comment(start, "=:"); 200 | if (*end == '=' || *end == ':') { 201 | *end = '\0'; 202 | name = rstrip(start); 203 | value = end + 1; 204 | #if INI_ALLOW_INLINE_COMMENTS 205 | end = find_chars_or_comment(value, NULL); 206 | if (*end) 207 | *end = '\0'; 208 | #endif 209 | value = lskip(value); 210 | rstrip(value); 211 | 212 | /* Valid name[=:]value pair found, call handler */ 213 | strncpy0(prev_name, name, sizeof(prev_name)); 214 | if (!HANDLER(user, section, name, value) && !error) 215 | error = lineno; 216 | } 217 | else if (!error) { 218 | /* No '=' or ':' found on name[=:]value line */ 219 | #if INI_ALLOW_NO_VALUE 220 | *end = '\0'; 221 | name = rstrip(start); 222 | if (!HANDLER(user, section, name, NULL) && !error) 223 | error = lineno; 224 | #else 225 | error = lineno; 226 | #endif 227 | } 228 | } 229 | 230 | #if INI_STOP_ON_FIRST_ERROR 231 | if (error) 232 | break; 233 | #endif 234 | } 235 | 236 | #if !INI_USE_STACK 237 | ini_free(line); 238 | #endif 239 | 240 | return error; 241 | } 242 | 243 | /* See documentation in header file. */ 244 | int ini_parse_file(FILE* file, ini_handler handler, void* user) 245 | { 246 | return ini_parse_stream((ini_reader)fgets, file, handler, user); 247 | } 248 | 249 | /* See documentation in header file. */ 250 | int ini_parse(const char* filename, ini_handler handler, void* user) 251 | { 252 | FILE* file; 253 | int error; 254 | 255 | file = fopen(filename, "r"); 256 | if (!file) 257 | return -1; 258 | error = ini_parse_file(file, handler, user); 259 | fclose(file); 260 | return error; 261 | } 262 | 263 | /* An ini_reader function to read the next line from a string buffer. This 264 | is the fgets() equivalent used by ini_parse_string(). */ 265 | static char* ini_reader_string(char* str, int num, void* stream) { 266 | ini_parse_string_ctx* ctx = (ini_parse_string_ctx*)stream; 267 | const char* ctx_ptr = ctx->ptr; 268 | size_t ctx_num_left = ctx->num_left; 269 | char* strp = str; 270 | char c; 271 | 272 | if (ctx_num_left == 0 || num < 2) 273 | return NULL; 274 | 275 | while (num > 1 && ctx_num_left != 0) { 276 | c = *ctx_ptr++; 277 | ctx_num_left--; 278 | *strp++ = c; 279 | if (c == '\n') 280 | break; 281 | num--; 282 | } 283 | 284 | *strp = '\0'; 285 | ctx->ptr = ctx_ptr; 286 | ctx->num_left = ctx_num_left; 287 | return str; 288 | } 289 | 290 | /* See documentation in header file. */ 291 | int ini_parse_string(const char* string, ini_handler handler, void* user) { 292 | ini_parse_string_ctx ctx; 293 | 294 | ctx.ptr = string; 295 | ctx.num_left = strlen(string); 296 | return ini_parse_stream((ini_reader)ini_reader_string, &ctx, handler, 297 | user); 298 | } 299 | -------------------------------------------------------------------------------- /src/scan.c: -------------------------------------------------------------------------------- 1 | #define _GNU_SOURCE // strcasestr 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | #include "list.h" 15 | #include "scan.h" 16 | #include "term.h" 17 | #include "utils_string.h" 18 | 19 | List *results; 20 | 21 | static const int PATH = 1024; 22 | static void recent_apps_on_top(void); 23 | static List *get_cache(void); 24 | static void *refresh_cache(); 25 | 26 | /* Paths of applications we will search to find what we want */ 27 | static List *search_paths = NULL; 28 | 29 | /* Directories to traverse in order to find application paths */ 30 | static List *paths = NULL; 31 | static bool cache_ready = false; 32 | 33 | static pthread_t th_refresh_cache; 34 | /* Set to true if cache refresh thread should be stopped */ 35 | static bool stop_traversing; 36 | 37 | static CmdLine *cmdline; 38 | 39 | void init_search(void) 40 | { 41 | results = list_new(10); 42 | read_recently_open_list(); 43 | } 44 | 45 | void free_search(void) 46 | { 47 | if (results) { 48 | list_free(results); 49 | } 50 | } 51 | 52 | bool is_cache_ready(void) 53 | { 54 | return cache_ready; 55 | } 56 | 57 | void free_cache(void) 58 | { 59 | if (search_paths) { 60 | for (int i = 0; i < list_size(search_paths); i++) { 61 | char *t = list_get(search_paths, i); 62 | free(t); 63 | } 64 | } 65 | 66 | if (search_paths) 67 | list_free(search_paths); 68 | 69 | if (paths) { 70 | for (int i = 0; i < list_size(paths); i++) { 71 | char *t = list_get(paths, i); 72 | if (t) 73 | free(t); 74 | } 75 | } 76 | 77 | if (paths) 78 | list_free(paths); 79 | } 80 | 81 | void load_cache(CmdLine *cmdline_, bool extra_thread) 82 | { 83 | cmdline = cmdline_; 84 | 85 | stop_traversing = false; 86 | 87 | if (!extra_thread) { 88 | refresh_cache(); 89 | return; 90 | } 91 | 92 | int code = pthread_create(&th_refresh_cache, NULL, refresh_cache, NULL); 93 | 94 | if (code) { 95 | dump_debug( 96 | "Failed t create refresh_cache thread, pthread_create error code:"); 97 | dump_debug_int(code); 98 | 99 | // Refresh cache in current thread 100 | refresh_cache(); 101 | } 102 | } 103 | 104 | void kill_scan(void) 105 | { 106 | if (!cache_ready) { 107 | stop_traversing = true; 108 | pthread_join(th_refresh_cache, NULL); 109 | } else { 110 | pthread_detach(th_refresh_cache); 111 | } 112 | } 113 | 114 | /* 115 | Searches paths for a specific query 116 | 117 | Returns: 118 | true: if search was successful and we need to update GUI 119 | false: no need to update GUI 120 | */ 121 | bool search(const char *query, unsigned query_len) 122 | { 123 | const Config *conf = config_get(); 124 | 125 | bool resp = true; 126 | 127 | if (query_len < conf->section_main->min_query_len) { 128 | return false; 129 | } 130 | 131 | if (query[0] == ' ') 132 | return false; 133 | 134 | List *cache = get_cache(); 135 | 136 | int current_query_len = 1; 137 | StrArray *query_parts = NULL; 138 | 139 | if (conf->section_main->allow_spaces) { 140 | query_parts = str_array_new(xs_strdup(query), " "); 141 | 142 | if ((query_len > 0 && query[query_len - 1] == ' ') || 143 | query_parts == NULL) { 144 | resp = false; 145 | goto free_query_parts; 146 | } 147 | 148 | current_query_len = query_parts->length; 149 | } 150 | 151 | list_free(results); 152 | results = list_new(10); 153 | 154 | for (int i = 0; i < list_size(cache); i++) { 155 | char *path = (char *)list_get(cache, i); 156 | bool found = true; 157 | 158 | if (current_query_len == 1) { 159 | char *name = xs_basename(path); 160 | 161 | if (strcasestr(name, query) != NULL) { 162 | list_append(results, path); 163 | } 164 | 165 | free(name); 166 | } else if (current_query_len > 1) { 167 | for (int i = 0; i < current_query_len; i++) { 168 | if (strcmp(query_parts->data[i], " ") == 0) 169 | continue; 170 | 171 | char *name = (path); 172 | 173 | if (strstr(name, query_parts->data[i]) == NULL) { 174 | found = false; 175 | goto finish; 176 | } 177 | 178 | finish: 179 | free(name); 180 | 181 | if (!found) 182 | break; 183 | } 184 | 185 | if (found) { 186 | list_append(results, path); 187 | } 188 | } 189 | } 190 | 191 | recent_apps_on_top(); 192 | 193 | free_query_parts: 194 | str_array_free(query_parts); 195 | 196 | return resp; 197 | } 198 | 199 | void print_cache_apps(void) 200 | { 201 | // Print recently open apps 202 | for (int i = 0; i < recent_apps_cnt; i++) { 203 | printf("%s\n", recent_apps[i]); 204 | } 205 | 206 | List *cache = get_cache(); 207 | 208 | // Print other apps 209 | for (int i = 0; i < list_size(cache); i++) { 210 | const char *path = list_get(search_paths, i); 211 | 212 | printf("%s\n", path); 213 | } 214 | } 215 | 216 | /* 217 | Get apps that were recently started to the top of the list 218 | */ 219 | static void recent_apps_on_top(void) 220 | { 221 | const Config *conf = config_get(); 222 | 223 | if (!conf->section_main->recent_apps_first) { 224 | return; 225 | } 226 | 227 | List *temp = list_new(list_size(results)); 228 | 229 | for (int i = 0; i < recent_apps_cnt; i++) { 230 | for (int j = 0; j < list_size(results); j++) { 231 | if (strcmp(list_get(results, j), recent_apps[i]) == 0) { 232 | char *el = list_get(results, j); 233 | list_append(temp, el); 234 | 235 | list_del(results, j); 236 | break; 237 | } 238 | } 239 | } 240 | 241 | for (int j = 0; j < list_size(results); j++) { 242 | char *r = list_get(results, j); 243 | list_append(temp, r); 244 | } 245 | 246 | list_free(results); 247 | results = temp; 248 | } 249 | 250 | static void listdir(char *name, int level) 251 | { 252 | DIR *dir; 253 | struct dirent *entry; 254 | 255 | if (!(dir = opendir(name))) { 256 | return; 257 | } 258 | 259 | if (!(entry = readdir(dir))) { 260 | closedir(dir); 261 | return; 262 | } 263 | 264 | char buf[PATH]; 265 | 266 | do { 267 | if (stop_traversing) 268 | break; 269 | 270 | if (entry->d_type == DT_DIR) { 271 | char path[PATH]; 272 | int len = 273 | snprintf(path, sizeof(path) - 1, "%s/%s", name, entry->d_name); 274 | 275 | if (len < 0) { 276 | return; 277 | } 278 | 279 | path[len] = 0; 280 | 281 | if (strcmp(entry->d_name, ".") == 0 || 282 | strcmp(entry->d_name, "..") == 0) 283 | continue; 284 | 285 | listdir(path, level + 1); 286 | } else { 287 | struct stat sb; 288 | 289 | memset(buf, (unsigned char)' ', sizeof(buf)); 290 | 291 | strcpy(buf, name); 292 | strcat(buf, "/"); 293 | strcat(buf, entry->d_name); 294 | 295 | if (stat(buf, &sb) == 0 && sb.st_mode & S_IXUSR) { 296 | list_append(search_paths, xs_strdup(buf)); 297 | } 298 | } 299 | } while ((entry = readdir(dir)) != NULL); 300 | 301 | closedir(dir); 302 | } 303 | 304 | static void cache_to_file() 305 | { 306 | char path[1024]; 307 | if (snprintf(path, sizeof(path), "%s/cache", xstarter_dir) < 0) { 308 | return; 309 | } 310 | 311 | FILE *file = fopen(path, "w"); 312 | 313 | for (int i = 0; i < list_size(search_paths); i++) { 314 | char *t = list_get(search_paths, i); 315 | 316 | fprintf(file, "%s\n", t); 317 | } 318 | 319 | fclose(file); 320 | } 321 | 322 | static void read_cache_file() 323 | { 324 | FILE *fptr; 325 | 326 | char path[1024]; 327 | search_paths = list_new(10); 328 | if (snprintf(path, sizeof(path), "%s/cache", xstarter_dir) < 0) { 329 | return; 330 | } 331 | 332 | fptr = fopen(path, "r"); 333 | 334 | if (!fptr) { 335 | return; 336 | } 337 | 338 | char line[1024]; 339 | 340 | while (fgets(line, 1024, fptr)) { 341 | line[strcspn(line, "\n")] = 0; 342 | list_append(search_paths, xs_strdup(line)); 343 | } 344 | 345 | fclose(fptr); 346 | } 347 | 348 | static bool cache_needs_refresh() 349 | { 350 | /* If a user requested cache refresh from the cmdline */ 351 | if (cmdline->force_cache_refresh) 352 | return true; 353 | 354 | const Config *conf = config_get(); 355 | 356 | if (!conf->section_main->use_cache) 357 | return true; 358 | 359 | if (!conf->section_main->auto_cache_refresh) 360 | return false; 361 | 362 | /* If cache file does not exist then yes */ 363 | 364 | struct stat cache_stat; 365 | time_t cache_time; 366 | 367 | char path[1024]; 368 | if (snprintf(path, sizeof(path), "%s/cache", xstarter_dir) < 0) { 369 | return false; 370 | } 371 | 372 | if (stat(path, &cache_stat) == -1) { 373 | /* Does not exist */ 374 | return true; 375 | } else { 376 | /* If exists, get last modification time */ 377 | cache_time = mktime(localtime(&(cache_stat.st_ctime))); 378 | } 379 | 380 | /* Compare last modification dates of cache and directories */ 381 | 382 | struct stat dir_stat; 383 | time_t dir_time; 384 | 385 | for (int i = 0; i < list_size(paths); i++) { 386 | char *dir = list_get(paths, i); 387 | 388 | if (stat(dir, &dir_stat) == 0) { 389 | dir_time = mktime(localtime(&(dir_stat.st_ctime))); 390 | 391 | double diff = difftime(dir_time, cache_time); 392 | 393 | if (diff > 0) { 394 | /* A directory is more fresh that cache file - */ 395 | /* Need to refresh */ 396 | return true; 397 | } 398 | } 399 | } 400 | 401 | return false; 402 | } 403 | 404 | static void *refresh_cache() 405 | { 406 | paths = list_new(10); 407 | 408 | StrArray *dirs = config_get()->section_main->dirs; 409 | 410 | for (int i = 0; i < dirs->length; i++) { 411 | if (dirs->data[i][0] == '$') { 412 | char const *var = getenv(++dirs->data[i]); 413 | 414 | if (var) { 415 | StrArray *var_paths = str_array_new(xs_strdup(var), ":"); 416 | 417 | if (var_paths) { 418 | for (int j = 0; j < var_paths->length; j++) { 419 | if (var_paths->data[j]) { 420 | list_append(paths, xs_strdup(var_paths->data[j])); 421 | } 422 | } 423 | } 424 | str_array_free(var_paths); 425 | } 426 | } else { 427 | list_append(paths, xs_strdup(dirs->data[i])); 428 | } 429 | } 430 | 431 | if (cache_needs_refresh()) { 432 | search_paths = list_new(10); 433 | 434 | for (int i = 0; i < list_size(paths); i++) { 435 | char *t = list_get(paths, i); 436 | 437 | listdir(t, 0); 438 | } 439 | 440 | const Config *conf = config_get(); 441 | 442 | if (conf->section_main->use_cache) 443 | cache_to_file(); 444 | } else 445 | read_cache_file(); 446 | 447 | cache_ready = true; 448 | cache_loaded(); 449 | 450 | return NULL; 451 | } 452 | 453 | static List *get_cache(void) 454 | { 455 | return search_paths; 456 | } 457 | -------------------------------------------------------------------------------- /src/term.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include // umask 8 | #include // execve 9 | 10 | #include 11 | 12 | #include "list.h" 13 | #include "scan.h" 14 | #include "settings.h" 15 | #include "term.h" 16 | #include "utils.h" 17 | 18 | #define MAX_INPUT_LENGTH (80) 19 | #define KEY_ESCAPE (27) 20 | #define KEY_RETURN (10) 21 | 22 | // Seemed to help for ncurses 5.9 23 | #define KEY_BACKSPACE_ALTERNATIVE (8) 24 | #define KEY_DELETE (127) 25 | 26 | // Needed for key binding, non-standard 27 | #define KEY_CONTROL_RETURN (256) 28 | 29 | #define MAX_ITEMS (100) 30 | 31 | static const unsigned MAX_Y = 15; 32 | static const unsigned RECENT_APPS_SHOWN = 10; 33 | static const unsigned XS_COL_SEL = 8; 34 | 35 | static const unsigned XS_COLOR_PAIR_1 = 1; 36 | 37 | static const unsigned MAX_LIST_ITEM_LENGTH = 24; 38 | 39 | typedef struct { 40 | List *names; 41 | char query[MAX_INPUT_LENGTH]; 42 | bool run_app; 43 | unsigned query_len; 44 | 45 | // Selection is fixed in order to provide arguments 46 | bool fixed_selection; 47 | } search_t; 48 | 49 | typedef struct { 50 | unsigned row_start; 51 | unsigned row_end; 52 | } view_t; 53 | 54 | typedef struct { 55 | char *items[MAX_ITEMS]; 56 | unsigned choices_cnt; 57 | unsigned offset; 58 | unsigned selected; 59 | char *error; 60 | } items_list_t; 61 | 62 | static search_t status = { 63 | .names = NULL, 64 | .query_len = 0, 65 | .run_app = false, 66 | .fixed_selection = false, 67 | }; 68 | 69 | static view_t view_search_bar = {.row_start = 0, .row_end = 0}; 70 | 71 | static view_t view_info_bar = {.row_start = 13, .row_end = 14}; 72 | 73 | static items_list_t items_list; 74 | 75 | static void erase_view(const view_t *view); 76 | static int read_emacs_keys(const char *name); 77 | static void move_up(void); 78 | static void move_down(void); 79 | static void reset_query(void); 80 | static void open_by_shortcut(int key); 81 | static void clean_line(int line_y); 82 | static void prepare_for_new_results(void); 83 | static void show_menu(void); 84 | static void show_recent_apps(void); 85 | static void complete_selected_entry(void); 86 | 87 | void cache_loaded(void) 88 | { 89 | erase_view(&view_search_bar); 90 | mvprintw(0, 0, ""); 91 | refresh(); 92 | } 93 | 94 | void init_term_gui(void) 95 | { 96 | /* Fix ESC key */ 97 | set_escdelay(25); 98 | 99 | initscr(); 100 | start_color(); 101 | cbreak(); 102 | noecho(); 103 | keypad(stdscr, TRUE); 104 | 105 | const Config *conf = config_get(); 106 | 107 | colour_t col_sel; 108 | get_rgb(&col_sel, conf->section_colors->selected); 109 | 110 | if (can_change_color()) { 111 | init_color(XS_COL_SEL, col_sel.r, col_sel.g, col_sel.b); 112 | init_pair(XS_COLOR_PAIR_1, COLOR_WHITE, XS_COL_SEL); 113 | } else { 114 | init_pair(XS_COLOR_PAIR_1, COLOR_WHITE, COLOR_BLUE); 115 | } 116 | 117 | show_recent_apps(); 118 | prepare_for_new_results(); 119 | 120 | show_menu(); 121 | 122 | erase_view(&view_search_bar); 123 | 124 | mvprintw(0, 0, "Loading paths..."); 125 | 126 | refresh(); 127 | } 128 | 129 | void run_term(void) 130 | { 131 | const Config *conf = config_get(); 132 | 133 | int c; 134 | 135 | while ((c = getch()) != KEY_ESCAPE) { 136 | if (conf->section_main->emacs_bindings) { 137 | int key = read_emacs_keys(keyname(c)); 138 | 139 | if (key != -1) { 140 | if (key == KEY_ESCAPE) 141 | break; 142 | c = key; 143 | } 144 | } 145 | 146 | open_by_shortcut(c); 147 | 148 | switch (c) { 149 | case 0: 150 | // No-op, needed for shortcuts 151 | break; 152 | 153 | case KEY_DOWN: 154 | move_down(); 155 | break; 156 | 157 | case KEY_UP: 158 | move_up(); 159 | break; 160 | 161 | case KEY_CONTROL_RETURN: 162 | status.run_app = true; 163 | 164 | open_app(list_get(results, items_list.selected + items_list.offset), 165 | status.query, APP_LAUNCH_MODE_TERM, true); 166 | break; 167 | 168 | case KEY_RETURN: 169 | status.run_app = true; 170 | 171 | open_app(list_get(results, items_list.selected + items_list.offset), 172 | status.query, APP_LAUNCH_MODE_GUI, true); 173 | 174 | break; 175 | 176 | case '\t': 177 | complete_selected_entry(); 178 | erase_view(&view_search_bar); 179 | mvprintw(0, 0, status.query); 180 | 181 | prepare_for_new_results(); 182 | 183 | break; 184 | 185 | case KEY_DELETE: 186 | case KEY_BACKSPACE: 187 | case KEY_BACKSPACE_ALTERNATIVE: 188 | if (!status.query_len) 189 | continue; 190 | 191 | status.query_len--; 192 | 193 | if (status.query_len) { 194 | char *new_query = smalloc(status.query_len + 1); 195 | memcpy(new_query, status.query, status.query_len); 196 | new_query[status.query_len] = '\0'; 197 | 198 | status.query[status.query_len] = 0; 199 | 200 | erase_view(&view_search_bar); 201 | mvprintw(0, 0, status.query); 202 | 203 | if (!status.fixed_selection) { 204 | search(new_query, status.query_len); 205 | prepare_for_new_results(); 206 | } 207 | 208 | free(new_query); 209 | } else 210 | reset_query(); 211 | 212 | break; 213 | 214 | default: 215 | if (status.query_len >= MAX_INPUT_LENGTH) 216 | continue; 217 | 218 | if (!isprint(c)) 219 | continue; 220 | 221 | if (!is_cache_ready()) 222 | continue; 223 | 224 | if (status.query_len == 0 && c == ' ') { 225 | reset_query(); 226 | 227 | continue; 228 | } else if (status.query_len == 0) { 229 | clean_line(0); 230 | } 231 | 232 | status.query[status.query_len] = c; 233 | 234 | mvaddch(0, status.query_len, c); 235 | 236 | status.query_len++; 237 | char new_query[status.query_len]; 238 | 239 | memcpy(new_query, status.query, status.query_len); 240 | new_query[status.query_len] = '\0'; 241 | 242 | if (status.fixed_selection) { 243 | continue; 244 | } 245 | 246 | if (search(new_query, status.query_len)) 247 | prepare_for_new_results(); 248 | } 249 | 250 | show_menu(); 251 | move(0, status.query_len); 252 | refresh(); 253 | 254 | if (status.run_app) 255 | break; 256 | } 257 | 258 | endwin(); 259 | } 260 | 261 | static void clean_line(int line_y) 262 | { 263 | move(line_y, 0); 264 | clrtoeol(); 265 | } 266 | 267 | static void erase_view(const view_t *view) 268 | { 269 | for (int i = view->row_start; i <= view->row_end; i++) 270 | clean_line(i); 271 | } 272 | 273 | static void clear_menu(void) 274 | { 275 | for (int i = 0; i < MAX_ITEMS; i++) { 276 | items_list.items[i] = NULL; 277 | } 278 | } 279 | 280 | static void update_info_bar(void) 281 | { 282 | erase_view(&view_info_bar); 283 | 284 | if (items_list.choices_cnt > 0) { 285 | if (items_list.selected >= items_list.choices_cnt) { 286 | items_list.selected = 0; 287 | items_list.offset = 0; 288 | } 289 | 290 | unsigned item = items_list.selected + items_list.offset; 291 | 292 | char *l = list_get(results, item); 293 | 294 | if (l) { 295 | char text[100]; 296 | 297 | if (snprintf(text, 100, "Results: %d", items_list.choices_cnt) < 298 | 0) { 299 | return; 300 | } 301 | 302 | mvprintw(MAX_Y - 2, 0, text); 303 | mvprintw(MAX_Y - 1, 0, l); 304 | } 305 | } 306 | } 307 | 308 | static void draw_menu_item(unsigned i) 309 | { 310 | int item_id = items_list.offset + i; 311 | 312 | if (items_list.items[item_id]) { 313 | char item[MAX_LIST_ITEM_LENGTH]; 314 | 315 | unsigned shortcut = (i == 9) ? 0 : i + 1; 316 | 317 | if (snprintf(item, MAX_LIST_ITEM_LENGTH, "%d %s", shortcut, 318 | items_list.items[item_id]) < 0) { 319 | return; 320 | } 321 | 322 | mvprintw(i + 2, 0, item); 323 | } 324 | } 325 | 326 | static void show_menu(void) 327 | { 328 | for (int i = 0; i < 10; i++) { 329 | wmove(stdscr, i + 2, 0); 330 | 331 | wclrtoeol(stdscr); 332 | } 333 | 334 | if (items_list.choices_cnt) { 335 | for (unsigned i = 0; i < 10; i++) { 336 | if (i == items_list.selected) 337 | attron(COLOR_PAIR(1)); 338 | 339 | draw_menu_item(i); 340 | 341 | if (i == items_list.selected) 342 | attroff(COLOR_PAIR(1)); 343 | } 344 | } else { 345 | mvprintw(2, 0, "No results found, sorry"); 346 | } 347 | } 348 | 349 | static void move_down(void) 350 | { 351 | if (items_list.selected + items_list.offset >= items_list.choices_cnt - 1) 352 | return; 353 | 354 | if (items_list.selected >= 9 && items_list.choices_cnt > 10) { 355 | items_list.offset++; 356 | } else if (items_list.selected < items_list.choices_cnt - 1) 357 | items_list.selected++; 358 | 359 | update_info_bar(); 360 | } 361 | 362 | static void move_up(void) 363 | { 364 | if (items_list.selected + items_list.offset == 0) 365 | return; 366 | 367 | if (items_list.selected == 0 && items_list.offset > 0) { 368 | items_list.offset--; 369 | } else if (items_list.selected > 0) 370 | items_list.selected--; 371 | 372 | update_info_bar(); 373 | } 374 | 375 | static void prepare_for_new_results(void) 376 | { 377 | const Config *conf = config_get(); 378 | 379 | clear_menu(); 380 | 381 | if (!status.names) { 382 | status.names = list_new(10); 383 | } 384 | 385 | items_list.choices_cnt = list_size(results); 386 | 387 | int cnt = 388 | items_list.choices_cnt > MAX_ITEMS ? MAX_ITEMS : items_list.choices_cnt; 389 | 390 | for (int i = 0; i < cnt; i++) { 391 | char *path = list_get(results, i); 392 | char *name = xs_basename(path); 393 | list_append(status.names, name); 394 | 395 | if (conf->section_main->numeric_shortcuts) { 396 | if (i < 10) { 397 | items_list.items[i] = name; 398 | } else 399 | items_list.items[i] = name; 400 | } else { 401 | items_list.items[i] = name; 402 | } 403 | } 404 | 405 | update_info_bar(); 406 | } 407 | 408 | static void show_recent_apps(void) 409 | { 410 | bool recent_apps_valid = true; 411 | 412 | for (items_list.choices_cnt = 0; items_list.choices_cnt < RECENT_APPS_SHOWN; 413 | items_list.choices_cnt++) { 414 | if (recent_apps[items_list.choices_cnt] != NULL && 415 | strcmp(recent_apps[items_list.choices_cnt], "") != 0) { 416 | for (int i = 0; i < strlen(recent_apps[items_list.choices_cnt]); 417 | i++) { 418 | if (!isprint(recent_apps[items_list.choices_cnt][i])) { 419 | recent_apps_valid = false; 420 | break; 421 | } 422 | } 423 | 424 | if (!recent_apps_valid) 425 | break; 426 | 427 | list_append(results, recent_apps[items_list.choices_cnt]); 428 | } 429 | } 430 | } 431 | 432 | static void open_by_shortcut(int key) 433 | { 434 | const Config *conf = config_get(); 435 | 436 | if (!conf->section_main->numeric_shortcuts) { 437 | return; 438 | } 439 | 440 | if (key >= ASCII_1 && key <= ASCII_9) { 441 | status.run_app = true; 442 | 443 | open_app(list_get(results, items_list.offset + (key - ASCII_1)), 444 | status.query, APP_LAUNCH_MODE_GUI, true); 445 | } else if (key == ASCII_0) { 446 | status.run_app = true; 447 | 448 | open_app(list_get(results, RECENT_APPS_SHOWN - 1), status.query, 449 | APP_LAUNCH_MODE_GUI, true); 450 | } 451 | } 452 | 453 | static void reset_query(void) 454 | { 455 | erase_view(&view_search_bar); 456 | clear_menu(); 457 | strcpy(status.query, ""); 458 | status.query_len = 0; 459 | status.fixed_selection = false; 460 | 461 | list_free(results); 462 | results = list_new(10); 463 | items_list.selected = 0; 464 | items_list.offset = 0; 465 | show_recent_apps(); 466 | prepare_for_new_results(); 467 | } 468 | 469 | static void complete_selected_entry(void) 470 | { 471 | char *selected = list_get(results, items_list.selected + items_list.offset); 472 | 473 | if (!selected) 474 | return; 475 | 476 | char *name = (selected); 477 | strcpy(status.query, name); 478 | status.query_len = strlen(name); 479 | status.fixed_selection = true; 480 | 481 | if (name) 482 | free(name); 483 | 484 | list_free(results); 485 | results = list_new(10); 486 | 487 | list_append(results, selected); 488 | } 489 | 490 | static int read_emacs_keys(const char *name) 491 | { 492 | if (strcmp(name, "^N") == 0) { 493 | return KEY_DOWN; 494 | } else if (strcmp(name, "^P") == 0) { 495 | return KEY_UP; 496 | } else if (strcmp(name, "^G") == 0) { 497 | return KEY_ESCAPE; 498 | } else if (strcmp(name, "^W") == 0) { 499 | reset_query(); 500 | return 0; 501 | } else if (strcmp(name, "^D") == 0) { 502 | return KEY_BACKSPACE; 503 | } else if (strcmp(name, "^O") == 0) { 504 | return KEY_CONTROL_RETURN; 505 | } 506 | 507 | return -1; 508 | } 509 | -------------------------------------------------------------------------------- /src/utils.c: -------------------------------------------------------------------------------- 1 | #define _GNU_SOURCE 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include // umask 9 | #include // execve, readlink 10 | 11 | #include "utils.h" 12 | #include "utils_string.h" 13 | 14 | static void record_open_file(const char *path); 15 | static bool check_path(char *out, char *in); 16 | static bool get_xstarter_path(int argc, char **argv, char *path); 17 | static char *get_home_dir(); 18 | 19 | int err; 20 | char xstarter_dir[1024]; 21 | int xstarter_dir_avail; 22 | char recent_apps[100][1024]; 23 | int recent_apps_cnt; 24 | char exec_term[32]; 25 | 26 | static const char *error_messages[] = { 27 | "No error, all's fine", 28 | "No xstarter path found", 29 | "No xstarter directory found", 30 | "List of directories is too long", 31 | "Failed to create the ~/.xstarter.d directory", 32 | "Fork failed", 33 | "setsid() failed", 34 | "chdir() failed", 35 | "dumping debugging data failed", 36 | "redirecting to dev/null failed", 37 | }; 38 | 39 | void get_rgb(colour_t *dest, char *src) 40 | { 41 | if (strlen(src) && src[0] == ';') 42 | src++; 43 | 44 | int c = (int)strtol(src, NULL, 16); 45 | 46 | dest->r = ((c >> 16) & 0xff) / 255.0 * 1000; 47 | dest->g = ((c >> 8) & 0xff) / 255.0 * 1000; 48 | dest->b = (c & 0xff) / 255.0 * 1000; 49 | } 50 | 51 | void open_app(const char *path, const char *query, app_launch_mode_t mode, 52 | bool save_open_file) 53 | { 54 | if (!path || !query) 55 | return; 56 | 57 | char path_cpy[1024]; 58 | strcpy(path_cpy, path); 59 | 60 | if (save_open_file) { 61 | record_open_file(path_cpy); 62 | } 63 | 64 | pid_t pid; 65 | 66 | switch (pid = fork()) { 67 | case -1: 68 | dump_debug("fork failed"); 69 | dump_debug_int(errno); 70 | 71 | set_err(ERR_FORK_FAILED); 72 | 73 | break; 74 | 75 | case 0: // Child 76 | /* Change the file mode mask */ 77 | umask(0); 78 | 79 | if (setsid() < 0) { 80 | dump_debug("setsid failed"); 81 | dump_debug_int(errno); 82 | 83 | set_err(ERR_SETSID_FAILED); 84 | } 85 | 86 | char *dir = get_home_dir(); 87 | 88 | if (chdir(dir ? dir : "/tmp") < 0) { 89 | dump_debug("chdir failed"); 90 | dump_debug_int(errno); 91 | 92 | set_err(ERR_CHDIR_FAILED); 93 | } 94 | 95 | /* Redirect standard files to /dev/null */ 96 | if (freopen("/dev/null", "r", stdin) == NULL) { 97 | set_err(ERR_REDIRECTING_TO_DEV_NULL_FAILED); 98 | } 99 | 100 | if (freopen("/dev/null", "w", stdout) == NULL) { 101 | set_err(ERR_REDIRECTING_TO_DEV_NULL_FAILED); 102 | } 103 | if (freopen("/dev/null", "w", stderr) == NULL) { 104 | set_err(ERR_REDIRECTING_TO_DEV_NULL_FAILED); 105 | } 106 | 107 | StrArray *query_parts = str_array_new((char *)query, " "); 108 | int args_cnt = 0; 109 | const int STR_SIZE = 255; 110 | 111 | extern char **environ; 112 | 113 | if (mode == APP_LAUNCH_MODE_GUI) { 114 | if (query_parts->length <= 1) 115 | args_cnt = 2; 116 | else { 117 | args_cnt = 2 + query_parts->length - 118 | 1; // First argument is command name 119 | } 120 | 121 | char **args = smalloc(args_cnt * sizeof(char *)); 122 | 123 | for (int i = 0; i < args_cnt; i++) { 124 | args[i] = smalloc(STR_SIZE); 125 | } 126 | 127 | str_copy(args[0], path_cpy, STR_SIZE); 128 | args[args_cnt - 1] = NULL; 129 | 130 | for (int i = 1; i < query_parts->length; i++) { 131 | str_copy(args[i], query_parts->data[i], STR_SIZE); 132 | } 133 | 134 | if (args[0][0] == '/') { 135 | execve(args[0], &args[0], environ); 136 | } else { 137 | execvpe(args[0], &args[0], environ); 138 | } 139 | } else if (mode == APP_LAUNCH_MODE_TERM) { 140 | if (query_parts->length <= 1) 141 | args_cnt = 4; 142 | else { 143 | args_cnt = 4 + query_parts->length - 144 | 1; // First argument is command name 145 | } 146 | 147 | char **args = smalloc(args_cnt * sizeof(char *)); 148 | 149 | for (int i = 0; i < args_cnt; i++) { 150 | args[i] = smalloc(STR_SIZE); 151 | } 152 | 153 | str_copy(args[0], exec_term, STR_SIZE); 154 | str_copy(args[1], "-e", STR_SIZE); 155 | str_copy(args[2], path_cpy, STR_SIZE); 156 | 157 | args[args_cnt - 1] = NULL; 158 | 159 | for (int i = 1; i < query_parts->length; i++) { 160 | str_copy(args[i + 2], query_parts->data[i], STR_SIZE); 161 | } 162 | 163 | execvpe(args[0], &args[0], environ); 164 | } 165 | } 166 | } 167 | 168 | static void record_open_file(const char *path) 169 | { 170 | if (xstarter_dir_avail) { 171 | char recently_f[1024]; 172 | 173 | if (snprintf(recently_f, sizeof(recently_f), "%s/recent", 174 | xstarter_dir) < 0) { 175 | return; 176 | } 177 | 178 | FILE *file = fopen(recently_f, "w"); 179 | 180 | if (file) { 181 | // Check if it's already in the list 182 | 183 | int path_index = -1; 184 | 185 | int items_to_save = recent_apps_cnt + 1; 186 | 187 | for (int i = 0; i < recent_apps_cnt; i++) { 188 | if (strcmp(recent_apps[i], path) == 0) { 189 | path_index = i; 190 | items_to_save -= 1; 191 | } 192 | } 193 | 194 | int last_index = recent_apps_cnt; 195 | 196 | if (last_index >= RECENT_APPS_REMEMBERED) { 197 | last_index = recent_apps_cnt - 1; 198 | items_to_save = RECENT_APPS_REMEMBERED; 199 | } 200 | 201 | // Remove item already existing in the list 202 | if (path_index != -1) { 203 | for (int i = path_index; i < last_index; i++) { 204 | strcpy(recent_apps[i], recent_apps[i + 1]); 205 | } 206 | } 207 | 208 | // Move rest of the items 209 | 210 | for (int i = last_index; i > 0; i--) { 211 | strcpy(recent_apps[i], recent_apps[i - 1]); 212 | } 213 | 214 | strcpy(recent_apps[0], path); 215 | 216 | for (int i = 0; i < items_to_save; i++) { 217 | fprintf(file, "%s\n", recent_apps[i]); 218 | } 219 | 220 | fclose(file); 221 | } 222 | } 223 | } 224 | 225 | void read_recently_open_list() 226 | { 227 | recent_apps_cnt = 0; 228 | 229 | if (xstarter_dir_avail) { 230 | FILE *fptr; 231 | char recently_f[1024]; 232 | 233 | if (snprintf(recently_f, sizeof(recently_f), "%s/recent", 234 | xstarter_dir) < 0) { 235 | return; 236 | } 237 | 238 | fptr = fopen(recently_f, "r"); 239 | 240 | if (fptr) { 241 | char line[1024]; 242 | 243 | int i = 0; 244 | 245 | while (fgets(line, 1024, fptr)) { 246 | memmove(recent_apps[i], line, strlen(line) - 1); 247 | i++; 248 | } 249 | 250 | recent_apps_cnt = i; 251 | 252 | fclose(fptr); 253 | } 254 | } 255 | } 256 | 257 | void dump_debug(const char *str) 258 | { 259 | char debug[1024]; 260 | 261 | snprintf(debug, 1024, "echo %s>> ~/debug_xstarter", str); 262 | 263 | int ret = system(debug); 264 | 265 | if (ret) { 266 | set_err(ERR_DUMP_DEBUG_FAILED); 267 | } 268 | } 269 | 270 | void dump_debug_ptr(const char *str) 271 | { 272 | char debug[1024]; 273 | 274 | snprintf(debug, 1024, "echo %p>> ~/debug_xstarter", (void *)&str); 275 | 276 | int ret = system(debug); 277 | 278 | if (ret) { 279 | set_err(ERR_DUMP_DEBUG_FAILED); 280 | } 281 | } 282 | 283 | void dump_debug_char(const char c) 284 | { 285 | char debug[1024]; 286 | 287 | snprintf(debug, 1024, "echo %c>> ~/debug_xstarter", c); 288 | 289 | int ret = system(debug); 290 | 291 | if (ret) { 292 | set_err(ERR_DUMP_DEBUG_FAILED); 293 | } 294 | } 295 | 296 | void dump_debug_int(int d) 297 | { 298 | char debug[1024]; 299 | 300 | snprintf(debug, 1024, "echo %d >> ~/debug_xstarter", d); 301 | 302 | int ret = system(debug); 303 | 304 | if (ret) { 305 | set_err(ERR_DUMP_DEBUG_FAILED); 306 | } 307 | } 308 | 309 | bool in_terminal() 310 | { 311 | bool xstarter_run = getenv("XSTARTER") ? true : false; 312 | 313 | return xstarter_run || isatty(STDOUT_FILENO); 314 | } 315 | 316 | void open_itself(int argc, char **argv) 317 | { 318 | pid_t pid = fork(); 319 | 320 | if (pid < 0) { 321 | dump_debug("Fork failed"); 322 | exit(1); 323 | } else if (pid > 0) { 324 | exit(0); 325 | } else { 326 | char xstarter_path[MAX_LEN]; 327 | 328 | if (!get_xstarter_path(argc, argv, xstarter_path)) { 329 | dump_debug("xstarter path not found, will try $PATH"); 330 | dump_debug_int(errno); 331 | 332 | set_err(ERR_NO_XSTARTER_PATH); 333 | 334 | strcpy(xstarter_path, "xstarter"); 335 | } 336 | 337 | umask(0); 338 | 339 | if (setsid() < 0) { 340 | dump_debug("setsid failed"); 341 | dump_debug_int(errno); 342 | 343 | set_err(ERR_SETSID_FAILED); 344 | } 345 | 346 | if (chdir("/") < 0) { 347 | dump_debug("chdir failed"); 348 | dump_debug_int(errno); 349 | 350 | set_err(ERR_CHDIR_FAILED); 351 | } 352 | 353 | /* Redirect standard files to /dev/null */ 354 | if (freopen("/dev/null", "r", stdin) == NULL) { 355 | set_err(ERR_REDIRECTING_TO_DEV_NULL_FAILED); 356 | } 357 | 358 | if (freopen("/dev/null", "w", stdout) == NULL) { 359 | set_err(ERR_REDIRECTING_TO_DEV_NULL_FAILED); 360 | } 361 | 362 | if (freopen("/dev/null", "w", stderr) == NULL) { 363 | set_err(ERR_REDIRECTING_TO_DEV_NULL_FAILED); 364 | } 365 | 366 | extern char **environ; 367 | 368 | int env_cnt = 0; 369 | 370 | for (char *it = environ[0]; *it; it++, env_cnt++) 371 | ; 372 | 373 | char **newenvp = malloc((env_cnt + 2) * sizeof(char *)); 374 | 375 | for (int i = 0; i < env_cnt - 2; i++) { 376 | newenvp[i] = environ[i]; 377 | } 378 | 379 | newenvp[env_cnt - 2] = "XSTARTER=1"; 380 | newenvp[env_cnt - 1] = NULL; 381 | 382 | char *term_argv[] = {exec_term, "-e", xstarter_path, NULL}; 383 | 384 | execvpe(term_argv[0], &term_argv[0], newenvp); 385 | } 386 | } 387 | 388 | void xstarter_directory() 389 | { 390 | xstarter_dir_avail = true; 391 | bool using_tmp_dir = false; 392 | 393 | char *dir = get_home_dir(); 394 | 395 | if (!dir) { 396 | using_tmp_dir = true; 397 | dir = smalloc(1024); 398 | strcpy(dir, "/tmp"); 399 | } 400 | 401 | if (dir) { 402 | snprintf(xstarter_dir, sizeof(xstarter_dir), "%s/.xstarter.d", dir); 403 | 404 | if (using_tmp_dir) 405 | free(dir); 406 | 407 | struct stat st = {0}; 408 | 409 | if (stat(xstarter_dir, &st) == -1) { 410 | if (mkdir(xstarter_dir, 0700)) { 411 | set_err(ERR_XSTARTER_MKDIR_FAILED); 412 | } else { 413 | xstarter_dir_avail = true; 414 | } 415 | } else { 416 | xstarter_dir_avail = true; 417 | } 418 | } 419 | } 420 | 421 | void set_err(int err_code) 422 | { 423 | /* Only set the first encountered error */ 424 | if (err == NO_ERR) 425 | err = err_code; 426 | } 427 | 428 | int get_err() 429 | { 430 | return err; 431 | } 432 | 433 | void print_err() 434 | { 435 | printf("Error code: %d\n", err); 436 | 437 | ssize_t cnt = sizeof(error_messages) / sizeof(char *); 438 | 439 | if (err < cnt) { 440 | PRINTS(error_messages[err]); 441 | } else { 442 | PRINTS("Unknown error"); 443 | } 444 | } 445 | 446 | void *safe_malloc(size_t n, unsigned long line) 447 | { 448 | void *p = malloc(n); 449 | 450 | if (!p) { 451 | fprintf(stderr, "[%s:%lu] Out of memory(%lu bytes)\n", __FILE__, line, 452 | (unsigned long)n); 453 | 454 | exit(EXIT_FAILURE); 455 | } 456 | 457 | return p; 458 | } 459 | 460 | static bool check_path(char *out, char *in) 461 | { 462 | if (in[0] == '/') { 463 | /* Absolute path */ 464 | 465 | strcpy(out, in); 466 | 467 | return true; 468 | } else if (in[0] == '.' && in[1] == '/') { 469 | /* Path starting with ./ - append it to cwd */ 470 | 471 | char cwd[MAX_LEN]; 472 | 473 | if (getcwd(cwd, sizeof(cwd)) != NULL) { 474 | char *xs = in; 475 | xs += 2; 476 | strcat(cwd, "/"); 477 | strcat(cwd, xs); 478 | 479 | return true; 480 | } 481 | } 482 | 483 | return false; 484 | } 485 | 486 | /* 487 | Get path to xstarter using different methods 488 | 489 | Returns true if the path was found, false otherwise 490 | */ 491 | static bool get_xstarter_path(int argc, char **argv, char *path) 492 | { 493 | if (argc >= 1) 494 | return check_path(path, argv[0]); 495 | 496 | ssize_t len; 497 | 498 | len = readlink("/proc/self/exe", path, MAX_LEN - 1); 499 | 500 | if (len != -1) { 501 | path[len] = '\0'; 502 | 503 | return true; 504 | } 505 | 506 | len = readlink("/proc/curproc/file", path, MAX_LEN - 1); 507 | 508 | if (len != -1) { 509 | path[len] = '\0'; 510 | 511 | return true; 512 | } 513 | 514 | return false; 515 | } 516 | 517 | /* 518 | Get user's home directory 519 | */ 520 | static char *get_home_dir() 521 | { 522 | char *dir = NULL; 523 | 524 | if ((dir = (getenv("HOME"))) == NULL) { 525 | struct passwd *pw = getpwuid(getuid()); 526 | 527 | if (pw) 528 | dir = pw->pw_dir; 529 | } 530 | 531 | return dir; 532 | } 533 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | {one line to give the program's name and a brief idea of what it does.} 635 | Copyright (C) {year} {name of author} 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | {project} Copyright (C) {year} {fullname} 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | --------------------------------------------------------------------------------