Support interations with selected text #1885
Replies: 3 comments 7 replies
-
Those are some interesting ideas. Would you be able to give some more detail? Much of what you suggest can be achieved with the clipboard extension and some brief Scripts or Shell commands (which can be included in the YAML to avoid calling external files), I think, but I may have misunderstood. - trigger: "\x05" # <ctrl-e>
replace: "{{output}}"
vars:
- name: text
type: clipboard
- name: output
type: shell
params:
cmd: echo {{text}} | tr '[:upper:]' '[:lower:]'
shell: bash or cmd: echo '{{text}}'.ToLower()
shell: pwsh It is a three-step process, however (select text, <ctrl-c>, <ctrl-e>). |
Beta Was this translation helpful? Give feedback.
-
You've inspired me to produce my own version, with portions unashamedly copied from yours: - trigger: "\x1F" # Select text and hit <CTRL+_>
label: "Modify selected text CTRL+_"
replace: "{{output}}"
vars:
- name: null
type: shell
params:
shell: bash
cmd: xdotool key --clearmodifiers ctrl+c
- name: clipb
type: clipboard
- name: script_choice
type: choice
params:
values:
- label: Uppercase
id: upper
- label: Lowercase
id: lower
- label: Initcase
id: initcap
- label: Evaluate equation
id: math
- label: Word count
id: wordcount
- name: output
type: shell
params:
shell: bash
cmd: |
case "{{script_choice}}" in
upper)
echo "{{clipb}}" | tr '[:lower:]' '[:upper:]';;
lower)
echo "{{clipb}}" | tr '[:upper:]' '[:lower:]';;
initcap)
awk '{for(i=1;i<=NF;i++) $i=toupper(substr($i,1,1)) tolower(substr($i,2))}1' <<< "{{clipb}}";;
wordcount)
echo "{{clipb}}" | wc -w;;
math)
awk "BEGIN {print {{clipb}}}";;
esac Thank you! |
Beta Was this translation helpful? Give feedback.
-
For your interest, I've put another version here and posted on Discord, which uses the choice extension id: parameters to select the command directly and pass it to the bash shell in a variable. |
Beta Was this translation helpful? Give feedback.
-
It would be nice it there was some way of interacting with selected text similar to the clipboard extension. Maybe with an option to also replace the text or not. For now this would probably require you to trigger the "match" using the search. But if/when keybindings are added (#1188 #1259 #1511) this would be great together with that.
With some simple scripts this could be used for operations such as
For now the workaround is to cut the text and paste it in a form then I you can access it with the variable (or directly from the clipboard). The disadvantage of course being that your clipboard gets replaced and you need to push a few extra buttons.
Beta Was this translation helpful? Give feedback.
All reactions