From cc09b607330385d6d81b9c47cf64a2442432e93f Mon Sep 17 00:00:00 2001 From: Soispha Date: Tue, 20 Feb 2024 16:35:15 +0100 Subject: refactor(treewide): Add a `.sh` extension to shell scripts --- sys/svcs/xdg/default.nix | 2 +- sys/svcs/xdg/scripts/lf_wrapper | 76 -------------------------------------- sys/svcs/xdg/scripts/lf_wrapper.sh | 76 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 77 insertions(+), 77 deletions(-) delete mode 100755 sys/svcs/xdg/scripts/lf_wrapper create mode 100755 sys/svcs/xdg/scripts/lf_wrapper.sh (limited to 'sys/svcs') diff --git a/sys/svcs/xdg/default.nix b/sys/svcs/xdg/default.nix index 513e7a65..3229b97c 100644 --- a/sys/svcs/xdg/default.nix +++ b/sys/svcs/xdg/default.nix @@ -14,7 +14,7 @@ filechooser = { default_dir = "/tmp"; cmd = "${sysLib.writeShellScript { - src = ./scripts/lf_wrapper; + src = ./scripts/lf_wrapper.sh; name = "lf_wrapper"; keepPath = true; dependencies = with pkgs; [ diff --git a/sys/svcs/xdg/scripts/lf_wrapper b/sys/svcs/xdg/scripts/lf_wrapper deleted file mode 100755 index 7a508d39..00000000 --- a/sys/svcs/xdg/scripts/lf_wrapper +++ /dev/null @@ -1,76 +0,0 @@ -#!/usr/bin/env sh - -# This wrapper script is invoked by xdg-desktop-portal-termfilechooser. -# -# 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" -recommended_path="$4" -out="$5" - -# echo > /tmp/stdout -# echo > /tmp/stderr -# -# exec 1>> /tmp/stdout -# exec 2>> /tmp/stderr - -cmd="$(command -v lf)" -termcmd="${TERMINAL:-$(command -v alacritty)}" - -if [ "$save" = "1" ]; then - set -- -selection-path="$out" -command='set promptfmt "Select the file to write to %S \033[32;1m%u@%h\033[0m:\033[34;1m%d\033[0m\033[1m%f\033[0m"' "$recommended_path" - cat << EOF > "$recommended_path" -xdg-desktop-portal-termfilechooser saving files tutorial - -!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -!!! === WARNING! === !!! -!!! The contents of *whatever* file you open last in !!! -!!! lf 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 . - -Notes: -1) This file is provided for your convenience. You - could delete it and choose another file to overwrite - that, for example. -2) If you quit lf without opening a file, this file - will be removed and the save operation aborted. -EOF - -elif [ "$directory" = "1" ]; then - set -- -selection-path="$out" -command='set dironly' -command='set promptfmt "Select directory (quit in dir to select it) %S \033[32;1m%u@%h\033[0m:\033[34;1m%d\033[0m\033[1m%f\033[0m"' -elif [ "$multiple" = "1" ]; then - set -- -selection-path="$out" -command='set promptfmt "Select file(s) (open file to select it; to select multiple) %S \033[32;1m%u@%h\033[0m:\033[34;1m%d\033[0m\033[1m%f\033[0m"' -else - set -- -selection-path="$out" -command='set promptfmt "Select file (open file to select it) %S \033[32;1m%u@%h\033[0m:\033[34;1m%d\033[0m\033[1m%f\033[0m"' -fi - -"$termcmd" --title 'floating please' -e "$cmd" "$@" - -if [ "$save" = "1" ] && [ ! -s "$out" ]; then - rm "$recommended_path" -fi -# vim: ft=sh diff --git a/sys/svcs/xdg/scripts/lf_wrapper.sh b/sys/svcs/xdg/scripts/lf_wrapper.sh new file mode 100755 index 00000000..7a508d39 --- /dev/null +++ b/sys/svcs/xdg/scripts/lf_wrapper.sh @@ -0,0 +1,76 @@ +#!/usr/bin/env sh + +# This wrapper script is invoked by xdg-desktop-portal-termfilechooser. +# +# 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" +recommended_path="$4" +out="$5" + +# echo > /tmp/stdout +# echo > /tmp/stderr +# +# exec 1>> /tmp/stdout +# exec 2>> /tmp/stderr + +cmd="$(command -v lf)" +termcmd="${TERMINAL:-$(command -v alacritty)}" + +if [ "$save" = "1" ]; then + set -- -selection-path="$out" -command='set promptfmt "Select the file to write to %S \033[32;1m%u@%h\033[0m:\033[34;1m%d\033[0m\033[1m%f\033[0m"' "$recommended_path" + cat << EOF > "$recommended_path" +xdg-desktop-portal-termfilechooser saving files tutorial + +!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! +!!! === WARNING! === !!! +!!! The contents of *whatever* file you open last in !!! +!!! lf 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 . + +Notes: +1) This file is provided for your convenience. You + could delete it and choose another file to overwrite + that, for example. +2) If you quit lf without opening a file, this file + will be removed and the save operation aborted. +EOF + +elif [ "$directory" = "1" ]; then + set -- -selection-path="$out" -command='set dironly' -command='set promptfmt "Select directory (quit in dir to select it) %S \033[32;1m%u@%h\033[0m:\033[34;1m%d\033[0m\033[1m%f\033[0m"' +elif [ "$multiple" = "1" ]; then + set -- -selection-path="$out" -command='set promptfmt "Select file(s) (open file to select it; to select multiple) %S \033[32;1m%u@%h\033[0m:\033[34;1m%d\033[0m\033[1m%f\033[0m"' +else + set -- -selection-path="$out" -command='set promptfmt "Select file (open file to select it) %S \033[32;1m%u@%h\033[0m:\033[34;1m%d\033[0m\033[1m%f\033[0m"' +fi + +"$termcmd" --title 'floating please' -e "$cmd" "$@" + +if [ "$save" = "1" ] && [ ! -s "$out" ]; then + rm "$recommended_path" +fi +# vim: ft=sh -- cgit 1.4.1