Cleanup Joshuto config
This commit is contained in:
parent
e02aaf916c
commit
e6d09891c0
6 changed files with 130 additions and 104 deletions
|
|
@ -89,94 +89,6 @@ in {
|
|||
enableZshIntegration = true;
|
||||
nix-direnv.enable = true;
|
||||
};
|
||||
joshuto = {
|
||||
enable = true;
|
||||
package = with pkgs;
|
||||
writeShellScriptBin "joshuto" ''
|
||||
export joshuto_wrap_id="$$"
|
||||
export joshuto_wrap_tmp="$(mktemp -d -t joshuto-wrap-$joshuto_wrap_id-XXXXXX)"
|
||||
export joshuto_wrap_preview_meta="$joshuto_wrap_tmp/preview-meta"
|
||||
export ueberzug_pid_file="$joshuto_wrap_tmp/pid"
|
||||
export ueberzug_img_identifier="preview"
|
||||
export ueberzug_socket=""
|
||||
export ueberzug_pid=""
|
||||
|
||||
function start_ueberzugpp {
|
||||
## Adapt Überzug++ options here. For example, remove the '--no-opencv' or set another output method.
|
||||
${ueberzugpp}/bin/ueberzug layer --no-stdin --pid-file "$ueberzug_pid_file" --no-opencv &>/dev/null
|
||||
export ueberzug_pid="$(cat "$ueberzug_pid_file")"
|
||||
export ueberzug_socket=/tmp/ueberzugpp-"$ueberzug_pid".socket
|
||||
mkdir -p "$joshuto_wrap_preview_meta"
|
||||
}
|
||||
|
||||
function stop_ueberzugpp {
|
||||
remove_image
|
||||
${ueberzugpp}/bin/ueberzug cmd -s "$ueberzug_socket" -a exit
|
||||
kill "$ueberzug_pid"
|
||||
rm -rf "$joshuto_wrap_tmp"
|
||||
}
|
||||
|
||||
function show_image {
|
||||
${ueberzugpp}/bin/ueberzug cmd -s "$ueberzug_socket" -a add -i "$ueberzug_img_identifier" -x "$2" -y "$3" --max-width "$4" --max-height "$5" -f "$1" &>/dev/null
|
||||
}
|
||||
|
||||
function remove_image {
|
||||
${ueberzugpp}/bin/ueberzug cmd -s "$ueberzug_socket" -a remove -i "$ueberzug_img_identifier" &>/dev/null
|
||||
}
|
||||
|
||||
function get_preview_meta_file {
|
||||
echo "$joshuto_wrap_preview_meta/$(echo "$1" | md5sum | sed 's/ //g')"
|
||||
}
|
||||
|
||||
export -f get_preview_meta_file
|
||||
export -f show_image
|
||||
export -f remove_image
|
||||
|
||||
if [ -n "$DISPLAY" ] && command -v ${ueberzugpp}/bin/ueberzug > /dev/null; then
|
||||
trap stop_ueberzugpp EXIT QUIT INT TERM
|
||||
start_ueberzugpp
|
||||
fi
|
||||
|
||||
${joshuto}/bin/joshuto "$@"
|
||||
exit $?
|
||||
'';
|
||||
settings = {
|
||||
xdg_open = true;
|
||||
xdg_open_fork = true;
|
||||
display = { show_icons = true; };
|
||||
# preview.preview_protocol = "kitty";
|
||||
preview.preview_script = ./files/joshuo_preview_file.sh;
|
||||
preview.preview_shown_hook_script = with pkgs;
|
||||
writeScript "on_preview_shown" ''
|
||||
#!/usr/bin/env bash
|
||||
test -z "$joshuto_wrap_id" && exit 1;
|
||||
|
||||
path="$1" # Full path of the previewed file
|
||||
x="$2" # x coordinate of upper left cell of preview area
|
||||
y="$3" # y coordinate of upper left cell of preview area
|
||||
width="$4" # Width of the preview pane (number of fitting characters)
|
||||
height="$5" # Height of the preview pane (number of fitting characters)
|
||||
|
||||
# Find out mimetype and extension
|
||||
mimetype=$(${file}/bin/file --mime-type -Lb "$path")
|
||||
extension=$(echo "''${path##*.}" | awk '{print tolower($0)}')
|
||||
|
||||
case "$mimetype" in
|
||||
image/png | image/jpeg)
|
||||
show_image "$path" $x $y $width $height
|
||||
;;
|
||||
*)
|
||||
remove_image
|
||||
|
||||
esac
|
||||
'';
|
||||
preview.preview_removed_hook_script =
|
||||
pkgs.writeScript "on_preview_removed" ''
|
||||
#!/usr/bin/env bash
|
||||
test -z "$joshuto_wrap_id" && exit 1;
|
||||
remove_image'';
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
xdg.desktopEntries = {
|
||||
|
|
@ -240,20 +152,6 @@ in {
|
|||
xorg.xwininfo
|
||||
xorg.xkill
|
||||
|
||||
# Joshuto preview utils
|
||||
file
|
||||
catdoc
|
||||
pandoc
|
||||
mu
|
||||
djvulibre
|
||||
exiftool
|
||||
mediainfo
|
||||
atool
|
||||
gnutar
|
||||
poppler_utils
|
||||
libtransmission
|
||||
w3m
|
||||
|
||||
brave
|
||||
keepassxc
|
||||
krita
|
||||
|
|
|
|||
|
|
@ -1,5 +1,3 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
## This script is a template script for creating textual file previews in Joshuto.
|
||||
##
|
||||
## Copy this script to your Joshuto configuration directory and refer to this
|
||||
|
|
@ -61,6 +59,7 @@ while [ "$#" -gt 0 ]; do
|
|||
;;
|
||||
"--preview-height")
|
||||
shift
|
||||
# shellcheck disable=SC2034
|
||||
PREVIEW_HEIGHT="$1"
|
||||
;;
|
||||
esac
|
||||
53
modules/desktop/files/joshuto_wrapper.sh
Normal file
53
modules/desktop/files/joshuto_wrapper.sh
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
export joshuto_wrap_id="$$"
|
||||
joshuto_wrap_tmp="$(mktemp -d -t joshuto-wrap-$joshuto_wrap_id-XXXXXX)"
|
||||
export joshuto_wrap_tmp
|
||||
export joshuto_wrap_preview_meta="$joshuto_wrap_tmp/preview-meta"
|
||||
export ueberzug_pid_file="$joshuto_wrap_tmp/pid"
|
||||
export ueberzug_img_identifier="preview"
|
||||
export ueberzug_socket=""
|
||||
export ueberzug_pid=""
|
||||
|
||||
# shellcheck disable=SC2317
|
||||
function start_ueberzugpp {
|
||||
## Adapt Überzug++ options here. For example, remove the '--no-opencv' or set another output method.
|
||||
ueberzug layer --no-stdin --pid-file "$ueberzug_pid_file" --no-opencv &>/dev/null
|
||||
ueberzug_pid="$(cat "$ueberzug_pid_file")"
|
||||
export ueberzug_pid
|
||||
export ueberzug_socket=/tmp/ueberzugpp-"$ueberzug_pid".socket
|
||||
mkdir -p "$joshuto_wrap_preview_meta"
|
||||
}
|
||||
|
||||
# shellcheck disable=SC2317
|
||||
function stop_ueberzugpp {
|
||||
remove_image
|
||||
ueberzug cmd -s "$ueberzug_socket" -a exit
|
||||
kill "$ueberzug_pid"
|
||||
rm -rf "$joshuto_wrap_tmp"
|
||||
}
|
||||
|
||||
# shellcheck disable=SC2317
|
||||
function show_image {
|
||||
ueberzug cmd -s "$ueberzug_socket" -a add -i "$ueberzug_img_identifier" -x "$2" -y "$3" --max-width "$4" --max-height "$5" -f "$1" &>/dev/null
|
||||
}
|
||||
|
||||
# shellcheck disable=SC2317
|
||||
function remove_image {
|
||||
ueberzug cmd -s "$ueberzug_socket" -a remove -i "$ueberzug_img_identifier" &>/dev/null
|
||||
}
|
||||
|
||||
# shellcheck disable=SC2317
|
||||
function get_preview_meta_file {
|
||||
echo "$joshuto_wrap_preview_meta/$(echo "$1" | md5sum | sed 's/ //g')"
|
||||
}
|
||||
|
||||
export -f get_preview_meta_file
|
||||
export -f show_image
|
||||
export -f remove_image
|
||||
|
||||
if [ -n "$DISPLAY" ] && command -v ueberzug > /dev/null; then
|
||||
trap stop_ueberzugpp EXIT QUIT INT TERM
|
||||
start_ueberzugpp
|
||||
fi
|
||||
|
||||
joshuto "$@"
|
||||
exit $?
|
||||
74
modules/desktop/joshuto.nix
Normal file
74
modules/desktop/joshuto.nix
Normal file
|
|
@ -0,0 +1,74 @@
|
|||
{ config, lib, pkgs, ... }:
|
||||
|
||||
with lib;
|
||||
with lib.my;
|
||||
let cfg = config.modules.desktop.joshuto;
|
||||
in {
|
||||
options.modules.desktop.joshuto = { enable = mkBoolOpt false; };
|
||||
config = mkIf cfg.enable {
|
||||
home-manager.users.${config.user.name} = {
|
||||
programs.joshuto = {
|
||||
enable = true;
|
||||
package = with pkgs;
|
||||
writeShellApplication {
|
||||
name = "joshuto";
|
||||
runtimeInputs = [ ueberzugpp joshuto ];
|
||||
text = builtins.readFile ./files/joshuto_wrapper.sh;
|
||||
};
|
||||
settings = {
|
||||
xdg_open = true;
|
||||
xdg_open_fork = true;
|
||||
display = { show_icons = true; };
|
||||
preview.preview_script = with pkgs;
|
||||
"${writeShellApplication {
|
||||
name = "joshuto-preview";
|
||||
runtimeInputs = [
|
||||
file
|
||||
catdoc
|
||||
pandoc
|
||||
mu
|
||||
djvulibre
|
||||
exiftool
|
||||
mediainfo
|
||||
atool
|
||||
gnutar
|
||||
poppler_utils
|
||||
libtransmission
|
||||
w3m
|
||||
];
|
||||
text = builtins.readFile ./files/joshuto_preview_file.sh;
|
||||
}}/bin/joshuto-preview";
|
||||
preview.preview_shown_hook_script = with pkgs;
|
||||
writeScript "on_preview_shown" ''
|
||||
#!/usr/bin/env bash
|
||||
test -z "$joshuto_wrap_id" && exit 1;
|
||||
|
||||
path="$1" # Full path of the previewed file
|
||||
x="$2" # x coordinate of upper left cell of preview area
|
||||
y="$3" # y coordinate of upper left cell of preview area
|
||||
width="$4" # Width of the preview pane (number of fitting characters)
|
||||
height="$5" # Height of the preview pane (number of fitting characters)
|
||||
|
||||
# Find out mimetype and extension
|
||||
mimetype=$(${file}/bin/file --mime-type -Lb "$path")
|
||||
extension=$(echo "''${path##*.}" | awk '{print tolower($0)}')
|
||||
|
||||
case "$mimetype" in
|
||||
image/png | image/jpeg)
|
||||
show_image "$path" $x $y $width $height
|
||||
;;
|
||||
*)
|
||||
remove_image
|
||||
|
||||
esac
|
||||
'';
|
||||
preview.preview_removed_hook_script =
|
||||
pkgs.writeScript "on_preview_removed" ''
|
||||
#!/usr/bin/env bash
|
||||
test -z "$joshuto_wrap_id" && exit 1;
|
||||
remove_image'';
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue