fix: centralize and nixifiy in 'zk' module
This commit is contained in:
@@ -1,4 +0,0 @@
|
|||||||
#!/usr/bin/env bash
|
|
||||||
|
|
||||||
cd "$ZK_PATH" || echo "No zettelkasten directory found"
|
|
||||||
git a . && git commit -m "Update" && git push
|
|
||||||
@@ -1,20 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
|
|
||||||
if [ ! -d ~/.zk ]; then
|
|
||||||
echo "[zk] Setting up zettelkasten"
|
|
||||||
gh repo clone zk ~/.zk
|
|
||||||
else
|
|
||||||
echo "[zk] Zettelkasten already set up."
|
|
||||||
fi
|
|
||||||
|
|
||||||
read -p "Would you like open your zettelkasten? [y/N] " -n 1 -r
|
|
||||||
echo
|
|
||||||
|
|
||||||
if [[ $REPLY =~ ^[Yy]$ ]]; then
|
|
||||||
if [ -x "$(command -v zk)" ]; then
|
|
||||||
zk
|
|
||||||
else
|
|
||||||
echo "Error: 'zk' command not found or not executable"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
@@ -1,6 +1,8 @@
|
|||||||
|
require("zk.utils")
|
||||||
|
|
||||||
vim.cmd([[
|
vim.cmd([[
|
||||||
" Change local buffer to directory of current file after the plugin has loaded
|
" Change local buffer to directory of current file after the plugin has loaded
|
||||||
autocmd VimEnter * lcd %:p:h
|
execute 'autocmd BufEnter' g:zk_path . '/*.md' 'silent lcd %:p:h'
|
||||||
|
|
||||||
" " Override wiki index mapping to also cd into the wiki
|
" " Override wiki index mapping to also cd into the wiki
|
||||||
nm <leader>ww <plug>(wiki-index)
|
nm <leader>ww <plug>(wiki-index)
|
||||||
@@ -76,7 +78,7 @@ let g:wiki_templates = [
|
|||||||
"
|
"
|
||||||
|
|
||||||
let g:wiki_filetypes=['md']
|
let g:wiki_filetypes=['md']
|
||||||
let g:wiki_root='~/.zk'
|
let g:wiki_root=g:zk_path
|
||||||
let g:wiki_global_load=0
|
let g:wiki_global_load=0
|
||||||
let g:wiki_link_creation = {
|
let g:wiki_link_creation = {
|
||||||
\ 'md': {
|
\ 'md': {
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
require("zk.cmp")
|
require("zk.cmp")
|
||||||
|
require("zk.utils")
|
||||||
|
|
||||||
vim.cmd([[
|
vim.cmd([[
|
||||||
let s:zk_preview_enabled = 0
|
let s:zk_preview_enabled = 0
|
||||||
let s:live_server_job = -1
|
let s:live_server_job = -1
|
||||||
au BufEnter /home/h/.zk/*.md silent exe '!echo "%" > /home/h/.zk/current-zettel.txt'
|
execute 'au BufEnter' g:zk_path . '/*.md' 'silent exe "!echo %" ">" g:zk_path . "/current-zettel.txt"'
|
||||||
function! ToggleZKPreview()
|
function! ToggleZKPreview()
|
||||||
if s:zk_preview_enabled == 1
|
if s:zk_preview_enabled == 1
|
||||||
let s:zk_preview_enabled = 0
|
let s:zk_preview_enabled = 0
|
||||||
@@ -11,10 +12,10 @@ function! ToggleZKPreview()
|
|||||||
au! ZKPreview
|
au! ZKPreview
|
||||||
else
|
else
|
||||||
let s:zk_preview_enabled = 1
|
let s:zk_preview_enabled = 1
|
||||||
let s:live_server_job = jobstart('live-server --watch=/home/h/.zk/current-zettel-content.html --open=current-zettel-content.html --port=8080')
|
let s:live_server_job = jobstart('live-server --watch=' . g:zk_path . '/current-zettel-content.html --open=current-zettel-content.html --port=8080')
|
||||||
augroup ZKPreview
|
augroup ZKPreview
|
||||||
au BufEnter /home/h/.zk/*.md silent exe '!cat "%:r.html" > /home/h/.zk/current-zettel-content.html'
|
execute 'au BufEnter' g:zk_path . '/*.md' 'silent exe "!cat %:r.html" ">" g:zk_path . "/current-zettel-content.html"'
|
||||||
au BufWritePost /home/h/.zk/*.md silent exe '!make && cat "%:r.html" > /home/h/.zk/current-zettel-content.html'
|
execute 'au BufWritePost' g:zk_path . '/*.md' 'silent exe "!make && cat %:r.html" ">" g:zk_path . "/current-zettel-content.html"'
|
||||||
augroup END
|
augroup END
|
||||||
endif
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
|
|||||||
2
dots/.config/nvim/lua/zk/utils.lua
Normal file
2
dots/.config/nvim/lua/zk/utils.lua
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
vim.g.zk_path = os.getenv("ZK_PATH") or (os.getenv("HOME") .. "/.zk")
|
||||||
|
return vim.g.zk_path
|
||||||
@@ -30,6 +30,7 @@
|
|||||||
../../modules/ssh
|
../../modules/ssh
|
||||||
../../modules/taskwarrior
|
../../modules/taskwarrior
|
||||||
../../modules/terminal
|
../../modules/terminal
|
||||||
|
../../modules/zk
|
||||||
../../modules/torrenting
|
../../modules/torrenting
|
||||||
];
|
];
|
||||||
|
|
||||||
@@ -54,6 +55,7 @@
|
|||||||
shell.bash.aliases.lang-js = true;
|
shell.bash.aliases.lang-js = true;
|
||||||
shell.bash.addBinToPath = true;
|
shell.bash.addBinToPath = true;
|
||||||
torrenting.enable = true;
|
torrenting.enable = true;
|
||||||
|
zk.enable = true;
|
||||||
|
|
||||||
programs = {
|
programs = {
|
||||||
home-manager.enable = true;
|
home-manager.enable = true;
|
||||||
|
|||||||
45
home/modules/zk/default.nix
Normal file
45
home/modules/zk/default.nix
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
{
|
||||||
|
config,
|
||||||
|
lib,
|
||||||
|
pkgs,
|
||||||
|
...
|
||||||
|
}:
|
||||||
|
|
||||||
|
let
|
||||||
|
cfg = config.zk;
|
||||||
|
in
|
||||||
|
{
|
||||||
|
options.zk = {
|
||||||
|
enable = lib.mkEnableOption "zettelkasten";
|
||||||
|
path = lib.mkOption {
|
||||||
|
type = lib.types.str;
|
||||||
|
default = config.home.homeDirectory + "/.zk";
|
||||||
|
description = "Path to the zettelkasten directory";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
config = lib.mkIf cfg.enable {
|
||||||
|
home = {
|
||||||
|
sessionVariables.ZK_PATH = cfg.path;
|
||||||
|
packages = [
|
||||||
|
(pkgs.writeShellApplication {
|
||||||
|
name = "zk";
|
||||||
|
runtimeInputs = with pkgs; [ tmux ];
|
||||||
|
text = builtins.readFile ./scripts/zk.sh;
|
||||||
|
})
|
||||||
|
|
||||||
|
(pkgs.writeShellApplication {
|
||||||
|
name = "save-zk";
|
||||||
|
runtimeInputs = with pkgs; [ git ];
|
||||||
|
text = builtins.readFile ./scripts/save-zk.sh;
|
||||||
|
})
|
||||||
|
|
||||||
|
(pkgs.writeShellApplication {
|
||||||
|
name = "setup-zk";
|
||||||
|
runtimeInputs = with pkgs; [ gh ];
|
||||||
|
text = builtins.readFile ./scripts/setup-zk.sh;
|
||||||
|
})
|
||||||
|
];
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
||||||
2
home/modules/zk/scripts/save-zk.sh
Normal file
2
home/modules/zk/scripts/save-zk.sh
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
cd "$ZK_PATH" || { echo "No zettelkasten directory found"; exit 1; }
|
||||||
|
git add . && git commit -m "Update" && git push
|
||||||
13
home/modules/zk/scripts/setup-zk.sh
Normal file
13
home/modules/zk/scripts/setup-zk.sh
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
if [ ! -d "$ZK_PATH" ]; then
|
||||||
|
echo "[zk] Setting up zettelkasten"
|
||||||
|
gh repo clone zk "$ZK_PATH"
|
||||||
|
else
|
||||||
|
echo "[zk] Zettelkasten already set up."
|
||||||
|
fi
|
||||||
|
|
||||||
|
read -p "Would you like open your zettelkasten? [y/N] " -n 1 -r
|
||||||
|
echo
|
||||||
|
|
||||||
|
if [[ $REPLY =~ ^[Yy]$ ]]; then
|
||||||
|
$EDITOR "$ZK_PATH"
|
||||||
|
fi
|
||||||
12
dots/.bin/zk → home/modules/zk/scripts/zk.sh
Executable file → Normal file
12
dots/.bin/zk → home/modules/zk/scripts/zk.sh
Executable file → Normal file
@@ -1,8 +1,6 @@
|
|||||||
#!/usr/bin/env bash
|
|
||||||
|
|
||||||
current_zettel_path="$ZK_PATH/$(cat "$ZK_PATH/current-zettel.txt")"
|
current_zettel_path="$ZK_PATH/$(cat "$ZK_PATH/current-zettel.txt")"
|
||||||
|
|
||||||
if [ "$TERM_PROGRAM" = tmux ]; then
|
if [ -n "${TMUX:-}" ]; then
|
||||||
cd "$ZK_PATH" && $EDITOR "$current_zettel_path"
|
cd "$ZK_PATH" && $EDITOR "$current_zettel_path"
|
||||||
else
|
else
|
||||||
echo 'Not in tmux'
|
echo 'Not in tmux'
|
||||||
@@ -12,13 +10,9 @@ else
|
|||||||
read -r -p 'Enter your choice: ' choice
|
read -r -p 'Enter your choice: ' choice
|
||||||
case $choice in
|
case $choice in
|
||||||
1)
|
1)
|
||||||
# Check if a tmux session is running with a window named zk
|
if tmux has-session -t zk 2>/dev/null; then
|
||||||
if tmux list-windows -F '#{window_name}' | grep -q zk; then
|
tmux attach -t zk
|
||||||
# Attach to the session containing the 'zk' window
|
|
||||||
session="$(tmux list-windows -F '#{window_name} #{session_name}' | grep zk | head -n 1 | awk '{ print $2 }')"
|
|
||||||
tmux attach -t "$session"
|
|
||||||
else
|
else
|
||||||
# Create session with a window named 'zk' and start nvim
|
|
||||||
tmux new-session -s zk -n zk -d
|
tmux new-session -s zk -n zk -d
|
||||||
tmux send-keys -t zk:zk "cd $ZK_PATH && $EDITOR $current_zettel_path" Enter
|
tmux send-keys -t zk:zk "cd $ZK_PATH && $EDITOR $current_zettel_path" Enter
|
||||||
tmux attach -t zk
|
tmux attach -t zk
|
||||||
Reference in New Issue
Block a user