Last active
October 10, 2024 11:03
-
-
Save do-me/f6e9ef4b9d6932c60a462da5513e6d79 to your computer and use it in GitHub Desktop.
personal wiki with bash & zsh, searches a directory with .txt files. includes command for new note
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
wiki() { | |
# Combine arguments into a single string for multi-word search | |
search_string="$*" | |
# Perform case-insensitive grep search with the combined string | |
grep -Hni --color=always "$search_string" /Users/dome/work/wikifiles/*.txt | awk -F':' ' | |
BEGIN { | |
prevfile="" | |
} | |
{ | |
if ($1 != prevfile) { | |
print "\033[1;34m==============================\033[0m" # Blue separator line | |
print "\033[1;36mπ File: \033[0m" $1 # File name in cyan | |
} | |
# Ensure only the first two fields (filename and line number) are split by colon | |
print " \033[1;33mβ Line "$2":\033[0m " substr($0, index($0,$3)) # Print line content starting from $3 to avoid cutting URLs | |
prevfile=$1 | |
}' | |
} | |
note() { | |
# Get the current date and time in the format YYYY-MM-DD_HH-MM-SS | |
local timestamp=$(date +"%Y-%m-%d_%H-%M-%S") | |
# Define the directory where the note should be created | |
local directory="/Users/dome/work/wikifiles" | |
# Define the note filename with the timestamp and full path | |
local filepath="${directory}/${timestamp}.txt" | |
# Create the new file and open it with micro editor | |
touch "$filepath" && micro "$filepath" | |
} | |
# usage & example results | |
(base) β ~ note # opens micro editor for new note, can be replaced with vim or nano | |
(base) β ~ wiki pandoc # search results | |
============================== | |
π File: /Users/dome/work/wikifiles/Pandoc HTML to markdown.txt | |
β Line 1: pandoc input.html -t gfm -o output.md | |
============================== | |
π File: /Users/dome/work/wikifiles/Pandoc Word to Markdown.txt | |
β Line 1: pandoc -s hll.docx --reference-links -t markdown -o hll.md | |
============================== | |
π File: /Users/dome/work/wikifiles/markdown regex replace.txt | |
β Line 19: 1. mit pandoc zu md | |
β Line 24: siehe auch pandoc wiki file |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For zsh shell. Add the function to
~/.zshrc
and update the shell withsource ~/.zshrc
.Results are nicely formatted with colors and clickable with the mouse when pressing CTRL