From fc3af8a3b3af5e3cd35c9c6b075e71e9ce43eb69 Mon Sep 17 00:00:00 2001 From: TheSiahxyz <164138827+TheSiahxyz@users.noreply.github.com> Date: Thu, 11 Sep 2025 17:28:34 +0900 Subject: updates --- mac/.qutebrowser/userscripts/substiqute | 61 +++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100755 mac/.qutebrowser/userscripts/substiqute (limited to 'mac/.qutebrowser/userscripts/substiqute') diff --git a/mac/.qutebrowser/userscripts/substiqute b/mac/.qutebrowser/userscripts/substiqute new file mode 100755 index 0000000..e52e345 --- /dev/null +++ b/mac/.qutebrowser/userscripts/substiqute @@ -0,0 +1,61 @@ +#!/bin/bash +# +# Author: palb91 +# Date: 2022 +# +# Bash style quick substitution in URL +# +# Usage: +# substiqute [-t] +# +# Option: +# -t Open in a new tab +# +# In config.py: +# bind('gs', 'set-cmd-text -s -- :spawn -u -- substiqute') +# bind('gS', 'set-cmd-text -s -- :spawn -u -- substiqute -t') +# +# Note: +# Don't forget to quote replace_string and new_string if there are spaces + +set -e + +OPEN_IN_TAB=false + +# logging +info() { printf 'message-info "%s"\n' "${*}" >>"${QUTE_FIFO}"; } +warn() { printf 'message-warning "%s"\n' "${*}" >>"${QUTE_FIFO}"; } +err() { printf 'message-error "%s"\n' "${*}" >>"${QUTE_FIFO}"; return 1; } + + +replace() { + "${OPEN_IN_TAB}" \ + && printf 'open -t %s\n' "${QUTE_URL/"${1}"/"${2}"}" >>"${QUTE_FIFO}" \ + || printf 'open %s\n' "${QUTE_URL/"${1}"/"${2}"}" >>"${QUTE_FIFO}" +} + + +# with a binding like '^', it is possible to do like in bash ^string1^string2 +split() { + case "${1}" in + *^*) set -- "${1%%\^*}" "${1#*\^}" ;; + *) err 'Unknown substitution format' ;; + esac + replace "${@}" +} + + +# -t open in a new tab... but to replace the string -t with another, use +# `substiqute -- -t anything_else` +case "${1}" in + -t) OPEN_IN_TAB=true; shift ;; + --) shift ;; +esac + + +case "${#}" in + 0) err "No substitution in command" ;; + 1) split "${1}" ;; + 2) replace "${@}" ;; + *) err "To many arguments" ;; +esac -- cgit v1.2.3