yazi: filechooser
This commit is contained in:
+31
-2
@@ -1,4 +1,4 @@
|
|||||||
{
|
{ pkgs, ... }: {
|
||||||
imports = [
|
imports = [
|
||||||
./host/bluetooth.nix
|
./host/bluetooth.nix
|
||||||
./host/bootloader.nix
|
./host/bootloader.nix
|
||||||
@@ -17,7 +17,36 @@
|
|||||||
./host/yggdrasil.nix
|
./host/yggdrasil.nix
|
||||||
];
|
];
|
||||||
|
|
||||||
programs.hyprland.enable = true;
|
programs = {
|
||||||
|
dconf.enable = true;
|
||||||
|
hyprland.enable = true;
|
||||||
|
};
|
||||||
|
|
||||||
|
xdg.portal = {
|
||||||
|
enable = true;
|
||||||
|
xdgOpenUsePortal = true;
|
||||||
|
|
||||||
|
extraPortals = with pkgs; [
|
||||||
|
xdg-desktop-portal-hyprland
|
||||||
|
xdg-desktop-portal-gtk
|
||||||
|
xdg-desktop-portal-termfilechooser
|
||||||
|
];
|
||||||
|
|
||||||
|
config = {
|
||||||
|
common = {
|
||||||
|
default = [ "hyprland" "gtk" ];
|
||||||
|
"org.freedesktop.impl.portal.FileChooser" = [ "termfilechooser" "gtk" ];
|
||||||
|
"org.freedesktop.impl.portal.Settings" = [ "gtk" ];
|
||||||
|
};
|
||||||
|
|
||||||
|
hyprland = {
|
||||||
|
default = [ "hyprland" "gtk" ];
|
||||||
|
"org.freedesktop.impl.portal.FileChooser" = [ "termfilechooser" "gtk" ];
|
||||||
|
"org.freedesktop.impl.portal.Settings" = [ "gtk" ];
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
services = {
|
services = {
|
||||||
udisks2.enable = true;
|
udisks2.enable = true;
|
||||||
fstrim.enable = true;
|
fstrim.enable = true;
|
||||||
|
|||||||
+10
-3
@@ -1,8 +1,15 @@
|
|||||||
{
|
{ lib, ... }: {
|
||||||
environment.variables = {
|
environment.variables = {
|
||||||
EDITOR = "hx";
|
EDITOR = "hx";
|
||||||
RANGER_LOAD_DEFAULT_RC = "FALSE";
|
RANGER_LOAD_DEFAULT_RC = "FALSE";
|
||||||
QT_QPA_PLATFORMTHEME = "qt5ct";
|
# GTK/Electron apps do not consistently use the portal picker unless this
|
||||||
GSETTINGS_BACKEND = "keyfile";
|
# variable is present in the graphical session environment.
|
||||||
|
GTK_USE_PORTAL = "1";
|
||||||
|
|
||||||
|
# Qt/Telegram-like apps otherwise keep using their own picker. This makes
|
||||||
|
# them ask xdg-desktop-portal for file/folder selection.
|
||||||
|
QT_QPA_PLATFORMTHEME = lib.mkForce "xdgdesktopportal";
|
||||||
|
TDESKTOP_USE_GTK_FILE_DIALOG = "1";
|
||||||
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,6 +41,11 @@ in {
|
|||||||
env = [
|
env = [
|
||||||
"XDG_SESSION_TYPE,wayland"
|
"XDG_SESSION_TYPE,wayland"
|
||||||
"QT_QPA_PLATFORM,wayland"
|
"QT_QPA_PLATFORM,wayland"
|
||||||
|
"QT_QPA_PLATFORMTHEME,xdgdesktopportal"
|
||||||
|
"GTK_USE_PORTAL,1"
|
||||||
|
"TDESKTOP_USE_GTK_FILE_DIALOG,1"
|
||||||
|
"NIXOS_OZONE_WL,1"
|
||||||
|
"ELECTRON_OZONE_PLATFORM_HINT,auto"
|
||||||
|
|
||||||
"XDG_CURRENT_DESKTOP,Hyprland"
|
"XDG_CURRENT_DESKTOP,Hyprland"
|
||||||
"XDG_SESSION_DESKTOP,Hyprland"
|
"XDG_SESSION_DESKTOP,Hyprland"
|
||||||
@@ -115,6 +120,8 @@ in {
|
|||||||
|
|
||||||
exec-once = lib.mkBefore [
|
exec-once = lib.mkBefore [
|
||||||
"systemctl --user start plasma-polkit-agent"
|
"systemctl --user start plasma-polkit-agent"
|
||||||
|
"${lib.getExe' pkgs.dbus "dbus-update-activation-environment"} --systemd --all"
|
||||||
|
"systemctl --user import-environment XDG_CURRENT_DESKTOP XDG_SESSION_DESKTOP XDG_SESSION_TYPE WAYLAND_DISPLAY DISPLAY GTK_USE_PORTAL QT_QPA_PLATFORMTHEME TDESKTOP_USE_GTK_FILE_DIALOG NIXOS_OZONE_WL ELECTRON_OZONE_PLATFORM_HINT"
|
||||||
"awww-daemon"
|
"awww-daemon"
|
||||||
"wl-clip-persist --clipboard both"
|
"wl-clip-persist --clipboard both"
|
||||||
"clipse -listen"
|
"clipse -listen"
|
||||||
@@ -228,11 +235,21 @@ in {
|
|||||||
|
|
||||||
extraPortals = [
|
extraPortals = [
|
||||||
pkgs.xdg-desktop-portal-gtk
|
pkgs.xdg-desktop-portal-gtk
|
||||||
|
pkgs.xdg-desktop-portal-termfilechooser
|
||||||
];
|
];
|
||||||
|
|
||||||
config.common = {
|
config = {
|
||||||
default = [ "hyprland" "gtk" ];
|
common = {
|
||||||
"org.freedesktop.impl.portal.FileChooser" = [ "gtk" ];
|
default = [ "hyprland" "gtk" ];
|
||||||
|
"org.freedesktop.impl.portal.FileChooser" = [ "termfilechooser" "gtk" ];
|
||||||
|
"org.freedesktop.impl.portal.Settings" = [ "gtk" ];
|
||||||
|
};
|
||||||
|
|
||||||
|
hyprland = {
|
||||||
|
default = [ "hyprland" "gtk" ];
|
||||||
|
"org.freedesktop.impl.portal.FileChooser" = [ "termfilechooser" "gtk" ];
|
||||||
|
"org.freedesktop.impl.portal.Settings" = [ "gtk" ];
|
||||||
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
+11
-1
@@ -1,4 +1,14 @@
|
|||||||
{
|
{ lib, ... }: {
|
||||||
|
# Keep qtct/Kvantum for styling, but tell qtct to delegate standard file
|
||||||
|
# dialogs to xdg-desktop-portal. This is what makes AyuGram/Telegram-like Qt
|
||||||
|
# apps use the Yazi picker instead of Qt's built-in dialog.
|
||||||
|
stylix.targets.qt.standardDialogs = "xdgdesktopportal";
|
||||||
|
|
||||||
|
home.sessionVariables = {
|
||||||
|
QT_QPA_PLATFORMTHEME = lib.mkForce "xdgdesktopportal";
|
||||||
|
TDESKTOP_USE_GTK_FILE_DIALOG = "1";
|
||||||
|
};
|
||||||
|
|
||||||
qt = {
|
qt = {
|
||||||
enable = true;
|
enable = true;
|
||||||
platformTheme.name = "qtct";
|
platformTheme.name = "qtct";
|
||||||
|
|||||||
@@ -27,6 +27,61 @@
|
|||||||
exec ${lib.getExe pkgs.ghostty} --title="Yazi" -e ${lib.getExe yaziPkg} "$target"
|
exec ${lib.getExe pkgs.ghostty} --title="Yazi" -e ${lib.getExe yaziPkg} "$target"
|
||||||
'';
|
'';
|
||||||
|
|
||||||
|
yaziFileChooser = pkgs.writeShellScriptBin "yazi-file-chooser" ''
|
||||||
|
set -efu
|
||||||
|
|
||||||
|
directory="''${2:-0}"
|
||||||
|
save="''${3:-0}"
|
||||||
|
path="''${4:-}"
|
||||||
|
out="''${5:?missing termfilechooser output path}"
|
||||||
|
|
||||||
|
state_dir="''${XDG_STATE_HOME:-$HOME/.local/state}/xdg-desktop-portal-termfilechooser"
|
||||||
|
last_selected_path="$state_dir/last-selected"
|
||||||
|
${lib.getExe' pkgs.coreutils "mkdir"} -p "$state_dir"
|
||||||
|
|
||||||
|
if [ -s "$last_selected_path" ]; then
|
||||||
|
IFS= read -r last_selected < "$last_selected_path" || true
|
||||||
|
if [ -d "$last_selected" ]; then
|
||||||
|
if [ "$save" = "1" ] && [ -n "$path" ]; then
|
||||||
|
path="$last_selected/''${path##*/}"
|
||||||
|
else
|
||||||
|
path="$last_selected"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -z "$path" ]; then
|
||||||
|
path="$HOME"
|
||||||
|
fi
|
||||||
|
|
||||||
|
created_placeholder=0
|
||||||
|
if [ "$save" = "1" ] && [ ! -e "$path" ]; then
|
||||||
|
placeholder_dir="''${path%/*}"
|
||||||
|
if [ "$placeholder_dir" != "$path" ]; then
|
||||||
|
${lib.getExe' pkgs.coreutils "mkdir"} -p "$placeholder_dir"
|
||||||
|
fi
|
||||||
|
|
||||||
|
{
|
||||||
|
printf '%s\n' 'This file was created by xdg-desktop-portal-termfilechooser.'
|
||||||
|
printf '%s\n' 'Move/rename it in Yazi, then open/select it to choose the save path.'
|
||||||
|
} > "$path"
|
||||||
|
created_placeholder=1
|
||||||
|
fi
|
||||||
|
|
||||||
|
${lib.getExe pkgs.ghostty} --title="Yazi File Picker" -e ${lib.getExe yaziPkg} --chooser-file="$out" --cwd-file="$last_selected_path" "$path"
|
||||||
|
|
||||||
|
if [ "$directory" = "1" ] && [ ! -s "$out" ] && [ -s "$last_selected_path" ]; then
|
||||||
|
IFS= read -r cwd < "$last_selected_path" || true
|
||||||
|
if [ -n "''${cwd:-}" ] && [ -d "$cwd" ]; then
|
||||||
|
printf '%s\n' "$cwd" > "$out"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "$created_placeholder" = "1" ] && [ ! -s "$out" ]; then
|
||||||
|
${lib.getExe' pkgs.coreutils "rm"} -f "$path"
|
||||||
|
fi
|
||||||
|
'';
|
||||||
|
|
||||||
fileManager1 = pkgs.writeShellScriptBin "yazi-filemanager1" ''
|
fileManager1 = pkgs.writeShellScriptBin "yazi-filemanager1" ''
|
||||||
exec ${pkgs.python3.withPackages (ps: [ ps.dbus-next ])}/bin/python ${pkgs.writeText "yazi-filemanager1.py" ''
|
exec ${pkgs.python3.withPackages (ps: [ ps.dbus-next ])}/bin/python ${pkgs.writeText "yazi-filemanager1.py" ''
|
||||||
import asyncio
|
import asyncio
|
||||||
@@ -97,6 +152,18 @@ in {
|
|||||||
yaziOpen
|
yaziOpen
|
||||||
];
|
];
|
||||||
|
|
||||||
|
home.sessionVariables = {
|
||||||
|
GTK_USE_PORTAL = "1";
|
||||||
|
};
|
||||||
|
|
||||||
|
xdg.configFile."xdg-desktop-portal-termfilechooser/config".text = ''
|
||||||
|
[filechooser]
|
||||||
|
cmd=${lib.getExe yaziFileChooser}
|
||||||
|
default_dir=$HOME
|
||||||
|
open_mode=suggested
|
||||||
|
save_mode=last
|
||||||
|
'';
|
||||||
|
|
||||||
xdg.desktopEntries.yazi = {
|
xdg.desktopEntries.yazi = {
|
||||||
name = "Yazi";
|
name = "Yazi";
|
||||||
genericName = "File Manager";
|
genericName = "File Manager";
|
||||||
@@ -123,6 +190,8 @@ in {
|
|||||||
|
|
||||||
wayland.windowManager.hyprland.settings.windowrule = [
|
wayland.windowManager.hyprland.settings.windowrule = [
|
||||||
"match:class dragon-drop, move cursor_x-window_w/2 cursor_y-window_h/2"
|
"match:class dragon-drop, move cursor_x-window_w/2 cursor_y-window_h/2"
|
||||||
|
"match:title Yazi File Picker, float 1"
|
||||||
|
"match:title Yazi File Picker, size 1200 800"
|
||||||
];
|
];
|
||||||
|
|
||||||
programs.yazi = {
|
programs.yazi = {
|
||||||
|
|||||||
Reference in New Issue
Block a user