summaryrefslogtreecommitdiff
path: root/.local/bin/cht.sh
blob: 02a570082777b2f81f2b82d9a56ffe1bf0cc44e8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#!/usr/bin/env bash


langs=("assembly" "awk" "bash" "basic" "bf" "chapel" "clojure" "coffee" "cpp" "c" "csharp" "d"
    "dart" "delphi" "elisp" "elixir" "elm" "erlang" "factor" "forth" "fortran" "fsharp" "git" "go"
    "groovy" "haskell" "java" "js" "julia" "kotlin" "latex" "lisp" "lua" "mathematica" "matlab"
    "mongo" "nim" "objective" "ocaml" "octave" "perl" "perl6" "php" "psql" "python" "python3"
    "r" "racket" "ruby" "rust" "solidity" "scala" "scheme" "psql" "sql" "swift" "tcl" "tcsh" "vb"
    "vbnet" "vim" "arduino" "pike" "eiffel" "clean" "dylan" "cmake" "django" "flask")

selected=$(printf '%s\n' "${langs[@]}" | fzf)
if [ -z $selected ]; then
    exit 0
fi

echo "Language: $selected"
read -p "Enter Query: " query

# To differentiate between blank, non-blank, empty, unset
# https://unix.stackexchange.com/a/147362
case ${query+x$query} in
  (x*[![:blank:]]*)
    query="/$(echo $query | tr ' ' '+')";;
    # curl -s cht.sh/$selected/$query && while [ : ]; do sleep 1; done || echo "failed to search on cht.sh";;
    # echo \"curl cht.sh/$selected/$query\"
    # curl -s cht.sh/$selected/$query
    # while [ : ]; do sleep 1; done;;
  (*);;
    # keep the variable empty
    # curl -s cht.sh/$selected;;
esac

echo "curl cht.sh/$selected$query:"
echo ""
curl -s cht.sh/$selected$query | less