playing with filechooser
This commit is contained in:
parent
421f5070ab
commit
71cdb129d5
7 changed files with 139 additions and 40 deletions
6
flake.lock
generated
6
flake.lock
generated
|
@ -89,11 +89,11 @@
|
|||
"nixpkgs-stable": "nixpkgs-stable"
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1749060905,
|
||||
"narHash": "sha256-VPQgUnIeXsLnmUK5izlRr62HG4Bhrq9yH6hehmLTp9I=",
|
||||
"lastModified": 1749086887,
|
||||
"narHash": "sha256-ACs4F2QdKuwGF81P2gOjL0ZkYD4rvBhiR4dSqeJnDHs=",
|
||||
"owner": "nix-community",
|
||||
"repo": "emacs-overlay",
|
||||
"rev": "233041cb05a8cb5c346c6c4e3991e5111de83efe",
|
||||
"rev": "13fae16b4ff8b0d1ea11c0a173975d5a47089446",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
|
|
|
@ -1,5 +0,0 @@
|
|||
[default]
|
||||
mode = "fit"
|
||||
|
||||
[any]
|
||||
path = "/home/emenel/.local/wallpapers/crt1.jpg"
|
|
@ -266,7 +266,11 @@
|
|||
|
||||
xdg.portal = {
|
||||
enable = true;
|
||||
xdgOpenUsePortal = true;
|
||||
xdgOpenUsePortal = false; #true;
|
||||
config = {
|
||||
common.default = [ "niri" ];
|
||||
common."org.freedesktop.impl.portal.FileChooser" = [ "termfilechooser" ]; # xdg-?
|
||||
};
|
||||
extraPortals = [
|
||||
pkgs.xdg-desktop-portal-gnome
|
||||
pkgs.xdg-desktop-portal-gtk
|
||||
|
|
|
@ -150,7 +150,7 @@
|
|||
mangohud
|
||||
dualsensectl.out
|
||||
|
||||
wpaperd
|
||||
# wpaperd
|
||||
|
||||
# inputs.xwayland-satellite.packages.x86_64-linux.default
|
||||
];
|
||||
|
@ -226,9 +226,20 @@
|
|||
tray = "always";
|
||||
notify = false;
|
||||
};
|
||||
wpaperd = {
|
||||
enable = true;
|
||||
settings = {
|
||||
default = {
|
||||
mode = "fit";
|
||||
};
|
||||
any = {
|
||||
path = "/home/emenel/.local/wallpapers/crt1.jpg";
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
xdg.configFile."wpaperd/config.toml".source = ../../homes/emenel/dotfiles/dot_config/wpaperd/config.toml;
|
||||
# xdg.configFile."wpaperd/config.toml".source = ../../homes/emenel/dotfiles/dot_config/wpaperd/config.toml;
|
||||
home.file.".local/wallpapers".source = ../../assets/wallpapers;
|
||||
|
||||
# xdg.mime = {
|
||||
|
@ -250,6 +261,27 @@
|
|||
# };
|
||||
# };
|
||||
|
||||
# xdg.portal = {
|
||||
# enable = true;
|
||||
# configPackages = [ pkgs.niri-unstable ];
|
||||
# extraPortals = with pkgs; [
|
||||
# xdg-desktop-portal-gnome
|
||||
# xdg-desktop-portal-gtk
|
||||
# xdg-desktop-portal
|
||||
# xdg-desktop-portal-wlr
|
||||
# gnome-keyring
|
||||
# xdg-desktop-portal-termfilechooser
|
||||
# ];
|
||||
# config = {
|
||||
# common = {
|
||||
# default = [ "gtk" ];
|
||||
# "org.freedesktop.impl.portal.FileChooser" = "termfilechooser";
|
||||
# };
|
||||
# };
|
||||
# };
|
||||
|
||||
# home.sessionVariables.TERMCMD = "wezterm --class=file_chooser";
|
||||
|
||||
xdg.desktopEntries = {
|
||||
rmpc = {
|
||||
name = "rmpc (music player)";
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
### $XDG_CONFIG_HOME/xdg-desktop-portal-termfilechooser/config ###
|
||||
|
||||
[filechooser]
|
||||
cmd=yazi-wrapper.sh
|
||||
cmd=$HOME/.config/xdg-desktop-portal-termfilechooser/yazi-wrapper.sh
|
||||
default_dir=$HOME
|
||||
env=TERMCMD= wezlauncher
|
||||
env=TERMCMD=$HOME/.local/bin/wezlauncher
|
||||
|
|
|
@ -1,40 +1,108 @@
|
|||
#!/bin/sh
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -x
|
||||
|
||||
# This wrapper script is invoked by xdg-desktop-portal-termfilechooser.
|
||||
#
|
||||
# For more information about input/output arguments read `xdg-desktop-portal-termfilechooser(5)`
|
||||
|
||||
set -ex
|
||||
PATH="/usr/bin:/bin"
|
||||
# Inputs:
|
||||
# 1. "1" if multiple files can be chosen, "0" otherwise.
|
||||
# 2. "1" if a directory should be chosen, "0" otherwise.
|
||||
# 3. "0" if opening files was requested, "1" if writing to a file was
|
||||
# requested. For example, when uploading files in Firefox, this will be "0".
|
||||
# When saving a web page in Firefox, this will be "1".
|
||||
# 4. If writing to a file, this is recommended path provided by the caller. For
|
||||
# example, when saving a web page in Firefox, this will be the recommended
|
||||
# path Firefox provided, such as "~/Downloads/webpage_title.html".
|
||||
# Note that if the path already exists, we keep appending "_" to it until we
|
||||
# get a path that does not exist.
|
||||
# 5. The output path, to which results should be written.
|
||||
#
|
||||
# Output:
|
||||
# The script should print the selected paths to the output path (argument #5),
|
||||
# one path per line.
|
||||
# If nothing is printed, then the operation is assumed to have been canceled.
|
||||
|
||||
multiple="$1"
|
||||
directory="$2"
|
||||
|
||||
save="$3"
|
||||
path="$4"
|
||||
out="$5"
|
||||
|
||||
cmd="yazi"
|
||||
termcmd="${TERMCMD:-wezlauncher ''}"
|
||||
|
||||
cmd="/etc/profiles/per-user/emenel/bin/yazi"
|
||||
# "wezterm start --always-new-process" if you use wezterm
|
||||
if [ "$save" = "1" ]; then
|
||||
# save a file
|
||||
set -- --chooser-file="$out" "$path"
|
||||
TITLE="Save File:"
|
||||
elif [ "$directory" = "1" ]; then
|
||||
# upload files from a directory
|
||||
set -- --chooser-file="$out" --cwd-file="$out" "$path"
|
||||
elif [ "$multiple" = "1" ]; then
|
||||
# upload multiple files
|
||||
set -- --chooser-file="$out" "$path"
|
||||
TITLE="Select Directory:"
|
||||
else
|
||||
# upload only 1 file
|
||||
set -- --chooser-file="$out" "$path"
|
||||
TITLE="Select File:"
|
||||
fi
|
||||
|
||||
command="$termcmd $cmd"
|
||||
for arg in "$@"; do
|
||||
# escape double quotes
|
||||
escaped=$(printf "%s" "$arg" | sed 's/"/\\"/g')
|
||||
# escape spaces
|
||||
command="$command \"$escaped\""
|
||||
done
|
||||
quote_string() {
|
||||
local input="$1"
|
||||
echo "'${input//\'/\'\\\'\'}'"
|
||||
}
|
||||
|
||||
sh -c "$command"
|
||||
termcmd="${TERMCMD:-/etc/profiles/per-user/emenel/bin/wezterm}"
|
||||
|
||||
cleanup() {
|
||||
if [ -f "$tmpfile" ]; then
|
||||
/etc/profiles/per-user/emenel/bin/rm "$tmpfile" || :
|
||||
fi
|
||||
if [ "$save" = "1" ] && [ ! -s "$out" ]; then
|
||||
/etc/profiles/per-user/emenel/bin/rm "$path" || :
|
||||
fi
|
||||
}
|
||||
|
||||
trap cleanup EXIT HUP INT QUIT ABRT TERM
|
||||
|
||||
if [ "$save" = "1" ]; then
|
||||
tmpfile=$(/etc/profiles/per-user/emenel/bin/mktemp)
|
||||
|
||||
# Save/download file
|
||||
/etc/profiles/per-user/emenel/bin/printf '%s' 'xdg-desktop-portal-termfilechooser saving files tutorial
|
||||
|
||||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
!!! === WARNING! === !!!
|
||||
!!! The contents of *whatever* file you open last in !!!
|
||||
!!! yazi will be *overwritten*! !!!
|
||||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
|
||||
Instructions:
|
||||
1) Move this file wherever you want.
|
||||
2) Rename the file if needed.
|
||||
3) Confirm your selection by opening the file, for
|
||||
example by pressing <Enter>.
|
||||
|
||||
Notes:
|
||||
1) This file is provided for your convenience. You can
|
||||
only choose this placeholder file otherwise the save operation aborted.
|
||||
2) If you quit yazi without opening a file, this file
|
||||
will be removed and the save operation aborted.
|
||||
' >"$path"
|
||||
set -- --chooser-file="$(quote_string "$tmpfile")" "$(quote_string "$path")"
|
||||
elif [ "$directory" = "1" ]; then
|
||||
# upload files from a directory
|
||||
# Use this if you want to select folder by 'quit' function in yazi.
|
||||
set -- --cwd-file="$(quote_string "$out")" "$(quote_string "$path")"
|
||||
# NOTE: Use this if you want to select folder by enter a.k.a yazi keybind for 'open' funtion ('run = "open") .
|
||||
# set -- --chooser-file="$out" "$path"
|
||||
elif [ "$multiple" = "1" ]; then
|
||||
# upload multiple files
|
||||
set -- --chooser-file="$(quote_string "$out")" "$(quote_string "$path")"
|
||||
else
|
||||
# upload only 1 file
|
||||
set -- --chooser-file="$(quote_string "$out")" "$(quote_string "$path")"
|
||||
fi
|
||||
|
||||
eval "$termcmd -- $cmd $@"
|
||||
|
||||
# case save file
|
||||
if [ "$save" = "1" ] && [ -s "$tmpfile" ]; then
|
||||
selected_file=$(/etc/profiles/per-user/emenel/bin/head -n 1 "$tmpfile")
|
||||
# Check if selected file is placeholder file
|
||||
if [ -f "$selected_file" ] && /etc/profiles/per-user/emenel/bin/grep -qi "^xdg-desktop-portal-termfilechooser saving files tutorial" "$selected_file"; then
|
||||
/etc/profiles/per-user/emenel/bin/echo "$selected_file" >"$out"
|
||||
path="$selected_file"
|
||||
fi
|
||||
fi
|
||||
|
|
|
@ -179,5 +179,5 @@
|
|||
xdg.configFile."yazi/theme.toml".source = ./yazi/theme.toml;
|
||||
xdg.configFile."yazi/flavors".source = ./yazi/flavors;
|
||||
xdg.configFile."xdg-desktop-portal-termfilechooser/config".source = ./file-chooser/config;
|
||||
home.file.".local/bin/yazi-wrapper.sh".source = ./file-chooser/yazi-wrapper.sh;
|
||||
xdg.configFile."xdg-desktop-portal-termfilechooser/yazi-wrapper.sh".source = ./file-chooser/yazi-wrapper.sh;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue