From 03ac9fbfd028f4a447dbf9bb875805d9928fa3d6 Mon Sep 17 00:00:00 2001 From: JakeGinesin Date: Wed, 30 Apr 2025 16:25:38 -0400 Subject: [PATCH] 44 current 2025-04-30 16:25:32 25.05.20250424.f771eb4 6.12.24 * --- home/programs/nf/default.nix | 11 ++ home/programs/programs.nix | 1 + home/programs/rofi/styles/prompt-search.rasi | 91 ++++++++++ home/scripts/journal/nf.sh | 165 +++++++++++++++++++ 4 files changed, 268 insertions(+) create mode 100644 home/programs/nf/default.nix create mode 100644 home/programs/rofi/styles/prompt-search.rasi create mode 100644 home/scripts/journal/nf.sh diff --git a/home/programs/nf/default.nix b/home/programs/nf/default.nix new file mode 100644 index 0000000..ecd90ac --- /dev/null +++ b/home/programs/nf/default.nix @@ -0,0 +1,11 @@ +{ + config, + pkgs, + lib, + ... +}: { + home.activation.makeNfDir = lib.mkAfter '' + mkdir -p ~/journal + chmod -R u+w ~/journal + ''; +} diff --git a/home/programs/programs.nix b/home/programs/programs.nix index aadb688..8b38da7 100644 --- a/home/programs/programs.nix +++ b/home/programs/programs.nix @@ -23,5 +23,6 @@ ./git/default.nix ./zathura/default.nix ./keepassxc/default.nix + ./nf/default.nix ]; } diff --git a/home/programs/rofi/styles/prompt-search.rasi b/home/programs/rofi/styles/prompt-search.rasi new file mode 100644 index 0000000..e380159 --- /dev/null +++ b/home/programs/rofi/styles/prompt-search.rasi @@ -0,0 +1,91 @@ +@import "/home/synchronous/.config/rofi/styles/colors.rasi" + +configuration { + show-icons: false; +} + +* { + pink: @base0C; + cyan: @base0F; + green: #9ece6a; + + accent-color: @base06; + urgent-color: @base0A; + + background-color: transparent; + text-color: @text; + margin: 0; + padding: 0; +} + +window { + location: center; + anchor: center; + fullscreen: false; + y-offset: 0px; + + enabled: true; + background-color: @background; + cursor: "default"; + border: 1px; + border-color: #565657; + width: 500px; +} + +inputbar { + enabled: true; + background-color: @prompt; + padding: 10px; + children: ["entry"]; +} + +entry { + enabled: true; + padding: 0.75em 0.75em; + cursor: text; +} + +listview { + enabled: true; + columns: 1; + lines: 10; + cycle: true; + dynamic: true; + scrollbar: false; + layout: vertical; + reverse: false; + fixed-height: true; + fixed-columns: true; + margin: 0.25em 0 0.25em; + cursor: "default"; +} + +prompt { + text-color: @accent-color; + +} + +textbox { + padding: 0.5em 1.5em; + background-color: @prompt; +} + +element { + enabled: true; + margin: 0 0.25em; + padding: 0.5em 0.75em; + cursor: pointer; + orientation: vertical; +} + +element-text { + highlight: @green; + cursor: inherit; + vertical-align: 0.5; + horizontal-align: 0.0; + font: "Liga SFMono Nerd Font 14"; +} + +element-text selected { + text-color: @cyan; +} diff --git a/home/scripts/journal/nf.sh b/home/scripts/journal/nf.sh new file mode 100644 index 0000000..c523048 --- /dev/null +++ b/home/scripts/journal/nf.sh @@ -0,0 +1,165 @@ +#!/bin/bash + +main="/home/synchronous/journal/" +#main_dir="$main/abstract" +#main="/home/synchronous/code/nm/notes" +main_dir="$main/rest" +rofi_prompt="/home/synchronous/.config/rofi/styles/prompt-search.rasi" +len_maindir=${#main_dir} + +search() { + rs="$(find "$main_dir" -follow -printf "%T@ %Tc %p\n" | sort -n -r | cut -c"$((len_maindir + 49))"- | rg -a '\.md$')" + rcv=$(echo "$rs" | rofi -dmenu -theme "$rofi_prompt") + if [[ "$rcv" == "" ]]; then exit 1; fi + if [[ $(echo "$rs" | rg "$rcv") ]]; then # check if we actually have our note + alacritty -t "$rcv" -e nvim "$main_dir/$rcv" \ + -c "Goyo | execute 'normal 4j' | set path+=$main_dir | autocmd BufEnter * let b:coc_suggest_disable=1" &! + # -c "syntax match LinkPattern /[a-zA-Z0-9\-][a-zA-Z0-9\-]*\.md/" \ + # -c "highlight LinkPattern guifg=LightBlue gui=underline" \ + # -c "nnoremap :call CustomGf()" \ + # -c "nnoremap gf :call CustomGf()" \ + else + + # if rcv doesn't contain md, add it + if [[ $(echo "$rcv" | rg -v '\.md$') ]]; then + rcv="$rcv.md" + fi + + no_md="${rcv%.md}" + replaced="${no_md//[-_]/ }" + echo "lol" + + alacritty -t "$rcv" -e nvim "$main_dir/$rcv" \ + -c "Goyo | set path+=$main_dir | autocmd BufEnter * let b:coc_suggest_disable=1" \ + -c "call setline(1, ['---', 'title: $replaced', 'tags: ', '---', '']) | execute 'normal G'" &! + # make sure standardized frontmatter is there + fi +} + +open_daily() { + alacritty -t "daily.md" -e nvim "$main/daily.md" \ + -c "Goyo | set path+=$main_dir" &! + -c "execute 'normal G'" +} + +open_todo() { + alacritty -t "todo.md" -e nvim "$main/todo.md" \ + -c "Goyo | set path+=$main_dir" &! + # -c "execute 'normal G'" +} + +notes_find() { + rg $2 $main_dir +} + +search_by_tags() { + tt="" + # while IFS= read -r -d '' file; do + # is_tags=$(awk 'NR==3 {print substr($0, 1, 4)}' "$file") + # if [[ $is_tags == "tags" ]]; then + # line=$(sed -n '3p' "$file") + # tt+=$(echo "$file" | cut -c"$((len_maindir + 2))"- ) + # tt+=" [$(echo "$line" | cut -c7-)]\n" + # fi + # done < <(find $main_dir -type f -print0) + + rs="$(find "$main_dir" -follow -printf "%T@ %Tc %p\n" | sort -n -r | cut -c"$((len_maindir + 49))"- | rg -a '\.md$')" + + while IFS= read -r -d '' file; do + { read -r _; read -r _; read -r line; } < "$file" + + if [[ ${line:0:4} == "tags" ]]; then + tags="${line:6}" + tags="${tags#"${tags%%[![:space:]]*}"}" + tags="${tags%"${tags##*[![:space:]]}"}" + filename="${file:$((len_maindir + 1))}" + tt+="$filename [$tags]\n" + fi + done < <(find "$main_dir" -type f -print0) + + rcv=$(echo -e "$tt" | awk 'NR > 1 {print prev} {prev=$0} END {printf "%s", prev}' | rofi -dmenu -theme "$rofi_prompt") + rcv=$(echo $rcv | sed 's/ \[[^]]*\]$//') + if [[ "$rcv" == "" ]]; then exit 1; fi + if [[ $(echo "$rs" | rg "$rcv") ]]; then # check if we actually have our note + alacritty -t "$rcv" -e nvim "$main_dir/$rcv" \ + -c "Goyo | execute 'normal 4j' | set path+=$main_dir | autocmd BufEnter * let b:coc_suggest_disable=1" &! + else + + # if rcv doesn't contain md, add it + if [[ $(echo "$rcv" | rg -v '\.md$') ]]; then + rcv="$rcv.md" + fi + + no_md="${rcv%.md}" + replaced="${no_md//[-_]/ }" + + alacritty -t "$rcv" -e nvim "$main_dir/$rcv" \ + -c "Goyo | set path+=$main_dir | autocmd BufEnter * let b:coc_suggest_disable=1" \ + -c "call setline(1, ['---', 'title: $replaced', 'tags: ', '---', '']) | execute 'normal G'" &! # make sure standardized frontmatter is there + fi +} + +search_by_title() { + # tt="" + # while IFS= read -r -d '' file; do + # is_title=$(awk 'NR==2 {print substr($0, 1, 5)}' "$file") + # if [[ $is_title == "title" ]]; then + # line=$(sed -n '2p' "$file") + # # tt+="$(echo "$line" | cut -c7-)" + # tt+="$(echo "$line" | cut -c7- | sed 's/^ *//; s/ *$//')" + # tt+=' ('$(echo "$file" | cut -c"$((len_maindir + 2))"- )')\n' + # fi + # done < <(find $main_dir -type f -print0) + + rs="$(find "$main_dir" -follow -printf "%T@ %Tc %p\n" | sort -n -r | cut -c"$((len_maindir + 49))"- | rg -a '\.md$')" + + tt="" + while IFS= read -r -d '' file; do + { read -r _; read -r line; } < "$file" + + if [[ ${line:0:5} == "title" ]]; then + title="${line:6}" + + title="${title#"${title%%[![:space:]]*}"}" + title="${title%"${title##*[![:space:]]}"}" + filename="${file:$((len_maindir + 1))}" + tt+="$title ($filename)\n" + fi + done < <(find "$main_dir" -type f -print0) + + rcv=$(echo -e "$tt" | awk 'NR > 1 {print prev} {prev=$0} END {printf "%s", prev}' | rofi -dmenu -theme "$rofi_prompt") + rcv=$(echo $rcv | rg -e "[a-zA-Z0-9]*\.md" -o) + if [[ "$rcv" == "" ]]; then exit 1; fi + # echo "$rcv" + if [[ $(echo "$rs" | rg "$rcv") ]]; then # check if we actually have our note + alacritty -t "$rcv" -e nvim "$main_dir/$rcv" \ + -c "Goyo | execute 'normal 4j' | set path+=$main_dir | autocmd BufEnter * let b:coc_suggest_disable=1" &! + else + + # if rcv doesn't contain md, add it + if [[ $(echo "$rcv" | rg -v '\.md$') ]]; then + rcv="$rcv.md" + fi + + no_md="${rcv%.md}" + replaced="${no_md//[-_]/ }" + + alacritty -t "$rcv" -e nvim "$main_dir/$rcv" \ + -c "Goyo | set path+=$main_dir | autocmd BufEnter * let b:coc_suggest_disable=1" \ + -c "call setline(1, ['---', 'title: $replaced', 'tags: ', '---', '']) | execute 'normal G'" &! # make sure standardized frontmatter is there + fi +} + +run_command() { + case $1 in + "search") search ;; + "daily") open_daily ;; + "todo") open_todo ;; + "find") notes_find ;; + "tags") search_by_tags ;; + "title") search_by_title ;; + *) + esac +} + +run_command "$1"