Skip to content

Commit

Permalink
feat: add install script for bash
Browse files Browse the repository at this point in the history
  • Loading branch information
linhx committed Nov 16, 2022
1 parent 12a7db2 commit 6b6568c
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 6 deletions.
4 changes: 2 additions & 2 deletions bookmark/bookmark.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package bookmark

import (
"fmt"
"os"
"strconv"

common "linhx.com/tbmk/common"
Expand Down Expand Up @@ -39,7 +40,7 @@ type BookmarkRepo struct {

func NewBookmarkRepo() (*BookmarkRepo, error) {
repo := new(BookmarkRepo)
driver, err := simdb.New("data")
driver, err := simdb.New(os.Getenv("TBMK_DATA_DIR"))
repo.db = driver
return repo, err
}
Expand All @@ -50,7 +51,6 @@ func (repo *BookmarkRepo) createNewBookmarkItemId() (int, error) {
if err == simdb.ErrRecordNotFound {
increment = Increment{Name: "BookmarkItem", Index: 0}
err = repo.db.Insert(increment)
fmt.Print(increment.ID())
}
if err != nil {
return 0, fmt.Errorf("Can't create new ID")
Expand Down
12 changes: 12 additions & 0 deletions install
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
DATA_DIR="$HOME/.tbmk"
APP_DIR=$(pwd)

SCRIPT_KEYBINDING="$APP_DIR/key-bindings.bash"

if ! grep -Fqxe "export TBMK=${APP_DIR}/tbmk" ~/.bashrc ; then
printf "export TBMK='${APP_DIR}/tbmk'\n" >> ~/.bashrc
printf "export TBMK_DATA_DIR='${DATA_DIR}'\n" >> ~/.bashrc
printf "if [ -f '$SCRIPT_KEYBINDING' ]; then\n" >> ~/.bashrc
printf " . '$SCRIPT_KEYBINDING'\n" >> ~/.bashrc
printf "fi\n" >> ~/.bashrc
fi
6 changes: 3 additions & 3 deletions key-bindings.bash
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ __tbmk_save__() {
READLINE_POINT=0

command=$(echo "${READLINE_LINE:0}" | grep -oE '(.)+$')
./tbmk save -command="$command"
$TBMK save -command="$command"
}

__tbmk_search__() {
Expand All @@ -12,8 +12,8 @@ __tbmk_search__() {

local output
query=$(echo "${READLINE_LINE:0}" | grep -oE '(.)+$')
output=$(./tbmk search -query="$query")
READLINE_LINE=${output#*$'\t'}
output=$($TBMK search -query="$query")
READLINE_LINE=${output}
if [[ -z "$READLINE_POINT" ]]; then
echo "$READLINE_LINE"
else
Expand Down
2 changes: 1 addition & 1 deletion views/search/search_view.go
Original file line number Diff line number Diff line change
Expand Up @@ -279,5 +279,5 @@ func (m Model) View() string {
matchesContent += line + "\n"
}
}
return m.queryInput.View() + "\n" + matchesContent + "\n" + strconv.Itoa(m.firstIndex) + " " + strconv.Itoa(m.lastIndex)
return m.queryInput.View() + "\n" + matchesContent
}

0 comments on commit 6b6568c

Please sign in to comment.