Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added macOS compatibility #149

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 20 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
<h1 align="center">TUXI</h1>
<p align="center">A CLI tool that scrapes Google search results and SERPs that provides instant and concise answers</p>

##
##

<img src="https://i.ibb.co/sCwYpZ8/general.gif" alt="Video Preview Gif" align="right" width="500px"/>

### 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.


Expand All @@ -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
Expand All @@ -33,15 +39,15 @@ 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
```sh
$ 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
Expand All @@ -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
Expand Down Expand Up @@ -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**
Expand Down
30 changes: 23 additions & 7 deletions tuxi
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
}

Expand All @@ -98,10 +114,10 @@ while getopts "hrq" OPT; do
help_text
exit 0
;;
r)
r)
raw=true
;;
q)
q)
quiet=true
;;
*)
Expand All @@ -121,7 +137,7 @@ shift $((OPTIND-1))
if $raw; then
N=""; R=""; G=""; Y=""; M=""; C="";

output () {
output () {
printf "%s\n" "$*"
}
fi
Expand All @@ -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="$*"

Expand All @@ -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")


Expand Down