lots of changes :D

This commit is contained in:
Solomon Laing 2025-05-26 17:07:49 +09:30
parent 512177fd3d
commit e46d491826
7 changed files with 298 additions and 33 deletions

View File

@ -1,33 +1,33 @@
return {
{
"mickael-menu/zk-nvim",
enabled = true,
event = "VeryLazy",
opts = {
picker = "telescope",
},
config = function(_, opts)
require("zk").setup(opts)
local function yankName(options, picker_options)
require("zk").pick_notes(options, picker_options, function(notes)
local pos = vim.api.nvim_win_get_cursor(0)[2]
local line = vim.api.nvim_get_current_line()
if picker_options.multi_select == false then
notes = { notes }
end
for _, note in ipairs(notes) do
-- stylua: ignore
local nline = line:sub(0, pos) .. note.title .. " - " .. note.path .. line:sub(pos + 1)
vim.api.nvim_set_current_line(nline)
end
end)
end
require("zk.commands").add("ZkInsertLink", function(options)
yankName(options, { title = "Zk Yank" })
end)
end,
},
-- {
-- "mickael-menu/zk-nvim",
-- enabled = true,
-- event = "VeryLazy",
-- opts = {
-- picker = "telescope",
-- },
-- config = function(_, opts)
-- require("zk").setup(opts)
--
-- local function yankName(options, picker_options)
-- require("zk").pick_notes(options, picker_options, function(notes)
-- local pos = vim.api.nvim_win_get_cursor(0)[2]
-- local line = vim.api.nvim_get_current_line()
--
-- if picker_options.multi_select == false then
-- notes = { notes }
-- end
-- for _, note in ipairs(notes) do
-- -- stylua: ignore
-- local nline = line:sub(0, pos) .. note.title .. " - " .. note.path .. line:sub(pos + 1)
-- vim.api.nvim_set_current_line(nline)
-- end
-- end)
-- end
--
-- require("zk.commands").add("ZkInsertLink", function(options)
-- yankName(options, { title = "Zk Yank" })
-- end)
-- end,
-- },
}

View File

@ -22,7 +22,7 @@ export npm_config_prefix="$HOME/.local"
export EDITOR="nvim"
export EDITOR_SECONDARY="emacs"
export TERMINAL="st"
export BROWSER="firefox-bin"
export BROWSER="firefox"
# ~/ Clean-up:
export XDG_CONFIG_HOME="$HOME/.config"

16
.local/bin/dmenumusic Executable file
View File

@ -0,0 +1,16 @@
#!/usr/bin/env bash
# thanks bread
#---
# relative path to mpd's music directory *must* be used. absolute path will not be read by mpd.
# mpd also seems picky about special characters in filenames.
#file=$(find $HOME/music -type f -name "*.mp3" | sort | sed !s|^$HOME/music/||" | dmenu) || exit 0
file=$(fd .mp3 $HOME/music -p -t f | sort | sed "s|^$HOME/music/||" | dmenu) || exit 0
echo "$file"
notify-send "Playing $file" && mpc insert "$file" && mpc next >/dev/null && mpc play >/dev/null

26
.local/bin/linkhandler Executable file
View File

@ -0,0 +1,26 @@
#!/bin/sh
# Feed script a url or file location.
# If an image, it will view in nsxiv,
# if a video or gif, it will view in mpv
# if a music file or pdf, it will download,
# otherwise it opens link in browser.
if [ -z "$1" ]; then
url="$(xclip -o)"
else
url="$1"
fi
case "$url" in
*mkv|*webm|*mp4|*youtube.com/watch*|*youtube.com/playlist*|*youtube.com/shorts*|*youtu.be*|*hooktube.com*|*bitchute.com*|*videos.lukesmith.xyz*|*odysee.com*)
setsid -f mpv -quiet "$url" >/dev/null 2>&1 ;;
*png|*jpg|*jpe|*jpeg|*gif|*webp)
curl -sL "$url" > "/tmp/$(echo "$url" | sed "s/.*\///;s/%20/ /g")" && nsxiv -a "/tmp/$(echo "$url" | sed "s/.*\///;s/%20/ /g")" >/dev/null 2>&1 & ;;
*pdf|*cbz|*cbr)
curl -sL "$url" > "/tmp/$(echo "$url" | sed "s/.*\///;s/%20/ /g")" && zathura "/tmp/$(echo "$url" | sed "s/.*\///;s/%20/ /g")" >/dev/null 2>&1 & ;;
*mp3|*flac|*opus|*mp3?source*)
qndl "$url" 'curl -LO' >/dev/null 2>&1 ;;
*)
[ -f "$url" ] && setsid -f "$TERMINAL" -e "$EDITOR" "$url" >/dev/null 2>&1 || setsid -f "$BROWSER" "$url" >/dev/null 2>&1
esac

7
.local/bin/plumbpls Executable file
View File

@ -0,0 +1,7 @@
#!/usr/bin/env bash
pidof -s plumber || plumber
val=$(xclip -o)
plumb "$val"

View File

