Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#!/usr/bin/env bash
set -e
main() {
previous_file="$1"
file_to_edit=`select_file $previous_file`
if [ -n "$file_to_edit" ] ; then
"$EDITOR" "$file_to_edit"
main "$file_to_edit"
fi
}
select_file() {
given_file="$1"
fzf --preview="cat {}" --preview-window=right:70%:wrap --query="$given_file"
}
main ""
@BaseCase

This comment has been minimized.

Copy link
Owner Author

@BaseCase BaseCase commented Sep 19, 2017

My little note-taking thing using fzf. Here's a blog post where I explain it.

@echorebel

This comment has been minimized.

Copy link

@echorebel echorebel commented Jan 23, 2019

cool

@dofinn

This comment has been minimized.

Copy link

@dofinn dofinn commented Mar 13, 2019

#!/usr/bin/env bash
set -e

main() {
  cd $HOME/notes
  previous_file="$1"
  file_to_edit=`select_file $previous_file`

  if [ -n "$file_to_edit" ] ; then
    "$EDITOR" "$file_to_edit"
    main "$file_to_edit"
  fi
  cd -
}

select_file() {
  given_file="$1"
  fzf --preview="cat {}" --preview-window=right:70%:wrap --query="$given_file"
}

main ""

Add the two CD commands to wrap around the main func so you could call this from anywhere and have fzf only ever index the $HOME/notes dir

@alichtman

This comment has been minimized.

Copy link

@alichtman alichtman commented Jul 25, 2019

I added in-script file creation.

#!/usr/bin/env bash
# Modified from https://gist.github.com/BaseCase/c45299e4f8474119881d708a4b728fbf
# by Aaron Lichtman -- https://github.com/alichtman

# notes.sh
#
# A script for quickly editing your notes. Allows creation of new files by
# selecting CREATE_NEW_FILE at the menu. Depends on the $NOTES environment
# variable being set.

set -e

new_file_creation_option="CREATE_NEW_FILE"

main() {
	cd "$NOTES"
	touch "$new_file_creation_option"
	previous_file="$1"
	file_to_edit=$(select_file "$previous_file")

	if [ -n "$file_to_edit" ] ; then
	  if [ "$file_to_edit" == "$new_file_creation_option" ] ; then
		  read -p "Enter a new file name: " file_to_edit
		  touch_create_parent "$file_to_edit"
	  fi
	rm "$new_file_creation_option"
	"$EDITOR" "$file_to_edit"
	main "$file_to_edit"
	fi
	cd -
}

touch_create_parent() {
	mkdir -p "$(dirname "$1")" && touch "$1"
}

select_file() {
	given_file="$1"
	fzf --preview="cat {}" --preview-window=right:70%:wrap --query="$given_file"
}

# Hook SIGINT to clean up
trap cleanup EXIT INT TERM

function cleanup () {
	rm "$new_file_creation_option"
}

main ""
@BaseCase

This comment has been minimized.

Copy link
Owner Author

@BaseCase BaseCase commented Jul 25, 2019

I added in-script file creation.

@alichtman awesome! :)

Also awesome is that apparently GitHub now includes Gist comments in its Notification page, which I think is new.

@alichtman

This comment has been minimized.

Copy link

@alichtman alichtman commented Nov 12, 2019

https://github.com/alichtman/fzf-notes

I've fleshed this out into a more complete note taking tool and thought I'd share. It now supports multiple notebooks.

@BaseCase

This comment has been minimized.

Copy link
Owner Author

@BaseCase BaseCase commented Nov 13, 2019

Hey @alichtman that's really cool! I'll have to pull down your tool and try it out later today :)

@kutacoder

This comment has been minimized.

Copy link

@kutacoder kutacoder commented Mar 2, 2021

Thanks to this amazing idea, I created this small script to manage notes in the Zettelkasten method, using fzf, the silver searcher and bat.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment