Skip to content

Commit

Permalink
Merge pull request #429 from srid/srid/issue428
Browse files Browse the repository at this point in the history
Embed neuron-search script
  • Loading branch information
srid authored Oct 9, 2020
2 parents f153775 + f366ac0 commit 7eab4fb
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 8 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
6 changes: 3 additions & 3 deletions neuron/neuron.cabal
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -135,7 +135,6 @@ common app-common
foldl,
filepath,
dhall >= 1.30,
which,
unix,
megaparsec >= 8.0,
dependent-sum >= 0.7,
Expand All @@ -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
Expand Down
22 changes: 17 additions & 5 deletions neuron/src/app/Neuron/CLI/Search.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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 {..} =
Expand All @@ -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
Expand Down

0 comments on commit 7eab4fb

Please sign in to comment.