From 8b85cf7c9e3c3470107f7f2dbc1ac159d16cce30 Mon Sep 17 00:00:00 2001 From: aleidk Date: Thu, 12 Sep 2024 16:55:05 -0300 Subject: [PATCH] add zk workflow fixes #1 --- chezmoi/.chezmoidata/packages.yaml | 4 +- chezmoi/.chezmoiexternal.toml | 6 + chezmoi/dot_config/fzf/fzfrc | 42 ++-- .../nvim/lua/aleidk/plugins/key-help.lua | 35 +-- .../nvim/lua/aleidk/plugins/markdown.lua | 29 +++ .../dot_config/nvim/original_lazy-lock.json | 3 +- chezmoi/dot_config/tmux/tmux.conf | 2 + chezmoi/dot_config/zk/config.toml | 205 ++++++++++++++++++ chezmoi/dot_config/zsh/completions/_tea | 26 +++ scripts/fzf-fj | 20 ++ scripts/fzf-tea | 10 +- scripts/fzf-wikis | 38 ++++ 12 files changed, 373 insertions(+), 47 deletions(-) create mode 100644 chezmoi/dot_config/zk/config.toml create mode 100644 chezmoi/dot_config/zsh/completions/_tea create mode 100755 scripts/fzf-fj create mode 100755 scripts/fzf-wikis diff --git a/chezmoi/.chezmoidata/packages.yaml b/chezmoi/.chezmoidata/packages.yaml index aa94c29..3512bc7 100644 --- a/chezmoi/.chezmoidata/packages.yaml +++ b/chezmoi/.chezmoidata/packages.yaml @@ -3,8 +3,8 @@ packages: - du-dust - mise - rbw - - yazi-fm - - yazi-cli + # - yazi-fm + # - yazi-cli dnf: copr: - atim/lazygit diff --git a/chezmoi/.chezmoiexternal.toml b/chezmoi/.chezmoiexternal.toml index 853bfa1..7067d6a 100644 --- a/chezmoi/.chezmoiexternal.toml +++ b/chezmoi/.chezmoiexternal.toml @@ -24,3 +24,9 @@ url = "https://github.com/joshmedeski/sesh/releases/latest/download/sesh_Linux_x86_64.tar.gz" path = "sesh" refreshPeriod = "168h" + +[".local/bin/zk"] + type = "archive-file" + url = "https://github.com/zk-org/zk/releases/latest/download/zk-v0.14.1-linux-amd64.tar.gz" + path = "zk" + refreshPeriod = "168h" diff --git a/chezmoi/dot_config/fzf/fzfrc b/chezmoi/dot_config/fzf/fzfrc index d7c9236..3fc1657 100644 --- a/chezmoi/dot_config/fzf/fzfrc +++ b/chezmoi/dot_config/fzf/fzfrc @@ -1,26 +1,25 @@ export FZF_SHOW_HELP_OPTS="$( cat <<-EOF +FZF Keybinds Shortcut - FZF Keybinds Shortcut +? Toggle/Hide Preview +C-space Change preview layout +C-e Open in Editor +C-v Open in VsCode +C-o Launch Application Chooser +M-o Open in Default Appllication +C-/ Directory: Navigate on broot +C-/ File: Open in Pager (bat) - ? Toggle/Hide Preview - C-space Change preview layout - C-e Open in Editor - C-v Open in VsCode - C-o Launch Application Chooser - M-o Open in Default Appllication - C-/ Directory: Navigate on broot - C-/ File: Open in Pager (bat) +M-s Toggle Sort +C-y Copy/Yank +C-M-y Copy/Yank Working Directory +C-a Select all +C-M-d Deselect All +Del Delete/Remove file - M-s Toggle Sort - C-y Copy/Yank - C-M-y Copy/Yank Working Directory - C-a Select all - C-M-d Deselect All - Del Delete/Remove file - - Alt-? Help (this page) - ESC Quit +Alt-? Help (this page) +ESC Quit EOF )" @@ -30,8 +29,8 @@ export FZF_DEFAULT_OPTS=" \ --color=marker:#f4dbd6,fg+:#cad3f5,prompt:#c6a0f6,hl+:#ed8796" export FZF_PREVIEW_OPTS="--preview -'([[ {} =~ ('.jpg'|'.jpeg'|'.png'|'.gif'|'.bmp'|'.svg'|'.mp4'|'.mkv')$ ]] && (chafa --center=on {} && exiftool {})) || -([[ -f {} ]] && (bat --style=header,numbers,changes,plain --color=always --language=sh --line-range :500 {} || cat {})) || +'([[ {} =~ ('.jpg'|'.jpeg'|'.png'|'.gif'|'.bmp'|'.svg'|'.mp4'|'.mkv')$ ]] && (chafa --center=on {} && exiftool {})) || +([[ -f {} ]] && (bat --style=header,numbers,changes,plain --color=always --language=sh --line-range :500 {} || cat {})) || ([[ -d {} ]] && (lsd -all --long --tree --depth=5 --group-dirs=first -I=.git {} )) || echo {} 3>/dev/null | head -n 500' " @@ -56,7 +55,7 @@ $FZF_PREVIEW_KEYBIND_OPTS --bind 'ctrl-/:execute( if [[ -d {} ]]; then broot {} < /dev/tty > /dev/tty 2>&1 -elif [[ {} =~ ('.jpg'|'.jpeg'|'.png'|'.gif'|'.bmp'|'.svg'|'.mp4'|'.mkv')$ ]]; then +elif [[ {} =~ ('.jpg'|'.jpeg'|'.png'|'.gif'|'.bmp'|'.svg'|'.mp4'|'.mkv')$ ]]; then chafa --center {} | less > /dev/tty else bat --paging=always --style=plain --color=always --language=sh {} > /dev/tty @@ -86,7 +85,6 @@ export FZF_DEFAULT_OPTS=" --info=inline --no-separator --layout=reverse ---preview-window=:hidden " export FZF_ALT_C_COMMAND="fd --type=d --color=always --hidden --exclude .git" diff --git a/chezmoi/dot_config/nvim/lua/aleidk/plugins/key-help.lua b/chezmoi/dot_config/nvim/lua/aleidk/plugins/key-help.lua index 15d2cab..5914f0c 100644 --- a/chezmoi/dot_config/nvim/lua/aleidk/plugins/key-help.lua +++ b/chezmoi/dot_config/nvim/lua/aleidk/plugins/key-help.lua @@ -8,6 +8,7 @@ return { triggers = { -- Leader triggers { mode = "n", keys = "" }, + { mode = "v", keys = "" }, { mode = "x", keys = "" }, -- Built-in completion @@ -46,24 +47,26 @@ return { miniclue.gen_clues.windows(), miniclue.gen_clues.z(), - { mode = "n", keys = "", desc = "+Bookmarks" }, + { mode = "n", keys = "", desc = "+Bookmarks" }, { mode = "n", keys = "n", postkeys = "" }, { mode = "n", keys = "N", postkeys = "" }, - { mode = "n", keys = "b", desc = "+Buffers" }, - { mode = "n", keys = "bh", postkeys = "b" }, - { mode = "n", keys = "bl", postkeys = "b" }, - { mode = "n", keys = "f", desc = "+Find" }, - { mode = "n", keys = "g", desc = "+Git" }, - { mode = "n", keys = "l", desc = "+LSP" }, - { mode = "n", keys = "r", desc = "+Replace" }, - { mode = "n", keys = "u", desc = "+UI & Config" }, - { mode = "n", keys = "un", desc = "+Noice" }, - { mode = "n", keys = "w", desc = "+Workspace" }, - { mode = "n", keys = "p", desc = "+Run stuff" }, - { mode = "n", keys = "a", desc = "+ChatGPT" }, - { mode = "v", keys = "a", desc = "+ChatGPT" }, - { mode = "n", keys = "a", desc = "+ChatGPT" }, - { mode = "n", keys = "g?", desc = "+Print Debug" }, + { mode = "n", keys = "b", desc = "+Buffers" }, + { mode = "n", keys = "bh", postkeys = "b" }, + { mode = "n", keys = "bl", postkeys = "b" }, + { mode = "n", keys = "f", desc = "+Find" }, + { mode = "n", keys = "g", desc = "+Git" }, + { mode = "n", keys = "l", desc = "+LSP" }, + { mode = "n", keys = "r", desc = "+Replace" }, + { mode = "n", keys = "u", desc = "+UI & Config" }, + { mode = "n", keys = "un", desc = "+Noice" }, + { mode = "n", keys = "w", desc = "+Workspace" }, + { mode = "n", keys = "p", desc = "+Run stuff" }, + { mode = "n", keys = "a", desc = "+ChatGPT" }, + { mode = "n", keys = "z", desc = "+ZK" }, + { mode = "v", keys = "z", desc = "+ZK" }, + { mode = "v", keys = "a", desc = "+ChatGPT" }, + { mode = "n", keys = "a", desc = "+ChatGPT" }, + { mode = "n", keys = "g?", desc = "+Print Debug" }, }, -- Clue window settings diff --git a/chezmoi/dot_config/nvim/lua/aleidk/plugins/markdown.lua b/chezmoi/dot_config/nvim/lua/aleidk/plugins/markdown.lua index 581a25a..d332a1e 100644 --- a/chezmoi/dot_config/nvim/lua/aleidk/plugins/markdown.lua +++ b/chezmoi/dot_config/nvim/lua/aleidk/plugins/markdown.lua @@ -11,4 +11,33 @@ return { }, }, }, + { + "zk-org/zk-nvim", + config = function() + require("zk").setup({ + picker = "select", + }) + + function MAP(mode, l, r, desc) + vim.keymap.set(mode, l, r, { desc = desc, silent = true }) + end + + MAP("n", "", "lua vim.lsp.buf.definition()", "Open the link under cursor") + + MAP("n", "zn", "ZkNew { dir = vim.fn.expand('%:p:h'), title = vim.fn.input('Title: ') }", + "Create new note") + MAP("v", "zN", + ":'<,'>ZkNewFromContentSelection { dir = vim.fn.expand('%:p:h'), title = vim.fn.input('Title: ') }", + "Create new note using selection as content") + + MAP("n", "zl", "ZkInsertLink", "Insert Link into cursor position") + MAP("v", "zl", ":'<,'>ZkInsertLinkAtSelection", "Insert Link into selection") + + MAP("n", "zb", "ZkBacklinks", "Backlinks") + MAP("n", "zo", "ZkLinks", "Outlinks") + + MAP("n", "zf", "ZkNotes", "Find note") + MAP("n", "zt", "ZkTags", "Find tags") + end + } } diff --git a/chezmoi/dot_config/nvim/original_lazy-lock.json b/chezmoi/dot_config/nvim/original_lazy-lock.json index edbb388..fea1828 100644 --- a/chezmoi/dot_config/nvim/original_lazy-lock.json +++ b/chezmoi/dot_config/nvim/original_lazy-lock.json @@ -72,5 +72,6 @@ "vim-dadbod-ui": { "branch": "master", "commit": "f74a31e8c6c5a9dccc63450a09d5cd64a9294330" }, "vim-illuminate": { "branch": "master", "commit": "5eeb7951fc630682c322e88a9bbdae5c224ff0aa" }, "vim-sleuth": { "branch": "master", "commit": "1cc4557420f215d02c4d2645a748a816c220e99b" }, - "zen-mode.nvim": { "branch": "main", "commit": "2694c5a2bc4dc26c7a9e74b9e2b812920c90a830" } + "zen-mode.nvim": { "branch": "main", "commit": "2694c5a2bc4dc26c7a9e74b9e2b812920c90a830" }, + "zk-nvim": { "branch": "main", "commit": "dbf4eeab55b08856c9d6b6722dbff39630bb35eb" } } diff --git a/chezmoi/dot_config/tmux/tmux.conf b/chezmoi/dot_config/tmux/tmux.conf index 4ea8b36..c24df25 100644 --- a/chezmoi/dot_config/tmux/tmux.conf +++ b/chezmoi/dot_config/tmux/tmux.conf @@ -175,6 +175,8 @@ set -g @popup-id-format '#{b:socket_path}/#{session_name}/#{b:pane_current_path} # Use this to open specific programs in floating panes bind C-p run "#{@popup-toggle}" bind C-o run "#{@popup-toggle} -Ed'#{pane_current_path}' -w90% -h90% --name=tool fzf-tmux-tools-popup" +bind C-w run "#{@popup-toggle} -Ed'#{pane_current_path}' -w90% -h90% --name=wiki fzf-wikis" +bind C-z run "#{@popup-toggle} -Ed'#{pane_current_path}' -w90% -h90% --name=wiki fzf-wikis void" # ╭──────────────────────────────────────────────────────────╮ # │ FZF │ diff --git a/chezmoi/dot_config/zk/config.toml b/chezmoi/dot_config/zk/config.toml new file mode 100644 index 0000000..bf75464 --- /dev/null +++ b/chezmoi/dot_config/zk/config.toml @@ -0,0 +1,205 @@ +# zk configuration file +# +# Uncomment the properties you want to customize. + +# NOTE SETTINGS +# +# Defines the default options used when generating new notes. +[note] + +# Language used when writing notes. +# This is used to generate slugs or with date formats. +#language = "en" + +# The default title used for new note, if no `--title` flag is provided. +#default-title = "Untitled" + +# Template used to generate a note's filename, without extension. +filename = "{{slug title}}" + +# The file extension used for the notes. +#extension = "md" + +# Template used to generate a note's content. +# If not an absolute path, it is relative to .zk/templates/ +template = "default.md" + +# Path globs ignored while indexing existing notes. +#ignore = [ +# "drafts/*", +# "log.md" +#] + +# Configure random ID generation. + +# The charset used for random IDs. You can use: +# * letters: only letters from a to z. +# * numbers: 0 to 9 +# * alphanum: letters + numbers +# * hex: hexadecimal, from a to f and 0 to 9 +# * custom string: will use any character from the provided value +#id-charset = "alphanum" + +# Length of the generated IDs. +id-length = 8 + +# Letter case for the random IDs, among lower, upper or mixed. +#id-case = "lower" + + +# EXTRA VARIABLES +# +# A dictionary of variables you can use for any custom values when generating +# new notes. They are accessible in templates with {{extra.}} +[extra] + +#key = "value" + + +# GROUP OVERRIDES +# +# You can override global settings from [note] and [extra] for a particular +# group of notes by declaring a [group.""] section. +# +# Specify the list of directories which will automatically belong to the group +# with the optional `paths` property. +# +# Omitting `paths` is equivalent to providing a single path equal to the name of +# the group. This can be useful to quickly declare a group by the name of the +# directory it applies to. + +#[group.""] +#paths = ["", ""] +#[group."".note] +#filename = "{{format-date now}}" +#[group."".extra] +#key = "value" + + +# MARKDOWN SETTINGS +[format.markdown] + +# Format used to generate links between notes. +# Either "wiki", "markdown" or a custom template. Default is "markdown". +link-format = "wiki" +# Indicates whether a link's path will be percent-encoded. +# Defaults to true for "markdown" format and false for "wiki" format. +#link-encode-path = true +# Indicates whether a link's path file extension will be removed. +# Defaults to true. +#link-drop-extension = true + +# Enable support for #hashtags. +hashtags = true +# Enable support for :colon:separated:tags:. +colon-tags = false +# Enable support for Bear's #multi-word tags# +# Hashtags must be enabled for multi-word tags to work. +multiword-tags = false + + +# EXTERNAL TOOLS +[tool] + +# Default editor used to open notes. When not set, the EDITOR or VISUAL +# environment variables are used. +#editor = "vim" + +# Pager used to scroll through long output. If you want to disable paging +# altogether, set it to an empty string "". +#pager = "less -FIRX" + +fzf-line = "{{style 'title' path}}" +fzf-preview = "bat -p --color always --style header,grid {-1}" +fzf-bind-new = "" +fzf-options = """ + --layout reverse + --height 100% + --no-hscroll + --preview-window down,wrap,border-none,70% + --header "C-A: New note in root with query as slug\nC-N: New note respecting query path" + --bind "ctrl-n:abort+execute(mkdir -p $(dirname '{q}') && zk new $(dirname '{q}') --title $(basename '{q}'))" + --bind "ctrl-a:abort+execute(mkdir -p $(dirname '{q}') && zk new $(dirname '{q}') --title $(basename '{q}'))" +""" + + +# LSP +# +# Configure basic editor integration for LSP-compatible editors. +# See https://github.com/zk-org/zk/blob/main/docs/editors-integration.md +# +[lsp] + +[lsp.diagnostics] +# Each diagnostic can have for value: none, hint, info, warning, error + +# Report titles of wiki-links as hints. +# wiki-title = "hint" +# Warn for dead links between notes. +dead-link = "error" + +[lsp.completion] +# Customize the completion pop-up of your LSP client. + +# Show the note title in the completion pop-up, or fallback on its path if empty. +#note-label = "" +# Filter out the completion pop-up using the note title or its path. +#note-filter-text = " " +# Show the note filename without extension as detail. +#note-detail = "" + + +# NAMED FILTERS +# +# A named filter is a set of note filtering options used frequently together. +# +[filter] + +# Matches the notes created the last two weeks. For example: +# $ zk list recents --limit 15 +# $ zk edit recents --interactive +#recents = "--sort created- --created-after 'last two weeks'" + + +# COMMAND ALIASES +# +# Aliases are user commands called with `zk [] []`. +# +# The alias will be executed with `$SHELL -c`, please refer to your shell's +# man page to see the available syntax. In most shells: +# * $@ can be used to expand all the provided flags and arguments +# * you can pipe commands together with the usual | character +# +[alias] +# Here are a few aliases to get you started. + +# Shortcut to a command. +ls = "zk list --interactive --sort path+ $@" + +e = "zk edit --interactive --sort path+ $@" + +# Default flags for an existing command. +#list = "zk list --quiet $@" + +# Edit the last modified note. +#editlast = "zk edit --limit 1 --sort modified- $@" + +# Edit the notes selected interactively among the notes created the last two weeks. +# This alias doesn't take any argument, so we don't use $@. +#recent = "zk edit --sort created- --created-after 'last two weeks' --interactive" + +# Print paths separated with colons for the notes found with the given +# arguments. This can be useful to expand a complex search query into a flag +# taking only paths. For example: +# zk list --link-to "`zk path -m potatoe`" +#path = "zk list --quiet --format {{path}} --delimiter , $@" + +# Show a random note. +#lucky = "zk list --quiet --format full --sort random --limit 1" + +# Returns the Git history for the notes found with the given arguments. +# Note the use of a pipe and the location of $@. +#hist = "zk list --format path --delimiter0 --quiet $@ | xargs -t -0 git log --patch --" + +# Edit this configuration file. +#conf = '$EDITOR "$ZK_NOTEBOOK_DIR/.zk/config.toml"' diff --git a/chezmoi/dot_config/zsh/completions/_tea b/chezmoi/dot_config/zsh/completions/_tea new file mode 100644 index 0000000..0525f9b --- /dev/null +++ b/chezmoi/dot_config/zsh/completions/_tea @@ -0,0 +1,26 @@ +#compdef $PROG + +PROG=tea +_CLI_ZSH_AUTOCOMPLETE_HACK=1 + +_cli_zsh_autocomplete() { + + local -a opts + local cur + cur=${words[-1]} + if [[ "$cur" == "-"* ]]; then + opts=("${(@f)$(_CLI_ZSH_AUTOCOMPLETE_HACK=1 ${words[@]:0:#words[@]-1} ${cur} --generate-bash-completion)}") + else + opts=("${(@f)$(_CLI_ZSH_AUTOCOMPLETE_HACK=1 ${words[@]:0:#words[@]-1} --generate-bash-completion)}") + fi + + if [[ "${opts[1]}" != "" ]]; then + _describe 'values' opts + else + _files + fi + + return +} + +compdef _cli_zsh_autocomplete $PROG diff --git a/scripts/fzf-fj b/scripts/fzf-fj new file mode 100755 index 0000000..4b06626 --- /dev/null +++ b/scripts/fzf-fj @@ -0,0 +1,20 @@ +#!/usr/bin/env bash + +# ╭──────────────────────────────────────────────────────────╮ +# │ Interactivie Issue management of forgejo │ +# ╰──────────────────────────────────────────────────────────╯ + +host="git.alecodes.page" +repo="$(git remote get-url origin | rev | cut -d '/' -f -2 | rev | cut -d '.' -f 1)" +cache="$(mktemp --directory)" + +# --preview "[[ -e $cache/{1}.md ]] && bat $cache/{1}.md || fj --host $host issue view \"${repo}$(echo {1} | tr -d ':')\" | tee $cache/{1}.md" \ + +# TODO: Add more keybindings to interact with issues +fj --host "$host" issue search --repo "$repo" | tail -n +2 | + fzf \ + --preview "id=\"$(echo "{1}" | tr -cd "[:digit:]")\"; [[ -e $cache/$id ]] && bat $cache/$id || fj --host $host issue view ${repo}#$id | tee $cache/$id" \ + --bind "ctrl-r:execute-silent(rm -f $cache/{1})+refresh-preview" \ + --bind "ctrl-o:execute-silent(tea open {1})" + +rm -rf "$cache" diff --git a/scripts/fzf-tea b/scripts/fzf-tea index fc0013c..3393148 100755 --- a/scripts/fzf-tea +++ b/scripts/fzf-tea @@ -6,15 +6,13 @@ # ──────────────────────────────────────────────────────────── -tea_issue_cache="/tmp/tea-issue-cache" - -mkdir -p "$tea_issue_cache" +tea_cache="$(mktemp --directory)" # TODO: Add more keybindings to interact with issues tea i -o simple | fzf \ - --preview "[[ -e $tea_issue_cache/{1} ]] && cat $tea_issue_cache/{1} || tea issue --comments {1} | tee $tea_issue_cache/{1}" \ - --bind "ctrl-r:execute-silent(rm -f $tea_issue_cache/{1})+refresh-preview" \ + --preview "[[ -e $tea_cache/{1}.md ]] && bat -l md $tea_cache/{1}.md || tea issue --comments {1} | tee $tea_cache/{1}.md" \ + --bind "ctrl-r:execute-silent(rm -f $tea_cache/{1})+refresh-preview" \ --bind "ctrl-o:execute-silent(tea open {1})" -rm -rf "$tea_issue_cache" +rm -rf "$tea_cache" diff --git a/scripts/fzf-wikis b/scripts/fzf-wikis new file mode 100755 index 0000000..1f1cf92 --- /dev/null +++ b/scripts/fzf-wikis @@ -0,0 +1,38 @@ +#! /usr/bin/env bash + +set -e + +wikis_path="$HOME/Repos/wikis" +initial_path=$PWD + +if [[ -n $1 ]]; then + current_repo_name="$1" + shift +elif git rev-parse --git-dir &>/dev/null; then + current_repo_name=$(git remote get-url origin | rev | cut -d '/' -f -1 | rev | cut -d '.' -f 1) + current_repo_name="$current_repo_name.wiki" +else + echo "The command was not executed in a git repository and a repo name was not provided" + read -rn 1 -p "Press any key to exit..." + exit +fi + +path="$wikis_path/$current_repo_name" + +if [[ ! -e "$path" ]]; then + echo "The wiki for $current_repo_name doesn't exit, please clone it first to $wikis_path" + read -rn 1 -p "Press any key to exit..." + exit +fi + +cd "$path" || exit + +if [[ ! -e .zk/config.toml ]]; then + echo "ZK is not initialized in $path" + read -rn 1 -p "Press any key to exit..." + exit +fi + +zk e + +cd "$initial_path" || exit