@ -23,7 +23,7 @@ lock(){
kill -44 $(pidof dwmblocks)
}
case "$(printf "lock\nleave $WM\nrenew $WM\nhibernate\nreboot\nhutdown\nsleep\ndisplay off" | dmenu -i -p 'Action: ')" in
case "$(printf "lock\nleave $WM\nrenew $WM\nhibernate\nreboot\nshutdown\nsleep\ndisplay off" | dmenu -i -p 'Action: ')" in
'lock') lock ;;
"leave $WM") kill -TERM "$(wmpid)" ;;
"renew $WM") kill -HUP "$(wmpid)" ;;

216
lib/plumbing Normal file
View File

@ -0,0 +1,216 @@
# these are generally in order from most specific to least,
# since first rule that fires wins.
include fileaddr
# declarations of ports without rules
plumb to seemail
plumb to showmail
# should deal with all videos etc
type is text
data matches '(gopher|https?)://.*\.(mkv|mp4|avi|webm|ogg|ogv|gifv|mp3|mp4|opus|flac|ape)'
plumb start mpv --no-terminal $0
# youtube and similar services
type is text
data matches 'https?://(www\.)?(gfycat\.|youtube\.|youtu\.be|vimeo\.com|twitter\.com/i/videos|bandcamp\.com|invidio\.us|bitchute\.com|lbry\.tv|redgifs\.com)[a-zA-Z0-9_@\-:]*([.:][a-zA-Z0-9_@\-]+)*/?[a-zA-Z0-9_?,%#~&/\-+=]+([:.][a-zA-Z0-9_?,%#~&/\-+=]+)*'
plumb to web
plumb start mpv --no-terminal $0
type is text
data matches 'https://doi.org/.*'
plumb to web
plumb start surf_tor sci-hub.tw/$0
type is text
data matches '(gopher|https?)://[a-zA-Z0-9_@\-]+([.:][a-zA-Z0-9_@\-]+)*/?[a-zA-Z0-9_?,%#~&/\-+=]+([:.][a-zA-Z0-9_?,%#~&/\-+=]+)*\.(txt|log|sh|TXT|LOG|SH)$'
plumb start sh -c 'curl -H 'User-Agent:' -sL '$0' | tr -d $"\r" | plumb -i -d edit -a ''action=showdata filename=/url/'$0'''
type is text
data matches 'https?://(www\.)?(imgur\.com)[a-zA-Z0-9_@\-]*([.:][a-zA-Z0-9_@\-]+)*/?[a-zA-Z0-9_?,%#~&/\-+=]+([:.][a-zA-Z0-9_?,%#~&/\-+=]+)*'
plumb to web
plumb start sh -c 'links="$(albumrip '$0')"; for link in $links; do mkdir -p /tmp/imgur/; tmp=$(mktemp /tmp/imgur/XXXX); curl -x socks5h://localhost:9050 -s $link > $tmp && echo $tmp; done| sxiv -i && rm /tmp/imgur/*'
type is text
data matches '(gopher|https?)://[a-zA-Z0-9_@\-]+([.:][a-zA-Z0-9_@\-]+)*/?[a-zA-Z0-9_?,%#~&/\-+=]+([:.][a-zA-Z0-9_?,%#~&/\-+=]+)*\.(jpe?g|JPE?G|gif|GIF|tiff?|TIFF?|ppm|bit|png|PNG)(\?[a-zA-Z0-9_@\-&]*)?'
plumb start sh -c 'tmp=$(mktemp); curl -H 'User-Agent:' -sL '$0' > $tmp ;nsxiv $tmp; rm $tmp'
# magnet links
type is text
data matches 'magnet:\?xt=.*'
plumb to web
plumb start sh -c 'qbittorrent $(echo "'$0'" | sed -E "s/dn=.*/dn=ab/g")'
# urls go to web browser
type is text
data matches '(https?|ftp|file|news|nntp|telnet|wais|prospero)://[a-zA-Z0-9_@\-]+([.:][a-zA-Z0-9_@\-()]+)*/?[a-zA-Z0-9_?,%#;~&/\-+=()]+([:.][a-zA-Z0-9_?,%#;~&/\-+=()]+)*'
plumb to web
plumb start firefox $0
type is text
data matches 'gopher://[a-zA-Z0-9_@\-]+([.:][a-zA-Z0-9_@\-()]+)*/?[a-zA-Z0-9_?,%#;~&/\-+=()]+([:.][a-zA-Z0-9_?,%#;~&/\-+=()]+)*'
plumb to web
plumb start firefox $0
type is text
data matches '.*\.html?'
arg isfile $0
plumb to web
plumb start firefox $file
# doc and rtf files go to wdoc2txt
type is text
data matches '[a-zA-Z¡-￿0-9_\-./]+'
data matches '([a-zA-Z¡-￿0-9_\-./]+)\.(doc|rtf)'
arg isfile $0
plumb to msword
plumb start loffice $file
# start rule for microsoft word documents without .doc suffix
type is text
dst is msword
plumb to msword
plumb start loffice $file
# image files go to sxiv
type is text
data matches '[a-zA-Z¡-￿0-9_\-./]+'
data matches '([a-zA-Z¡-￿0-9_\-./]+)\.(jpe?g|JPE?G|gif|GIF|tiff?|TIFF?|ppm|bit|png|PNG)'
arg isfile $0
plumb to image
plumb start nsxiv $file
type is text
data matches '.*\.(mkv|avi|webm|ogg|ogv|gifv|mp3|mp4|opus|flac|ape)'
arg isfile $0
plumb to pager
plumb start mpv --no-terminal $file
# image files go to sxiv
type is text
data matches 'file://(([a-zA-Z¡-￿0-9_\-./]+)\.(jpe?g|JPE?G|gif|GIF|tiff?|TIFF?|ppm|bit|png|PNG))'
arg isfile $1
plumb to image
plumb start nsxiv $file
# postscript/pdf/dvi/epub go to zathura but not over the a plumb port
# the port is here for reference but is unused
type is text
data matches '.*\.(EPUB|epub|ps|PS|eps|EPS|pdf|PDF|dvi|DVI|djvu|DJVU)'
arg isfile $0
plumb to pager
plumb start zathura $file
# existing files tagged by line number:columnumber or linenumber.columnumber, twice, go to editor
type is text
data matches '([.a-zA-Z¡-￿0-9_/\-]*[a-zA-Z¡-￿0-9_/\-])':$twocolonaddr,$twocolonaddr
arg isfile $1
data set $file
attr add addr=$2-#1+#$3,$4-#1+#$5
plumb to edit
plumb client $editor
# existing files tagged by line number:columnumber or linenumber.columnumber, twice, go to editor
type is text
data matches '([.a-zA-Z¡-￿0-9_/\-]*[a-zA-Z¡-￿0-9_/\-])':$twocolonaddr
arg isfile $1
data set $file
attr add addr=$2-#1+#$3
plumb to edit
plumb client $editor
# existing files, possibly tagged by line number, go to editor
type is text
data matches '([.a-zA-Z¡-￿0-9_/\-]*[a-zA-Z¡-￿0-9_/\-])('$addr')?'
arg isfile $1
data set $file
attr add addr=$3
plumb to edit
plumb client $editor
# .h files are looked up in /usr/include and passed to edit
type is text
data matches '([a-zA-Z¡-￿0-9/_\-]+\.h)('$addr')?'
arg isfile /usr/include/$1
data set $file
attr add addr=$3
plumb to edit
plumb client $editor
# .h files are looked up in /usr/local/include and passed to edit
type is text
data matches '([a-zA-Z¡-￿0-9/_\-]+\.h)('$addr')?'
arg isfile /usr/local/include/$1
data set $file
attr add addr=$3
plumb to edit
plumb client $editor
# .h files are looked up in $plan9/include and passed to edit
type is text
data matches '([a-zA-Z¡-￿0-9/_\-]+\.h)('$addr')?'
arg isfile $plan9/include/$1
data set $file
attr add addr=$3
plumb to edit
plumb client $editor
# .m files are looked up in /usr/inferno/module and passed to edit
type is text
data matches '([a-zA-Z¡-￿0-9/_\-]+\.m)('$addr')?'
arg isfile /usr/inferno/module/$1
data set $file
attr add addr=$3
plumb to edit
plumb client st $editor
# faces -> new mail window for message
type is text
data matches '[a-zA-Z¡-￿0-9_\-./]+'
data matches '/mail/fs/[a-zA-Z¡-￿0-9/]+/[0-9]+'
plumb to showmail
plumb start window -r 4 120 750 600 upas/nedmail -s $0
# email addresses get a new mail window
type is text
data matches '(mailto:)?([a-zA-Z0-9_+.\-]+@[a-zA-Z0-9_+.\-]*)'
plumb to sendmail
plumb start st mutt $0
# plumb start window rc -c '''echo % mail '''$0'; mail '$0
# man index entries are synthesized
type is text
data matches '9([a-zA-Z¡-￿0-9_\-./]+)\(([1-8])\)'
plumb start 9 rc -c 'man '$2' '$1' | nobs | plumb -i -d edit -a ''action=showdata filename=/9man/'$1'('$2')'''
type is text
data matches '([a-zA-Z¡-￿0-9_\-./]+)\(([1-8])\)'
plumb start sh -c 'MANWIDTH=71 man '$2' '$1' | nobs | plumb -i -d edit -a ''action=showdata filename=/man/'$1'('$2')'''
# start rule for images without known suffixes
dst is image
arg isfile $data
plumb to image
plumb start 9 page $data
# start rule for postscript without known suffixes
dst is postscript
arg isfile $data
plumb start 9 page $data
# relative files as file: urls get made into absolute paths
type is text
data matches 'file:([.a-zA-Z¡-￿0-9_\-]([.a-zA-Z¡-￿0-9_/\-]*[a-zA-Z¡-￿0-9_/\-]))?'
arg isfile $1
data set file://$file
plumb start plumb $data
type is text
data matches 'file://(.*)'
arg isfile $1
plumb start plumb $1
type is text
data matches '.*\..*'
plumb start glinks $0