summaryrefslogtreecommitdiff
path: root/mut/bin
diff options
context:
space:
mode:
authorMike Vink <mike@pionative.com>2024-04-19 17:39:16 +0200
committerMike Vink <mike@pionative.com>2024-04-19 17:39:16 +0200
commite39341f567c74f88a3610adce25d42e2a3666a91 (patch)
treef12f8cf89eea186c2a005613ff07832169da22da /mut/bin
parent985cac44e0c7b33763d0f9d26842ad5325a4a303 (diff)
update from lemptop
Diffstat (limited to 'mut/bin')
-rwxr-xr-xmut/bin/lfub13
-rwxr-xr-xmut/bin/rotdir12
-rwxr-xr-xmut/bin/vremote50
3 files changed, 52 insertions, 23 deletions
diff --git a/mut/bin/lfub b/mut/bin/lfub
index 894ffde..ffcb52a 100755
--- a/mut/bin/lfub
+++ b/mut/bin/lfub
@@ -3,7 +3,6 @@
# This is a wrapper script for lb that allows it to create image previews with
# ueberzug. This works in concert with the lf configuration file and the
# lf-cleaner script.
-
set -e
cleanup() {
@@ -11,4 +10,14 @@ cleanup() {
rm "$FIFO_UEBERZUG"
}
-lf "$@"
+if [ -n "$SSH_CLIENT" ] || [ -n "$SSH_TTY" ]; then
+ lf "$@"
+else
+ [ ! -d "$HOME/.cache/lf" ] && mkdir -p "$HOME/.cache/lf"
+ export FIFO_UEBERZUG="$HOME/.cache/lf/ueberzug-$$"
+ mkfifo "$FIFO_UEBERZUG"
+ ueberzug layer -s <"$FIFO_UEBERZUG" -p json &
+ exec 3>"$FIFO_UEBERZUG"
+ trap cleanup HUP INT QUIT TERM PWR EXIT
+ lf "$@" 3>&-
+fi
diff --git a/mut/bin/rotdir b/mut/bin/rotdir
new file mode 100755
index 0000000..d171f29
--- /dev/null
+++ b/mut/bin/rotdir
@@ -0,0 +1,12 @@
+#!/bin/sh
+
+# When I open an image from the file manager in nsxiv (the image viewer), I want
+# to be able to press the next/previous keys to key through the rest of the
+# images in the same directory. This script "rotates" the content of a
+# directory based on the first chosen file, so that if I open the 15th image,
+# if I press next, it will go to the 16th etc. Autistic, I know, but this is
+# one of the reasons that nsxiv is great for being able to read standard input.
+
+[ -z "$1" ] && echo "usage: rotdir regex 2>&1" && exit 1
+base="$(basename "$1")"
+ls "$PWD" | awk -v BASE="$base" 'BEGIN { lines = ""; m = 0; } { if ($0 == BASE) { m = 1; } } { if (!m) { if (lines) { lines = lines"\n"; } lines = lines""$0; } else { print $0; } } END { print lines; }'
diff --git a/mut/bin/vremote b/mut/bin/vremote
index 75b404e..4d0d417 100755
--- a/mut/bin/vremote
+++ b/mut/bin/vremote
@@ -3,31 +3,39 @@ if [ -z "$PATH" ]; then
PATH="/etc/profiles/per-user/$USER/bin:/run/current-system/sw/bin:/usr/bin:/bin"
fi
server_pipe="$XDG_CACHE_HOME/nvim/server.pipe"
+if ! [ -e "$server_pipe" ]; then
+ nohup nvim --listen "$server_pipe" --headless >/dev/null 2>&1 &
+fi
+
(
- if ! [ -e "$server_pipe" ]; then
- nohup nvim --listen "$server_pipe" --headless >/dev/null 2>&1 &
+ file_names=()
+ if [ -n "$1" ]; then
+ for file_name in "${@}"; do
+ if [[ "${file_name:0:1}" == / || "${file_name:0:2}" == ~[/a-zA-Z0-9] ]]
+ then
+ file_names+=("$file_name")
+ else
+ file_names+=("${PWD}/$file_name")
+ fi
+ done
+ echo "got file_names: ${file_names[*]}"
fi
- if nvim --headless --server ~/.cache/nvim/server.pipe --remote-expr 'luaeval("vim.json.encode(vim.iter(vim.api.nvim_list_uis()):map(function(v) return v.chan end):totable())")' \
- | jq -r '.[]' \
- | while read -r chan; do
- osascript -e 'display notification "already existing ui('"$chan"')..." with title "vremote"'
- exit 1
- done
+ if ! nvim \
+ --headless \
+ --server ~/.cache/nvim/server.pipe \
+ --remote-expr 'luaeval("vim.json.encode(vim.iter(vim.api.nvim_list_uis()):map(function(v) return v.chan end):totable())")' \
+ | jq -er '.[]'
then
- if [ -n "$1" ]; then
- file_names=()
- for file_name in "${@}"; do
- if [[ "${file_name:0:1}" == / || "${file_name:0:2}" == ~[/a-zA-Z0-9] ]]
- then
- file_names+=("$file_name")
- else
- file_names+=("${PWD}/$file_name")
- fi
- done
- echo "got file_names: ${file_names[*]}"
- nvim --server "$server_pipe" --remote "${file_names[@]}" >/dev/tty
- fi
+ nvim --server "$server_pipe" --remote "${file_names[@]}" >/dev/tty
exec nvim --server "$server_pipe" --remote-ui >/dev/tty
+ else
+ if ! command -v osascript >/dev/null 2>&1; then
+ notify-send "already existing ui
+starting new nvim instance"
+ else
+ osascript -e 'display notification "already existing ui..." with title "vremote"'
+ fi
+ exec nvim "${file_names[@]}" >/dev/tty </dev/tty
fi
) > ~/vremote_logs 2>&1