From edd6f9a0a00f04769f5779a52ad5af67f915cf86 Mon Sep 17 00:00:00 2001 From: mbays Date: Tue, 17 Sep 2024 00:00:00 +0000 Subject: [PATCH] browse: shell-escape %s; add %S for unescaped --- Command.hs | 5 +++-- RunExternal.hs | 3 ++- diohscrc.sample | 8 ++++---- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/Command.hs b/Command.hs index 5e6d83f..41b53a0 100644 --- a/Command.hs +++ b/Command.hs @@ -422,8 +422,9 @@ helpOn s = , "The action is determined by the mime-type; see the run-mailcap manpage." ] "browse" -> [ "TARGET {browse}: run command given by environment variable $BROWSER on uri." , "TARGET {browse} COMMAND: run given shell command on uri." - , "%s is substituted with the uri" - , "if no %s appears, the uri is used as an additional final argument." + , "%s is substituted with the uri, shell-escaped," + , "%S is substituted with the unescaped uri." + , "if no %s/%S appears, the escaped uri is appended (separated by a space)." , "A literal '%' can be escaped as '%%'." , "" , "If an identity would be used at the target URI (if it had scheme gemini)," diff --git a/RunExternal.hs b/RunExternal.hs index 897880c..2bfb029 100644 --- a/RunExternal.hs +++ b/RunExternal.hs @@ -52,7 +52,8 @@ subPercentOrAppend sub str = subPercent "" = return [] subPercent ('%':'%':s) = ('%':) <$> subPercent s subPercent ('%':'c':s) = (':':) <$> subPercent s - subPercent ('%':'s':s) = put True >> (sub ++) <$> subPercent s + subPercent ('%':'S':s) = put True >> (sub ++) <$> subPercent s + subPercent ('%':'s':s) = put True >> (shellQuote sub ++) <$> subPercent s subPercent (c:s) = (c:) <$> subPercent s shellQuote s | all shellSafe s && not (null s) = s diff --git a/diohscrc.sample b/diohscrc.sample index 62b7d7d..d35a694 100644 --- a/diohscrc.sample +++ b/diohscrc.sample @@ -54,8 +54,8 @@ #alias Search 'search query #alias QueueNew at *- add #alias Mpv |mpv --cache-secs 5 - -#alias CS br screen -X register '%s' # copy URI to GNU screen buffer -#alias CX br xsel -i <<< '%s' # copy URI to X selection buffer +#alias CS br screen -X register %s # copy URI to GNU screen buffer +#alias CX br xsel -i <<< %s # copy URI to X selection buffer #alias GPGImport |gpg --import #alias Read ||- espeak -s 300 --stdin --stdout | aplay #alias BGRead ||- espeak -s 300 --stdin --stdout | aplay & @@ -66,11 +66,11 @@ # upload an existing file (or compose one), # or as "TARGET TE [-t TOKEN]" to edit a gemini TARGET and upload the changed # version via titan. -#alias TU br titan-upload.sh %s +#alias TU br titan-upload.sh #alias TE ! $EDITOR %s && titan-upload.sh titan://${URI#gemini://} %s # Paging with gmir: # For use with https://github.com/codesoap/gmir . # Requires perl with the URI library (which you probably have). # If you select a link in gmir, it will be added to the diohsc queue. -#alias GMIR !rel="$(gmir "%s")"; [ -n "$rel" ] && echo "$(perl -e 'use URI; print URI->new_abs(shift, shift)')' "$rel" "$URI")" >> ~/.diohsc/queue +#alias GMIR !rel="$(gmir %s)"; [ -n "$rel" ] && echo "$(perl -e 'use URI; print URI->new_abs(shift, shift)')' "$rel" "$URI")" >> ~/.diohsc/queue -- 2.11.4.GIT