Move shell scripts into plugin directories
This commit is contained in:
@@ -16,7 +16,7 @@ Item {
|
||||
property var history: []
|
||||
|
||||
property string historyPath: Quickshell.env("HOME") + "/.local/state/omarchy/clipboard-history.json"
|
||||
property string captureScript: root.omarchyPath + "/shell/scripts/clipboard-capture.sh"
|
||||
property string captureScript: root.omarchyPath + "/shell/plugins/clipboard/capture.sh"
|
||||
property string watchCommand: "script=$1\ntrap 'kill $(jobs -p) 2>/dev/null' EXIT\nwl-paste --watch \"$script\" &\nOMARCHY_CLIPBOARD_WATCH_MIME=image/png wl-paste --type image/png --watch \"$script\" 2>/dev/null &\nOMARCHY_CLIPBOARD_WATCH_MIME=image/jpeg wl-paste --type image/jpeg --watch \"$script\" 2>/dev/null &\nOMARCHY_CLIPBOARD_WATCH_MIME=image/webp wl-paste --type image/webp --watch \"$script\" 2>/dev/null &\nOMARCHY_CLIPBOARD_WATCH_MIME=image/gif wl-paste --type image/gif --watch \"$script\" 2>/dev/null &\nOMARCHY_CLIPBOARD_WATCH_MIME=image/bmp wl-paste --type image/bmp --watch \"$script\" 2>/dev/null &\nOMARCHY_CLIPBOARD_WATCH_MIME=image/tiff wl-paste --type image/tiff --watch \"$script\" 2>/dev/null &\nwait"
|
||||
// Shares the [menu] surface tokens — themes that style the menu also
|
||||
// style the clipboard. Selected-row colors composed in the
|
||||
|
||||
Executable
+83
@@ -0,0 +1,83 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -o pipefail
|
||||
|
||||
STATE_DIR="${XDG_STATE_HOME:-$HOME/.local/state}/omarchy"
|
||||
IMAGE_DIR="$STATE_DIR/clipboard-images"
|
||||
mkdir -p "$IMAGE_DIR"
|
||||
|
||||
types=$(wl-paste --list-types 2>/dev/null || true)
|
||||
|
||||
emit_image() {
|
||||
local mime="$1"
|
||||
local ext="$2"
|
||||
local tmp=""
|
||||
local hash=""
|
||||
local file=""
|
||||
|
||||
tmp=$(mktemp --tmpdir="$IMAGE_DIR" clipboard.XXXXXX) || return 0
|
||||
if ! timeout 2s wl-paste --type "$mime" > "$tmp" 2>/dev/null || [[ ! -s $tmp ]]; then
|
||||
rm -f "$tmp"
|
||||
return 0
|
||||
fi
|
||||
|
||||
hash=$(sha256sum "$tmp" | awk '{print $1}')
|
||||
file="$IMAGE_DIR/$hash.$ext"
|
||||
if [[ -e $file ]]; then
|
||||
rm -f "$tmp"
|
||||
else
|
||||
mv "$tmp" "$file"
|
||||
fi
|
||||
|
||||
jq -cn --arg mime "$mime" --arg path "$file" '{type:"image", mime:$mime, path:$path}'
|
||||
}
|
||||
|
||||
emit_image_stream() {
|
||||
local mime="$1"
|
||||
local ext="$2"
|
||||
local tmp=""
|
||||
local hash=""
|
||||
local file=""
|
||||
|
||||
tmp=$(mktemp --tmpdir="$IMAGE_DIR" clipboard.XXXXXX) || return 0
|
||||
cat >"$tmp"
|
||||
if [[ ! -s $tmp ]]; then
|
||||
rm -f "$tmp"
|
||||
return 0
|
||||
fi
|
||||
|
||||
hash=$(sha256sum "$tmp" | awk '{print $1}')
|
||||
file="$IMAGE_DIR/$hash.$ext"
|
||||
if [[ -e $file ]]; then
|
||||
rm -f "$tmp"
|
||||
else
|
||||
mv "$tmp" "$file"
|
||||
fi
|
||||
|
||||
jq -cn --arg mime "$mime" --arg path "$file" '{type:"image", mime:$mime, path:$path}'
|
||||
}
|
||||
|
||||
case "${OMARCHY_CLIPBOARD_WATCH_MIME:-}" in
|
||||
image/png) emit_image_stream 'image/png' 'png'; exit 0 ;;
|
||||
image/jpeg) emit_image_stream 'image/jpeg' 'jpg'; exit 0 ;;
|
||||
image/webp) emit_image_stream 'image/webp' 'webp'; exit 0 ;;
|
||||
image/gif) emit_image_stream 'image/gif' 'gif'; exit 0 ;;
|
||||
image/bmp) emit_image_stream 'image/bmp' 'bmp'; exit 0 ;;
|
||||
image/tiff) emit_image_stream 'image/tiff' 'tiff'; exit 0 ;;
|
||||
esac
|
||||
|
||||
if grep -qx 'image/png' <<<"$types"; then
|
||||
emit_image 'image/png' 'png'
|
||||
elif grep -qx 'image/jpeg' <<<"$types"; then
|
||||
emit_image 'image/jpeg' 'jpg'
|
||||
elif grep -qx 'image/webp' <<<"$types"; then
|
||||
emit_image 'image/webp' 'webp'
|
||||
elif grep -qx 'image/gif' <<<"$types"; then
|
||||
emit_image 'image/gif' 'gif'
|
||||
elif grep -qx 'image/bmp' <<<"$types"; then
|
||||
emit_image 'image/bmp' 'bmp'
|
||||
elif grep -qx 'image/tiff' <<<"$types"; then
|
||||
emit_image 'image/tiff' 'tiff'
|
||||
elif grep -q '^text/' <<<"$types" || grep -qx 'UTF8_STRING' <<<"$types" || grep -qx 'STRING' <<<"$types"; then
|
||||
wl-paste --type text --no-newline 2>/dev/null | jq -cRs 'select(length > 0) | {type:"text", text:.}'
|
||||
fi
|
||||
@@ -48,7 +48,7 @@ Item {
|
||||
onOpenedChanged: if (!opened) layoutSettled = false
|
||||
|
||||
function scriptPath(name) {
|
||||
return omarchyPath + "/shell/scripts/" + name
|
||||
return omarchyPath + "/shell/plugins/image-picker/" + name
|
||||
}
|
||||
|
||||
function focusPicker() {
|
||||
@@ -264,7 +264,7 @@ Item {
|
||||
loadImagesProc.activeSerial = serial
|
||||
loadImagesProc.queuedSerial = 0
|
||||
loadImagesProc.queuedDirs = ""
|
||||
loadImagesProc.command = [root.scriptPath("image-picker-list.sh"), dirs]
|
||||
loadImagesProc.command = [root.scriptPath("list.sh"), dirs]
|
||||
loadImagesProc.running = true
|
||||
}
|
||||
|
||||
|
||||
Executable
+45
@@ -0,0 +1,45 @@
|
||||
#!/bin/bash
|
||||
|
||||
image_dirs=${1:-}
|
||||
cache_dir=${XDG_CACHE_HOME:-$HOME/.cache}/omarchy/image-selector
|
||||
index_file="$cache_dir/index.tsv"
|
||||
|
||||
mkdir -p "$cache_dir"
|
||||
|
||||
thumbnail_for() {
|
||||
local image="$1"
|
||||
local signature hash thumbnail legacy_hash
|
||||
|
||||
signature=$(stat -Lc '%s:%Y' "$image") || return
|
||||
hash=$(awk -F '\t' -v path="$image" -v sig="$signature" '$1 == path && $2 == sig { print $3; exit }' "$index_file" 2>/dev/null)
|
||||
|
||||
if [[ -z $hash ]]; then
|
||||
hash=$(printf '%s\t%s' "$image" "$signature" | md5sum | cut -d ' ' -f 1)
|
||||
fi
|
||||
|
||||
thumbnail="$cache_dir/$hash.jpg"
|
||||
|
||||
if [[ ! -f $thumbnail ]]; then
|
||||
# Older on-demand picker code keyed fallback thumbnails by file content.
|
||||
# Keep finding those if a user still has them cached.
|
||||
legacy_hash=$(md5sum "$image" 2>/dev/null | cut -d ' ' -f 1)
|
||||
[[ -n $legacy_hash && -f $cache_dir/$legacy_hash.jpg ]] && thumbnail="$cache_dir/$legacy_hash.jpg"
|
||||
fi
|
||||
|
||||
if [[ -f $thumbnail ]]; then
|
||||
printf '%s' "$thumbnail"
|
||||
else
|
||||
printf '%s' "$image"
|
||||
fi
|
||||
}
|
||||
|
||||
while IFS= read -r dir; do
|
||||
[[ -n $dir && -d $dir ]] || continue
|
||||
find -L "$dir" -maxdepth 1 -type f \
|
||||
\( -iname '*.jpg' -o -iname '*.jpeg' -o -iname '*.png' -o -iname '*.gif' -o -iname '*.bmp' -o -iname '*.webp' \) \
|
||||
-print0 2>/dev/null
|
||||
done <<<"$image_dirs" | sort -z | while IFS= read -r -d '' image; do
|
||||
thumbnail=$(thumbnail_for "$image")
|
||||
[[ -n $thumbnail ]] || continue
|
||||
printf '%s\t%s\n' "$image" "$thumbnail"
|
||||
done
|
||||
@@ -143,7 +143,7 @@ Item {
|
||||
|
||||
function hiddenEntryScanCommand() {
|
||||
var desktop = [Quickshell.env("XDG_CURRENT_DESKTOP"), Quickshell.env("XDG_SESSION_DESKTOP"), Quickshell.env("DESKTOP_SESSION")].filter(function(v) { return String(v || "").length > 0 }).join(":")
|
||||
var script = root.omarchyPath + "/shell/scripts/launcher-hidden-entries.sh"
|
||||
var script = root.omarchyPath + "/shell/plugins/launcher/hidden-entries.sh"
|
||||
return Util.shellQuote(script) + " " + Util.shellQuote(desktop)
|
||||
}
|
||||
|
||||
|
||||
Executable
+102
@@ -0,0 +1,102 @@
|
||||
#!/bin/bash
|
||||
|
||||
desktop_names=${1:-}
|
||||
|
||||
declare -A seen_ids
|
||||
|
||||
desktop_matches() {
|
||||
local list=$1
|
||||
local desktop_name
|
||||
local entry
|
||||
|
||||
IFS=":" read -ra desktop_parts <<< "$desktop_names"
|
||||
IFS=";" read -ra entries <<< "$list"
|
||||
|
||||
for desktop_name in "${desktop_parts[@]}"; do
|
||||
[[ -z $desktop_name ]] && continue
|
||||
|
||||
for entry in "${entries[@]}"; do
|
||||
[[ -z $entry ]] && continue
|
||||
[[ $entry == "$desktop_name" ]] && return 0
|
||||
done
|
||||
done
|
||||
|
||||
return 1
|
||||
}
|
||||
|
||||
desktop_id_for_file() {
|
||||
local dir=$1
|
||||
local file=$2
|
||||
local rel=${file#"$dir"/}
|
||||
|
||||
rel=${rel%.desktop}
|
||||
printf '%s\n' "${rel//\//-}"
|
||||
}
|
||||
|
||||
is_hidden_desktop_file() {
|
||||
local file=$1
|
||||
local in_desktop_entry=0
|
||||
local hidden=false
|
||||
local only_show_in=
|
||||
local not_show_in=
|
||||
local line key value
|
||||
|
||||
while IFS= read -r line || [[ -n $line ]]; do
|
||||
line=${line%$'\r'}
|
||||
|
||||
if [[ $line =~ ^\[(.*)\]$ ]]; then
|
||||
[[ ${BASH_REMATCH[1]} == "Desktop Entry" ]] && in_desktop_entry=1 || in_desktop_entry=0
|
||||
continue
|
||||
fi
|
||||
|
||||
(( in_desktop_entry )) || continue
|
||||
[[ $line == *=* ]] || continue
|
||||
|
||||
key=${line%%=*}
|
||||
value=${line#*=}
|
||||
|
||||
case $key in
|
||||
Hidden|NoDisplay)
|
||||
[[ $value == "true" ]] && hidden=true
|
||||
;;
|
||||
OnlyShowIn)
|
||||
only_show_in=$value
|
||||
;;
|
||||
NotShowIn)
|
||||
not_show_in=$value
|
||||
;;
|
||||
esac
|
||||
done < "$file"
|
||||
|
||||
[[ $hidden == "true" ]] && return 0
|
||||
[[ -n $only_show_in ]] && ! desktop_matches "$only_show_in" && return 0
|
||||
[[ -n $not_show_in ]] && desktop_matches "$not_show_in" && return 0
|
||||
|
||||
return 1
|
||||
}
|
||||
|
||||
scan_dir() {
|
||||
local dir=$1
|
||||
local file id
|
||||
|
||||
[[ -d $dir ]] || return
|
||||
|
||||
while IFS= read -r -d '' file; do
|
||||
id=$(desktop_id_for_file "$dir" "$file")
|
||||
[[ -n ${seen_ids[$id]+set} ]] && continue
|
||||
seen_ids[$id]=1
|
||||
|
||||
if is_hidden_desktop_file "$file"; then
|
||||
printf '%s\n' "$id"
|
||||
fi
|
||||
done < <(find "$dir" -type f -name '*.desktop' -print0 2>/dev/null | sort -z)
|
||||
}
|
||||
|
||||
scan_dir "$HOME/.local/share/applications"
|
||||
|
||||
IFS=":" read -ra data_dirs <<< "${XDG_DATA_DIRS:-/usr/local/share:/usr/share}"
|
||||
for data_dir in "${data_dirs[@]}"; do
|
||||
scan_dir "$data_dir/applications"
|
||||
done
|
||||
|
||||
scan_dir "$HOME/.nix-profile/share/applications"
|
||||
@@ -435,7 +435,7 @@ Panel {
|
||||
// Poll the weather pill text/class every minute. Local to this widget.
|
||||
Process {
|
||||
id: weatherProc
|
||||
command: ["bash", "-lc", root.bar ? Util.shellQuote(root.bar.omarchyPath + "/shell/scripts/weather.sh") : ""]
|
||||
command: ["bash", "-lc", root.bar ? Util.shellQuote(root.bar.omarchyPath + "/shell/plugins/panels/weather/status.sh") : ""]
|
||||
stdout: StdioCollector {
|
||||
waitForEnd: true
|
||||
onStreamFinished: root.updateWeather(text)
|
||||
|
||||
Executable
+10
@@ -0,0 +1,10 @@
|
||||
#!/bin/bash
|
||||
|
||||
icon=$(omarchy-weather-icon 2>/dev/null)
|
||||
|
||||
if [[ -n $icon ]]; then
|
||||
icon=$(printf '%s' "$icon" | sed 's/["\\]/\\&/g')
|
||||
printf '{"text":"%s"}\n' "$icon"
|
||||
else
|
||||
printf '{"text":"","class":"unavailable"}\n'
|
||||
fi
|
||||
Reference in New Issue
Block a user