From 96b32441b4f3dd952ad6ffc78e8852d3e8e64b87 Mon Sep 17 00:00:00 2001 From: fogine <7884288+fogine@users.noreply.github.com> Date: Thu, 28 May 2020 21:14:32 +0200 Subject: [PATCH] feature/custom browser command, resolves #4 --- README.md | 4 +++- rofi-search | 11 +++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index fea9f66..3496346 100644 --- a/README.md +++ b/README.md @@ -46,7 +46,7 @@ You can even let `rofi-search` combine search results from multiple search engin so this information is not currently available when using this method - Use google's custom search engine API by setting `GOOGLE_API_KEY` & `GOOGLE_SEARCH_ID` env variables - - It can Search the entire web if you set enable it in settings + - It can Search the entire web if you enable it in settings - You will need to go to [https://cse.google.com/cse/all](https://cse.google.com/cse/all) and create your own google custom search engine. - Get `Search engine ID` from the settings panel ![Preview](https://github.com/fogine/rofi-search/blob/master/search_engine_key.png) @@ -103,6 +103,8 @@ Options This can't be set in rofi theme - `ROFI_SEARCH_TIMEOUT` - integer - delay between last character typed and automatic search execution (default `500`ms) - `ROFI_SEARCH_DEBUG` - enables verbose logging if set to any value +- `ROFI_SEARCH_CMD` - a command to execute when pressing `-kb-accept-entry` (`enter`) - defaults to `xdg-open` + - example: `export ROFI_SEARCH_CMD='google-chrome $URL'` ##### supported rofi actions diff --git a/rofi-search b/rofi-search index b12cb32..c983315 100755 --- a/rofi-search +++ b/rofi-search @@ -15,6 +15,7 @@ const $HOME = process.env.HOME; const $XDG_CACHE_HOME = process.env.XDG_CACHE_HOME; const TITLE_COLOR = process.env.TITLE_COLOR || '#3296c8'; const ROFI_SEARCH_TIMEOUT = parseInt(process.env.ROFI_SEARCH_TIMEOUT) || 500; +const ROFI_SEARCH_CMD = process.env.ROFI_SEARCH_CMD; const CACHE_DIR_PATH = ($XDG_CACHE_HOME || ($HOME + "/.cache")) + '/' + APP_NAME; const CACHE_FILE_PATH = `${CACHE_DIR_PATH}/last_search.json`; @@ -674,8 +675,14 @@ function getPreferedSearchMethods() { * @return stdout */ function xdgOpen(url) { - const xdgOpen = child_process.spawn('xdg-open', [url]); - xdgOpen.on('close', exit); + if (ROFI_SEARCH_CMD) { + child_process.exec(ROFI_SEARCH_CMD, { + env: Object.assign({URL: url}, process.env) + }, exit); + } else { + const xdgOpen = child_process.spawn('xdg-open', [url]); + xdgOpen.on('close', exit); + } } function exit() {