diff --git a/Makefile b/Makefile index 9119cac..17bcf90 100644 --- a/Makefile +++ b/Makefile @@ -5,24 +5,47 @@ build: submodules resh-collect resh-daemon install: build | $(HOME)/.resh $(HOME)/.resh/bin $(HOME)/.config $(HOME)/.resh/resh-uuid + # Copying files to resh directory ... cp -f submodules/bash-preexec/bash-preexec.sh ~/.bash-preexec.sh cp -f config.toml ~/.config/resh.toml cp -f shellrc.sh ~/.resh/shellrc cp -f uuid.sh ~/.resh/bin/resh-uuid cp -f resh-* ~/.resh/bin/ - [ ! -f ~/resh-history.json ] || mv ~/resh-history.json ~/.resh/history.json + # backward compatibility: We have a new location for resh history file + [ ! -f ~/.resh/history.json ] || mv ~/.resh/history.json ~/.resh_history.json + # Adding resh shellrc to .bashrc ... grep '[[ -f ~/.resh/shellrc ]] && source ~/.resh/shellrc' ~/.bashrc ||\ echo '[[ -f ~/.resh/shellrc ]] && source ~/.resh/shellrc' >> ~/.bashrc + # Adding bash-preexec to .bashrc ... grep '[[ -f ~/.bash-preexec.sh ]] && source ~/.bash-preexec.sh' ~/.bashrc ||\ echo '[[ -f ~/.bash-preexec.sh ]] && source ~/.bash-preexec.sh' >> ~/.bashrc + # Adding resh shellrc to .zshrc ... grep '[ -f ~/.resh/shellrc ] && source ~/.resh/shellrc' ~/.zshrc ||\ echo '[ -f ~/.resh/shellrc ] && source ~/.resh/shellrc' >> ~/.zshrc + # Restarting resh daemon ... [ ! -f ~/.resh/resh.pid ] || kill -SIGTERM $$(cat ~/.resh/resh.pid) nohup resh-daemon &>/dev/null & disown + # + ########################################################## + # # + # SUCCESS - thank you for trying out this project! # + # # + ########################################################## + # + # WHAT'S NEXT + # Please close all open terminal windows (or reload your rc files) + # Your resh history is located in `~/.resh_history.json` + # You can look at it using e.g. `tail -f ~/.resh_history.json | jq` + # + # ISSUES + # If anything looks broken create an issue: https://github.com/curusarn/resh/issues + # You can uninstall this at any time by running `rm -rf ~/.resh/` + # You won't lose any collected history by removing `~/.resh` directory + # uninstall: - -mv ~/.resh/history.json ~/resh-history.json - -rm -rf ~/.resh + # Uninstalling ... + -rm -rf ~/.resh/ resh-daemon: daemon/resh-daemon.go common/resh-common.go go build -o $@ $< @@ -32,9 +55,11 @@ resh-collect: collect/resh-collect.go common/resh-common.go $(HOME)/.resh $(HOME)/.resh/bin $(HOME)/.config: + # Creating dirs ... mkdir -p $@ $(HOME)/.resh/resh-uuid: + # Generating random uuid for this device ... cat /proc/sys/kernel/random/uuid > $@ 2>/dev/null || ./uuid.sh .PHONY: submodules build install @@ -44,13 +69,14 @@ submodules: | submodules/bash-preexec/bash-preexec.sh @# sets submodule.recurse to true if unset @# sets status.submoduleSummary to true if unset @git config --get submodule.recurse >/dev/null || git config --global submodule.recurse true - @git config --get status.submoduleSummary >/dev/null || git config --global status.submoduleSummary true - @git config --get diff.submodule >/dev/null || git config --global diff.submodule log + @#git config --get status.submoduleSummary >/dev/null || git config --global status.submoduleSummary true + @#git config --get diff.submodule >/dev/null || git config --global diff.submodule log @# warns user if submodule.recurse is not set to true @[[ "true" == `git config --get submodule.recurse` ]] || echo "WARN: You should REALLY set 'git config --global submodule.recurse true'!" @#git config --global push.recurseSubmodules check submodules/%: + # Getting submodules ... git submodule sync --recursive git submodule update --init --recursive diff --git a/daemon/resh-daemon.go b/daemon/resh-daemon.go index 895cd9b..78eb310 100644 --- a/daemon/resh-daemon.go +++ b/daemon/resh-daemon.go @@ -21,7 +21,7 @@ func main() { dir := usr.HomeDir pidfilePath := filepath.Join(dir, ".resh/resh.pid") configPath := filepath.Join(dir, ".config/resh.toml") - outputPath := filepath.Join(dir, ".resh/history.json") + outputPath := filepath.Join(dir, ".resh_history.json") logPath := filepath.Join(dir, ".resh/daemon.log") f, err := os.OpenFile(logPath, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0644) diff --git a/go.mod b/go.mod index c17322a..86da97e 100644 --- a/go.mod +++ b/go.mod @@ -2,4 +2,4 @@ module github.com/curusarn/resh go 1.12 -require github.com/BurntSushi/toml v0.3.1 // indirect +require github.com/BurntSushi/toml v0.3.1 diff --git a/install.sh b/install.sh new file mode 100755 index 0000000..7de3907 --- /dev/null +++ b/install.sh @@ -0,0 +1,40 @@ +#!/usr/bin/env bash + +if ! go version 2>/dev/null; then + echo "Please install Golang and rerun this script" + exit 1 +fi + +go_version=$(go version | cut -d' ' -f3) +go_version_major=$(echo ${go_version:2} | cut -d'.' -f1) +go_version_minor=$(echo ${go_version:2} | cut -d'.' -f2) + +if [ "$go_version_major" -gt 1 ]; then + # good to go - future proof ;) + echo "Building & installing ..." + make install +elif [ "$go_version_major" -eq 1 ] && [ "$go_version_minor" -ge 11 ]; then + # good to go - we have go modules + echo "Building & installing ..." + make install +elif dep version >/dev/null; then + if ! dep init; then + echo "`dep init` failed - bootstraping GOPATH ..." + export GOPATH=/tmp/gopath + project_path=$GOPATH/src/github.com/curusarn/resh + mkdir -p $project_path + cp -rf . $project_path + cd $project_path + if ! dep init; then + echo "Unexpected ERROR while running `dep init`!" + echo "Try fixing it yourself - I'm sorry :(" + exit 3 + fi + echo "Succesfuly bootstraped GOPATH" + fi + echo "Building & installing ..." + make install +else + echo "Please install dep and rerun this script" + exit 2 +fi