Skip to content

Commit 7eab4fb

Browse files
authored
Merge pull request #429 from srid/srid/issue428
Embed neuron-search script
2 parents f153775 + f366ac0 commit 7eab4fb

File tree

3 files changed

+24
-8
lines changed

3 files changed

+24
-8
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Change Log for neuron
22

3+
## 1.0.1.0
4+
5+
- Fix broken `neuron search` in static binary (#429)
6+
37
## 1.0.0.0
48

59
- Updates

neuron/neuron.cabal

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
cabal-version: 2.4
22
name: neuron
33
-- This version must be in sync with what's in Default.dhall
4-
version: 1.0.0.0
4+
version: 1.0.1.0
55
license: AGPL-3.0-only
66
copyright: 2020 Sridhar Ratnakumar
77
maintainer: srid@srid.ca
@@ -135,7 +135,6 @@ common app-common
135135
foldl,
136136
filepath,
137137
dhall >= 1.30,
138-
which,
139138
unix,
140139
megaparsec >= 8.0,
141140
dependent-sum >= 0.7,
@@ -146,7 +145,8 @@ common app-common
146145
with-utf8,
147146
shower,
148147
either,
149-
uri-encode
148+
uri-encode,
149+
temporary
150150

151151
-- Everything below will have to be stripped away, if whoever uses this repo
152152
-- will want to avoid non-core dependencies. Cabal doesn't seem to provide a way

neuron/src/app/Neuron/CLI/Search.hs

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ module Neuron.CLI.Search
1111
)
1212
where
1313

14+
import Data.FileEmbed (embedOneStringFileOf)
1415
import qualified Data.Text as Text
16+
import Data.Text.IO (hPutStr)
1517
import Development.Shake (Action)
1618
import Neuron.CLI.Rib
1719
( SearchBy (SearchByContent, SearchByTitle),
@@ -20,11 +22,13 @@ import Neuron.CLI.Rib
2022
import Neuron.Config.Type (Config, getZettelFormats)
2123
import Neuron.Reader.Type (ZettelFormat (ZettelFormat_Org), zettelFormatToExtension)
2224
import Relude
23-
import System.Posix.Process
24-
import System.Which
25+
import System.IO (hClose)
26+
import System.IO.Temp (withSystemTempFile)
27+
import System.Posix.Files (setFileMode)
28+
import System.Posix.Process (executeFile)
2529

26-
neuronSearchScript :: FilePath
27-
neuronSearchScript = $(staticWhich "neuron-search")
30+
searchScript :: Text
31+
searchScript = $(embedOneStringFileOf ["./src-bash/neuron-search", "./neuron/src-bash/neuron-search"])
2832

2933
searchScriptArgs :: (NonEmpty ZettelFormat) -> SearchCommand -> [String]
3034
searchScriptArgs formats SearchCommand {..} =
@@ -43,8 +47,16 @@ interactiveSearch notesDir searchCmd config =
4347
zettelFormats <- getZettelFormats config
4448
if searchBy searchCmd == SearchByTitle && ZettelFormat_Org `elem` toList zettelFormats
4549
then fail "search is not supported for .org files"
46-
else liftIO $ execScript neuronSearchScript $ notesDir : searchScriptArgs zettelFormats searchCmd
50+
else liftIO $ do
51+
asExecutableScript "neuron-search" searchScript $ \scriptFile -> do
52+
execScript scriptFile $ notesDir : searchScriptArgs zettelFormats searchCmd
4753
where
54+
asExecutableScript k s f =
55+
withSystemTempFile k $ \fp hdl -> do
56+
hPutStr hdl s
57+
hClose hdl
58+
setFileMode fp 0o700
59+
f fp
4860
execScript scriptPath args =
4961
-- We must use the low-level execvp (via the unix package's `executeFile`)
5062
-- here, such that the new process replaces the current one. fzf won't work

0 commit comments

Comments
 (0)