diff --git a/Makefile b/Makefile index 5b4ff8a..0a86aa2 100644 --- a/Makefile +++ b/Makefile @@ -11,7 +11,7 @@ build: submodules bin/resh-session-init bin/resh-collect bin/resh-postcollect bi install: build conf/config-dev.toml scripts/install.sh # Dev config - cp -f conf/config-dev.toml ~/.config/resh.toml + # cp -f conf/config-dev.toml ~/.config/resh.toml test_go: # Running tests diff --git a/cmd/control/cmd/update.go b/cmd/control/cmd/update.go index 788c6e2..4f7cc3f 100644 --- a/cmd/control/cmd/update.go +++ b/cmd/control/cmd/update.go @@ -3,6 +3,8 @@ package cmd import ( "os" "os/exec" + "os/user" + "path/filepath" "github.com/curusarn/resh/cmd/control/status" "github.com/spf13/cobra" @@ -12,8 +14,10 @@ var updateCmd = &cobra.Command{ Use: "update", Short: "check for updates and update RESH", Run: func(cmd *cobra.Command, args []string) { - url := "https://raw.githubusercontent.com/curusarn/resh/master/scripts/rawinstall.sh" - execCmd := exec.Command("bash", "-c", "curl -fsSL "+url+" | bash") + usr, _ := user.Current() + dir := usr.HomeDir + rawinstallPath := filepath.Join(dir, ".resh/rawinstall.sh") + execCmd := exec.Command("bash", rawinstallPath) execCmd.Stdout = os.Stdout execCmd.Stderr = os.Stderr err := execCmd.Run() diff --git a/scripts/install.sh b/scripts/install.sh index 1adf8cb..af75226 100755 --- a/scripts/install.sh +++ b/scripts/install.sh @@ -114,21 +114,7 @@ cp -f submodules/bash-zsh-compat-widgets/bindfunc.sh ~/.resh/bindfunc.sh cp -f scripts/shellrc.sh ~/.resh/shellrc cp -f scripts/reshctl.sh scripts/widgets.sh scripts/hooks.sh scripts/util.sh ~/.resh/ - -# hotfix to not overwrite enabled ctrl+R binding in config -bindcontrolr=0 -if [ "$(bin/resh-config -key bindcontrolr)" = true ]; then - # control_R binding is enabled - bindcontrolr=1 -fi - -cp -f conf/config.toml ~/.config/resh.toml - -# hotfix part2 (ctrl+R) -if [ "$bindcontrolr" = 1 ]; then - # reenable ctrl+R binding if it was enabled before - bin/resh-control enable ctrl_r_binding_global >/dev/null 2>/dev/null -fi +cp -f scripts/rawinstall.sh ~/.resh/ echo "Generating completions ..." bin/resh-control completion bash > ~/.resh/bash_completion.d/_reshctl @@ -143,6 +129,27 @@ cp -fr data/sanitizer ~/.resh/sanitizer_data # backward compatibility: We have a new location for resh history file [ ! -f ~/.resh/history.json ] || mv ~/.resh/history.json ~/.resh_history.json +update_config() { + version=$1 + key=$2 + value=$3 + # TODO: create bin/semver-lt + if bin/semver-lt "${__RESH_VERSION:-0.0.0}" "$1" && [ "$(bin/resh-config -key $key)" != "$value" ] ; then + echo " * config option $key was updated to $value" + # TODO: enable resh-config value setting + # resh-config -key "$key" -value "$value" + fi +} + +# Do not overwrite if exists +if [ ! -f ~/.config/resh.toml ]; then + cp conf/config.toml ~/.config/resh.toml +# else + # echo "Merging config files ..." + # NOTE: This is where we will merge configs when we make changes to the upstream config + # HINT: check which version are we updating FROM and make changes to config based on that +fi + echo "Finishing up ..." # Adding resh shellrc to .bashrc ... if [ ! -f ~/.bashrc ]; then diff --git a/scripts/rawinstall.sh b/scripts/rawinstall.sh index d6c2f73..d6816eb 100755 --- a/scripts/rawinstall.sh +++ b/scripts/rawinstall.sh @@ -34,7 +34,7 @@ version="${tag:1}" echo " * Latest version: $version (git tag: $tag)" # TODO: compare semanitcally instead of just using equality -if [ "${__RESH_VERSION-}" == "$version" ]; then +if [ "${__RESH_VERSION:-}" == "$version" ]; then echo " * Resh is up to date - nothing to do - exiting." exit 0 fi