diff --git a/CHANGELOG.md b/CHANGELOG.md index e4de39bb2..d8a0b28cf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Change Log for neuron +## 1.0.1.0 + +- Fix broken `neuron search` in static binary (#429) + ## 1.0.0.0 - Updates diff --git a/neuron/neuron.cabal b/neuron/neuron.cabal index 13e2fd0b2..3c85b63fb 100644 --- a/neuron/neuron.cabal +++ b/neuron/neuron.cabal @@ -1,7 +1,7 @@ cabal-version: 2.4 name: neuron -- This version must be in sync with what's in Default.dhall -version: 1.0.0.0 +version: 1.0.1.0 license: AGPL-3.0-only copyright: 2020 Sridhar Ratnakumar maintainer: srid@srid.ca @@ -135,7 +135,6 @@ common app-common foldl, filepath, dhall >= 1.30, - which, unix, megaparsec >= 8.0, dependent-sum >= 0.7, @@ -146,7 +145,8 @@ common app-common with-utf8, shower, either, - uri-encode + uri-encode, + temporary -- Everything below will have to be stripped away, if whoever uses this repo -- will want to avoid non-core dependencies. Cabal doesn't seem to provide a way diff --git a/neuron/src/app/Neuron/CLI/Search.hs b/neuron/src/app/Neuron/CLI/Search.hs index ef82c83a2..802e2b1c4 100644 --- a/neuron/src/app/Neuron/CLI/Search.hs +++ b/neuron/src/app/Neuron/CLI/Search.hs @@ -11,7 +11,9 @@ module Neuron.CLI.Search ) where +import Data.FileEmbed (embedOneStringFileOf) import qualified Data.Text as Text +import Data.Text.IO (hPutStr) import Development.Shake (Action) import Neuron.CLI.Rib ( SearchBy (SearchByContent, SearchByTitle), @@ -20,11 +22,13 @@ import Neuron.CLI.Rib import Neuron.Config.Type (Config, getZettelFormats) import Neuron.Reader.Type (ZettelFormat (ZettelFormat_Org), zettelFormatToExtension) import Relude -import System.Posix.Process -import System.Which +import System.IO (hClose) +import System.IO.Temp (withSystemTempFile) +import System.Posix.Files (setFileMode) +import System.Posix.Process (executeFile) -neuronSearchScript :: FilePath -neuronSearchScript = $(staticWhich "neuron-search") +searchScript :: Text +searchScript = $(embedOneStringFileOf ["./src-bash/neuron-search", "./neuron/src-bash/neuron-search"]) searchScriptArgs :: (NonEmpty ZettelFormat) -> SearchCommand -> [String] searchScriptArgs formats SearchCommand {..} = @@ -43,8 +47,16 @@ interactiveSearch notesDir searchCmd config = zettelFormats <- getZettelFormats config if searchBy searchCmd == SearchByTitle && ZettelFormat_Org `elem` toList zettelFormats then fail "search is not supported for .org files" - else liftIO $ execScript neuronSearchScript $ notesDir : searchScriptArgs zettelFormats searchCmd + else liftIO $ do + asExecutableScript "neuron-search" searchScript $ \scriptFile -> do + execScript scriptFile $ notesDir : searchScriptArgs zettelFormats searchCmd where + asExecutableScript k s f = + withSystemTempFile k $ \fp hdl -> do + hPutStr hdl s + hClose hdl + setFileMode fp 0o700 + f fp execScript scriptPath args = -- We must use the low-level execvp (via the unix package's `executeFile`) -- here, such that the new process replaces the current one. fzf won't work