Created
May 13, 2019 18:42
-
-
Save nrocco/ea236998e74fcd5208f73ad3e26b9806 to your computer and use it in GitHub Desktop.
Notes system using fzf, rg, fd and vim
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#compdef notes | |
local line state | |
_arguments -C \ | |
"1:Command:(ls search edit rm help)" \ | |
"2:arg:->args" | |
if [[ "$state" == "args" ]] | |
then | |
case "$line[1]" in | |
edit|rm) | |
_alternative 'notes:fafa:($(notes ls | xargs))' | |
;; | |
help) | |
_message "Show help" | |
;; | |
ls) | |
_message "Optionally filter filenames" | |
;; | |
search) | |
_message "Search through your notes" | |
;; | |
esac | |
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
NOTES_DIR=${NOTES_DIR:=~/Documents/Notes} | |
case "$1" in | |
help) | |
echo "Usage: $(basename $0) ls|search|edit|rm|help" | |
;; | |
ls) | |
( | |
cd "${NOTES_DIR}" | |
exec fd --color never --type f "$2" | |
) | |
;; | |
search) | |
( | |
cd "${NOTES_DIR}" | |
exec rg -i "$2" | |
) | |
;; | |
edit) | |
( | |
cd "${NOTES_DIR}" | |
if [ -z "$2" ] | |
then | |
exec vim . | |
else | |
exec vim -c 'set ft=markdown' "$2" | |
fi | |
) | |
;; | |
rm) | |
( | |
cd "${NOTES_DIR}" | |
exec rm "$2" | |
) | |
;; | |
*) | |
( | |
cd "${NOTES_DIR}" | |
note="$(fzf --preview='head -100 {}')" | |
if [ ! -z "${note}" ] | |
then | |
exec notes edit "${note}" | |
fi | |
) | |
;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment