Plugin which reads json objects from the standard input and fuzzy matches on the title and description fields of them.
Allows for a flexible use of the Anyrun matcher for arbitrary scripted workflows.
Use similarly as anyrun-stdin
; probably as only plugin with output from previous command piped in.
echo r#'{ "title": "A Title", "description": "Some description", "icon": "/home/fixerer/images/nausicaa_lab.jpg", "id": 42 }'# r#'{ "title": "Another", "icon": "help" }'# r#'{ "title": "<span foreground='red' size='x-large'>RED text</span> is <i>cool</i>" }'# | str join "\n" |
anyrun --plugins ~/.config/anyrun/plugins/libanyrun_json.so --show-results-immediately=true
Provide newline separated json objects on stdin, containing the following fields:
- title: The title field of the match entry.
- description: Optional description field of match entry.
- icon: Optional icon name or file to display.
- id: Optional id for the entry.
The selected entry will then be output on the same format.
Config(
// Whether to try to format pango in the text
use_pango: false,
// How many entries should be displayed at max
max_entries: 5,
// Whether to preserve the original order of entries instead of sorting by fuzzy match score. Matches are still filtered out if there is no similarity to input.
preserve_order: false,
)
Pick among running applications in hyprland and focus it.
# Select among running Hyprland windows to focus
# Read clients as json data
hyprctl clients -j | from json |
# Add columns for anyrun entries
insert icon {|item| $"($item.class)" } |
insert line {|item| $"<b>($item.class)</b>" } |
insert description {|item| $"($item.title)" } |
insert id {|item| ($item.address | into int) } |
select line icon description id | rename --column { line: title } |
# Format as json strings
each {|entry| $entry | to json --raw} | str join "\n" |
# Select using anyrun
anyrun --plugins ~/.config/anyrun/plugins/libanyrun_json.so --show-results-immediately=true |
# Read output and dispatch window focus event
if not ($in | is-empty) {
$in | from json |
get id | into int | format number | get lowerhex |
hyprctl dispatch focuswindow $"address:($in)"
} | default "" o> /dev/null
Pick from the cliphist history and add it to the top of the clipboard.
Uses image thumbnails as icons!
let thumbsize = "256x256"
let thumbnail_folder = $"($env.XDG_CACHE_HOME)/cliphist/thumbnails"
mkdir $thumbnail_folder
def mkthumbnail [infile, outfile] {
try {
magick $infile -define jpeg:size=512x512 -thumbnail $thumbsize -alpha set -background none -gravity center -extent $thumbsize $outfile e> /dev/null
$outfile
} catch {
null
}
}
cliphist list | split row "\n" | split column "\t" | rename id summary |
insert icon {|item| $item.summary |
parse "[[ binary data {amount} {size} {type} {dimensions} ]]" |
if (not ($in | is-empty)) and (( cliphist decode $item.id | str trim ) != ($item.summary | str trim)) {
let name = $"($thumbnail_folder)/($item.id).gif"
let type = $in.type | first
if not ($name | path exists) {
cliphist decode $item.id | mkthumbnail $"($type):-" $name
} else {
$name
}
} else {
if ($item.summary | str starts-with "<img") or ($item.summary | str starts-with "<meta") {
let source = (cliphist decode $item.id |
parse --regex '.*<img .*src="(?<source>[^"]*)".*>' |
get -i source | first 1 | default "" | str join "\n" )
let no_source = ( $source | is-empty )
let no_file = ( not ( $source | default "" | path exists ) )
let no_remote = ( not ( $source | default "" | str starts-with "http") )
if $no_source or ( $no_file and $no_remote ) {
null
} else {
let name = $"($thumbnail_folder)/($item.id).gif"
if not ($name | path exists) {
mkthumbnail $source $name
} else {
$name
}
}
} else {
null
}
}
} |
rename id title icon | update id { into int } |
# Format as json strings
each {|entry| $entry | to json --raw} | str join "\n" |
# Select using anyrun
anyrun --plugins ~/.config/anyrun/plugins/libanyrun_json.so --show-results-immediately=true |
if not ($in | is-empty) {
$in | split row "\n" |
where not ($it | str starts-with "Failed to load icon") |
first 1 | get -i 0 | default "" |
from json |
get id |
cliphist decode $in | wl-copy
} | default "" e+o> /dev/null
The code is adapted from the anyrun-stdin
plugin.