diff --git a/Cargo.lock b/Cargo.lock index 18750c8..d69b2f6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -418,7 +418,7 @@ dependencies = [ [[package]] name = "intelli-shell" -version = "0.2.4" +version = "0.2.5" dependencies = [ "anyhow", "clap", diff --git a/Cargo.toml b/Cargo.toml index 496f78a..6941515 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "intelli-shell" description = "Like IntelliSense, but for shells" -version = "0.2.4" +version = "0.2.5" edition = "2021" license = "Apache-2.0" readme = "README.md" diff --git a/install.ps1 b/install.ps1 index 0afaba7..715a07c 100755 --- a/install.ps1 +++ b/install.ps1 @@ -17,9 +17,10 @@ if (Test-Path -Path $Profile -PathType Leaf) { } if (($null -eq $ProfileContent) -Or ($ProfileContent -NotLike "*IntelliShell*")) { Add-Content $Profile "`n# IntelliShell" + Add-Content $Profile "`$env:INTELLI_HOME = `"`$env:APPDATA\IntelliShell\Intelli-Shell`"" Add-Content $Profile "# `$env:INTELLI_SEARCH_HOTKEY = 'Ctrl+Spacebar'" Add-Content $Profile "# `$env:INTELLI_BOOKMARK_HOTKEY = 'Ctrl+b'" Add-Content $Profile "# `$env:INTELLI_LABEL_HOTKEY = 'Ctrl+l'" - Add-Content $Profile ". `$env:APPDATA\IntelliShell\Intelli-Shell\bin\intelli-shell.ps1" + Add-Content $Profile ". `$env:INTELLI_HOME\bin\intelli-shell.ps1" } Write-Host "Close this terminal and open a new one for the changes to take effect" diff --git a/install.sh b/install.sh index 0d5a185..2982e31 100755 --- a/install.sh +++ b/install.sh @@ -9,7 +9,7 @@ case "$OSTYPE" in INTELLI_HOME="${INTELLI_HOME:-$HOME/.local/share/intelli-shell}" ;; darwin*) os="apple-darwin" - INTELLI_HOME="${INTELLI_HOME:-$HOME/Library/Application\ Support/org.IntelliShell.Intelli-Shell}" + INTELLI_HOME="${INTELLI_HOME:-$HOME/Library/Application Support/org.IntelliShell.Intelli-Shell}" ;; msys*) os="pc-windows-msvc" POSIX_APPDATA=$(echo "/$APPDATA" | sed 's/\\/\//g' | sed 's/://') @@ -22,8 +22,8 @@ esac target="$arch-$os" # Download latest release -mkdir -p $INTELLI_HOME/bin -curl -Lsf https://github.com/lasantosr/intelli-shell/releases/latest/download/intelli-shell-$target.tar.gz | tar zxf - -C $INTELLI_HOME/bin +mkdir -p "$INTELLI_HOME/bin" +curl -Lsf https://github.com/lasantosr/intelli-shell/releases/latest/download/intelli-shell-$target.tar.gz | tar zxf - -C "$INTELLI_HOME/bin" echo "Successfully installed IntelliShell at: $INTELLI_HOME" @@ -39,13 +39,13 @@ function update_rc () { then files+=("$1") echo -e '\n# IntelliShell' >> "$1" - echo "INTELLI_HOME=$INTELLI_HOME" >> "$1" + printf "export INTELLI_HOME=%q\n" "$INTELLI_HOME" >> "$1" echo '# export INTELLI_SEARCH_HOTKEY=\\C-@' >> "$1" echo '# export INTELLI_LABEL_HOTKEY=\\C-l' >> "$1" echo '# export INTELLI_BOOKMARK_HOTKEY=\\C-b' >> "$1" echo '# export INTELLI_SKIP_ESC_BIND=0' >> "$1" echo 'alias intelli-shell="$INTELLI_HOME/bin/intelli-shell"' >> "$1" - echo 'source $INTELLI_HOME/bin/intelli-shell.sh' >> "$1" + echo 'source "$INTELLI_HOME/bin/intelli-shell.sh"' >> "$1" fi } @@ -68,12 +68,12 @@ if [[ -f "/usr/bin/fish" ]]; then then files+=("$config") echo -e '\n# IntelliShell' >> "$config" - echo "set INTELLI_HOME $INTELLI_HOME" >> "$config" - echo '# set INTELLI_SEARCH_HOTKEY \cr' >> "$config" - echo '# set INTELLI_LABEL_HOTKEY \cl' >> "$config" - echo '# set INTELLI_BOOKMARK_HOTKEY \cb' >> "$config" - echo '# set INTELLI_SKIP_ESC_BIND 0' >> "$config" - echo 'source $INTELLI_HOME/bin/intelli-shell.fish' >> "$config" + printf "set -gx INTELLI_HOME %q\n" "$INTELLI_HOME" >> "$config" + echo '# set -gx INTELLI_SEARCH_HOTKEY \cr' >> "$config" + echo '# set -gx INTELLI_LABEL_HOTKEY \cl' >> "$config" + echo '# set -gx INTELLI_BOOKMARK_HOTKEY \cb' >> "$config" + echo '# set -gx INTELLI_SKIP_ESC_BIND 0' >> "$config" + echo 'source "$INTELLI_HOME/bin/intelli-shell.fish"' >> "$config" fi fi diff --git a/src/storage.rs b/src/storage.rs index f4b7a13..54bd9d4 100644 --- a/src/storage.rs +++ b/src/storage.rs @@ -1,6 +1,6 @@ use core::slice; use std::{ - fs, + env, fs, io::{BufRead, BufReader, BufWriter, Write}, sync::Mutex, }; @@ -58,10 +58,15 @@ pub struct SqliteStorage { impl SqliteStorage { /// Builds a new SQLite storage on the default path pub fn new() -> Result { - let path = ProjectDirs::from("org", "IntelliShell", "Intelli-Shell") - .context("Error initializing project dir")? - .data_dir() - .to_path_buf(); + let path = env::var_os("INTELLI_HOME") + .map(Into::into) + .map(anyhow::Ok) + .unwrap_or_else(|| { + Ok(ProjectDirs::from("org", "IntelliShell", "Intelli-Shell") + .context("Error initializing project dir")? + .data_dir() + .to_path_buf()) + })?; fs::create_dir_all(&path).context("Could't create data dir")?;