Skip to content

Instantly share code, notes, and snippets.

@nicholasrq
Last active March 16, 2016 13:13
Show Gist options
  • Save nicholasrq/f2da0281e102144af3c3 to your computer and use it in GitHub Desktop.
Save nicholasrq/f2da0281e102144af3c3 to your computer and use it in GitHub Desktop.
Tool to control your LTSearch instances

INSTALLATION

Automatic

Run command:

curl https://gist.githubusercontent.com/nicholasrq/f2da0281e102144af3c3/raw/install | sh

Manual

  • Create bin/ directory in your home dir if not exists
  • Add ~/bin/ to your $PATH using export PATH=/$HOME/bin:$PATH in .bashrc or .zshrc
  • Copy file above to your bin directory and grant execution rights using chmod +x lt-search
  • Run source . or exec $SHELL to reload your session

Also you may need to configure right paths to your Ruby and Go versions of lt-search

USAGE

Usage is slightly simple lt-search [command[, options]]

command description
lt-search start start both Ruby and GO search
lt-search stop stop both Ruby and GO search
lt-search restart restart both Ruby and GO search
`lt-search pid [ruby go]`
lt-search upgrade initiate self-upgrade for ~/bin/lt-searchche
`lt-search status [ruby go]`
`lt-search show [ruby go]`
#!/bin/sh
echo "Installing lt-search command"
url="https://gist.githubusercontent.com/nicholasrq/f2da0281e102144af3c3/raw/lt-search"
content=$(curl -s $url)
bin_dir="$HOME/bin"
file_path="$bin_dir/lt-search"
dir_exists=$(test -d $bin_dir && echo true)
path_exists=$(echo $PATH | grep $bin_dir && echo true)
if [[ $dir_exists != true ]]; then
echo "Creating $bin_dir"
mkdir $bin_dir
else
echo "Directory $bin_dir exists. Skipping step"
fi
if [[ $dir_exists != true ]]; then
echo "Adding $bin_dir to \$PATH"
if [[ -f "$HOME/.zshrc" ]]; then
startup_file="$HOME/.zshrc"
elif [[ -f "$HOME/.bashrc" ]]; then
startup_file="$HOME/.bashrc"
else
echo "Can't find valid startup file"
exit 1
fi
echo "export PATH=$bin_dir:\$PATH" >> $file_path
else
echo "Directory $bin_dir already in \$PATH. Skipping step"
fi
if [[ -e $file_path ]]; then
echo "File lt-search exists in $bin_dir"
md_new=$(printf "$content" | md5)
md_old=$(printf "$(cat $file_path)" | md5)
if [[ $md_new != $md_old ]]; then
echo "Updated to last version"
printf "$content" > $file_path
else
echo "File is up to date"
fi
else
echo "Added lt-search as $file_path"
printf "$content" > $file_path
fi
if [[ -x $file_path ]]; then
echo "File is already executable"
else
echo "Granting execution permissions"
chmod +x $file_path
fi
echo "Done"
exec $SHELL
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment