From a87ac6b690fe6564f24e33bacb6ef8f1af68d914 Mon Sep 17 00:00:00 2001 From: Steven De Coeyer Date: Thu, 25 Feb 2021 05:14:49 +0100 Subject: [PATCH] Added macOS compatibility --- README.md | 26 ++++++++++++++++++++------ tuxi | 30 +++++++++++++++++++++++------- 2 files changed, 43 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 0c2a5b6..d4fa63c 100644 --- a/README.md +++ b/README.md @@ -1,17 +1,17 @@

TUXI

A CLI tool that scrapes Google search results and SERPs that provides instant and concise answers

-## +## Video Preview Gif ### How does this work? The script uses `pup` to scrape Google search results and SERPs. -If the query returns several results, Tuxi will choose the most +If the query returns several results, Tuxi will choose the most relevant result on the basis of priority. -In addition to scraping, `tuxi` also uses `jq`, `awk` and `sed` +In addition to scraping, `tuxi` also uses `jq`, `awk` and `sed` to process and return results, and `recode` to unescape html. @@ -24,6 +24,12 @@ to process and return results, and `recode` to unescape html. * [recode](https://github.com/rrthomas/recode) - Charset converter tool and library. * [jq](https://github.com/stedolan/jq) - Command-line JSON processor. +### macOS specific requirements + +* [gnu-sed](https://www.gnu.org/software/sed/) - sed (stream editor) is a non-interactive command-line text editor +* [coreutils](https://www.gnu.org/software/sed/) - GNU File, Shell, and Text utilities + + ## Installation ### cURL @@ -33,7 +39,7 @@ cURL **tuxi** to your **$PATH** and give execute permissions. $ sudo curl -sL "https://raw.githubusercontent.com/Bugswriter/tuxi/main/tuxi" -o /usr/local/bin/tuxi $ sudo chmod +x /usr/local/bin/tuxi ``` -> To update, just do `curl` again, no need to `chmod` anymore. +> To update, just do `curl` again, no need to `chmod` anymore. > To uninstall, simply remove `tuxi` from your **$PATH**, for example `sudo rm -f /usr/local/bin/tuxi`. ### Make @@ -41,7 +47,7 @@ $ sudo chmod +x /usr/local/bin/tuxi $ git clone https://github.com/Bugswriter/tuxi.git && cd tuxi/ $ sudo make install ``` -> To update, just `git pull` on your local tuxi repository and reinstall with `sudo make install`. +> To update, just `git pull` on your local tuxi repository and reinstall with `sudo make install`. > To uninstall, simply run `sudo make uninstall`. ### Arch Linux AUR @@ -50,6 +56,14 @@ Tuxi is available as the [`tuxi-git`](https://aur.archlinux.org/packages/tuxi-gi $ yay -S tuxi-git ``` +### macOS +Tuxi dependencies are available as [`brew`](https://brew.sh) Formulae. cURL **tuxi** to your **$PATH** and give execute permissions. +```sh +brew install pup recode gnu-sed coreutils +sudo curl -sL "https://raw.githubusercontent.com/Bugswriter/tuxi/main/tuxi" -o /usr/local/bin/tuxi +sudo chmod +x /usr/local/bin/tuxi +``` + ## Usage ```sh @@ -85,7 +99,7 @@ Report bugs at https://github.com/Bugswriter/tuxi/issues. ## Features -**Easily change query language** +**Easily change query language** Line [8](./tuxi#L8) in `tuxi` contains the language variable which can be changed according the user's preference. However, tuxi will use the system default langauge if none is set. **Gives corrections** diff --git a/tuxi b/tuxi index 860681e..6f00f1c 100755 --- a/tuxi +++ b/tuxi @@ -11,6 +11,22 @@ LANGUAGE="" ##### Functions ##### ############################### +sed () { + if [[ "$OSTYPE" == "darwin"* ]]; then + gsed "${@}" + else + sed "${@}" + fi +} + +paste() { + if [[ "$OSTYPE" == "darwin"* ]]; then + gpaste "${@}" + else + paste "${@}" + fi +} + help_text () { printf "%bUsage:%b tuxi %b[options]%b %bquery%b\n" "$G" "$N" "$Y" "$N" "$M" "$N" printf "\n" @@ -80,7 +96,7 @@ raw=false quiet=false # search result output format (changes if raw=true) -output() { +output() { printf "%b---%b\n%s\n%b---%b\n" "$G" "$N" "$*" "$G" "$N" } @@ -98,10 +114,10 @@ while getopts "hrq" OPT; do help_text exit 0 ;; - r) + r) raw=true ;; - q) + q) quiet=true ;; *) @@ -121,7 +137,7 @@ shift $((OPTIND-1)) if $raw; then N=""; R=""; G=""; Y=""; M=""; C=""; - output () { + output () { printf "%s\n" "$*" } fi @@ -136,11 +152,11 @@ fi if [ -z "$1" ]; then if [ $quiet = "false" ]; then printf "Hi, I'm Tuxi. Ask me anything!\n" - help_text | head -n 1 + help_text | head -n 1 fi exit 0 fi - + # Else, all arguments are saved in $query query="$*" @@ -152,7 +168,7 @@ query="$*" user_agent="Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:53.0) Gecko/20100101 Firefox/53.0" google_url="https://www.google.com/search?hl="${LANGUAGE:="${LANG:=en_US}"}"" -# Response from Google via cURL (-G: get, -s: silent) +# Response from Google via cURL (-G: get, -s: silent) google_html=$(curl -Gs --compressed "$google_url" --user-agent "$user_agent" --data-urlencode "q=$query")