Last active
June 20, 2025 12:40
-
-
Save francisrstokes/7df4da6650ab2c45ff07f5d41b475a61 to your computer and use it in GitHub Desktop.
Non-typical applications of fzf
This file contains hidden or 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
# A TODO repl where hitting enter toggles the status of the task, alt+a adds a task (with text from the query), and alt+d deletes the selected task | |
# Assuming todo_file is a document that looks something like this: | |
# - [ ] Task 1 | |
# - [x] Task 2 | |
# - [ ] Task 3 | |
# - [ ] Subtask 1 | |
# etc | |
#!/bin/bash | |
TODO_FILE="${TODO_FILE:-/home/francis/.todo.md}" | |
touch $TODO_FILE | |
help_text="[enter] Toggle task state\n[alt-a] Add task (from query)\n[alt-d] Delete task\n[alt-p] Indent +\n[alt-o] Indent -\n[alt-i] Move up\n[alt-k] Move down" | |
cat -n $TODO_FILE | sed -E 's/\s*([0-9]+)\s(.+)/\1::\2/' | fzf \ | |
--layout reverse-list \ | |
--delimiter '::' \ | |
--list-label 'TODO List' \ | |
--preview "echo '$help_text'" \ | |
--with-nth '{2..}' \ | |
--bind "enter:execute-silent(sed -Ei '{1}s/(.+?)\[ \]/\1__CHECK__/; {1}s/(.+?)\[x\]/\1[ ]/; {1}s/(.+?)__CHECK__/\1[x]/' $TODO_FILE)+reload(cat -n $TODO_FILE | sed -E 's/\s*([0-9]+)\s(.+)/\1::\2/')+clear-query" \ | |
--bind "alt-a:execute-silent(echo '- [ ] {q}' >> $TODO_FILE)+reload(cat -n $TODO_FILE | sed -E 's/\s*([0-9]+)\s(.+)/\1::\2/')+clear-query" \ | |
--bind "alt-d:execute-silent(sed -i '{1}d' $TODO_FILE)+reload(cat -n $TODO_FILE | sed -E 's/\s*([0-9]+)\s(.+)/\1::\2/')+clear-query" \ | |
--bind "alt-p:execute-silent(sed -Ei '{1}s/(.+)/ \1/' $TODO_FILE)+reload(cat -n $TODO_FILE | sed -E 's/\s*([0-9]+)\s(.+)/\1::\2/')" \ | |
--bind "alt-o:execute-silent(sed -Ei '{1}s/ (.+)/\1/' $TODO_FILE)+reload(cat -n $TODO_FILE | sed -E 's/\s*([0-9]+)\s(.+)/\1::\2/')" \ | |
--bind "alt-i:execute-silent(bash -c 'sed -i \"\$((\$1 - 1)){h;d}; \$1{G}\" $TODO_FILE' _ {1})+reload(cat -n $TODO_FILE | sed -E 's/\s*([0-9]+)\s(.+)/\1::\2/')" \ | |
--bind "alt-k:execute-silent(bash -c 'sed -i \"\$1{h;d}; \$((\$1 + 1)){G}\" $TODO_FILE' _ {1})+reload(cat -n $TODO_FILE | sed -E 's/\s*([0-9]+)\s(.+)/\1::\2/')" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Interactive JQ repl, but only executes query when pressing enter