diff --git a/config/scripts/.local/scripts/fzfclip b/config/scripts/.local/scripts/fzfclip
index 1d93a4e..76549d3 100755
--- a/config/scripts/.local/scripts/fzfclip
+++ b/config/scripts/.local/scripts/fzfclip
@@ -38,9 +38,18 @@
set -euo pipefail
+_cleanup() {
+ if [ -n "${CACHE_DIR:-}" ] && [ -d "$CACHE_DIR" ]; then
+ rm -rf "$CACHE_DIR"
+ fi
+ if [ -n "${WATCH_PID:-}" ]; then
+ kill "$WATCH_PID" 2>/dev/null || true
+ fi
+}
+trap _cleanup EXIT
+
CACHE_DIR=$(mktemp -d)
export CACHE_DIR
-# trap rm later
export C_TERTIARY='\x1b[1;35m'
export C_PRIMARY='\x1b[1;34m'
@@ -91,10 +100,16 @@ export ENABLE_ITERM2
# Preview functions
+_clear_preview() {
+ if [ "$ENABLE_ICAT" -eq 1 ]; then
+ printf "\x1b_Ga=d\x1b\\"
+ fi
+}
+export -f _clear_preview
+
_preview_image() {
local file="$1"
if [ "$ENABLE_ICAT" -eq 1 ]; then
- printf "\x1b_Ga=d\x1b\\"
chafa -f kitty --size="${FZF_PREVIEW_COLUMNS}x${FZF_PREVIEW_LINES}" "$file"
elif [ "$ENABLE_SIXEL" -eq 1 ]; then
chafa -f sixels --size="${FZF_PREVIEW_COLUMNS}x${FZF_PREVIEW_LINES}" "$file"
@@ -108,40 +123,61 @@ export -f _preview_image
_preview_text() {
local content="$1"
- if [ "$ENABLE_ICAT" -eq 1 ]; then
- printf "\x1b_Ga=d\x1b\\"
- fi
- echo "$content" | head -n 100
+ printf "%s" "$content" | head -n 100
}
export -f _preview_text
+_preview_video() {
+ local video_hash, thumb_file, path
+ path="$1"
+ video_hash=$(echo "$path" | md5sum | cut -d" " -f1)
+ thumb_file="$CACHE_DIR/$video_hash.png"
+ if [ ! -f "$thumb_file" ]; then
+ if type ffmpegthumbnailer &>/dev/null; then
+ ffmpegthumbnailer -i "$path" -o "$thumb_file" -s 480 -t 0 >/dev/null 2>&1
+ else
+ _preview_text "ffmpegthumbnailer not installed, cannot generate thumbnail for video."
+ fi
+ fi
+ if [ -s "$thumb_file" ]; then
+ _preview_image "$thumb_file"
+ else
+ _preview_text "Video: $path (No thumbnail)"
+ fi
+}
+export -f _preview_video
+
+# Kinda buggy right now
+# _preview_audio() {
+# local path="$1"
+# if type mpv &>/dev/null; then
+# echo "Playing audio: $path" >&2
+# exec mpv --no-video --keep-open=no --loop-file=no --loop-playlist=no "$path" &>/dev/null
+# else
+# _preview_text "Audio: $path"
+# fi
+# }
+# export -f _preview_audio
+
_preview_file() {
path="$1"
path_mime=$(file -b --mime-type "$path")
if [[ $path_mime =~ image ]]; then
_preview_image "$path"
elif [[ "$path_mime" =~ video ]]; then
- video_hash=$(echo "$path" | md5sum | cut -d" " -f1)
- thumb_file="$CACHE_DIR/$video_hash.png"
- if [ ! -f "$thumb_file" ]; then
- if command -v ffmpegthumbnailer &>/dev/null; then
- ffmpegthumbnailer -i "$path" -o "$thumb_file" -s 480 -t 0 >/dev/null 2>&1
- else
- _preview_text "ffmpegthumbnailer not installed, cannot generate thumbnail for video."
- fi
- fi
- if [ -s "$thumb_file" ]; then
- _preview_image "$thumb_file"
- else
- _preview_text "Video: $path (No thumbnail)"
- fi
+ _preview_video "$path"
+ # elif [[ "$path_mime" =~ audio ]]; then
+ # _preview_audio "$path"
else
_preview_text "$path"
fi
}
export -f _preview_file
+
preview() {
+ _clear_preview
+
entry="$1"
content=$(echo "$entry" | cut -f2-)
@@ -154,31 +190,31 @@ preview() {
[ -f "$cache_file" ] || echo "$entry" | cliphist decode >"$cache_file"
_preview_image "$cache_file"
- elif [ "$mimeType" = "text/html" ] && echo "$content" | grep -q QQ; then
- qq_img_file=$(echo "$entry" | cliphist decode | grep -oP "^
/dev/null 2>&1 &
WATCH_PID=$!
-trap 'rm -rf "$CACHE_DIR"; kill $WATCH_PID 2>/dev/null' EXIT
# Ensure terminal is large enough
diff --git a/config/scripts/.local/scripts/playlive b/config/scripts/.local/scripts/playlive
index 4f39cdc..258755c 100755
--- a/config/scripts/.local/scripts/playlive
+++ b/config/scripts/.local/scripts/playlive
@@ -45,13 +45,13 @@ mp4_offset=$((offset - 3))
tail -c "+$mp4_offset" "$file" > "$tmp_video"
play_cmd=()
-if command -v mpv >/dev/null 2>&1; then
+if type mpv >/dev/null 2>&1; then
play_cmd=(mpv --title="Live Photo View: $file" --keep-open=yes --loop-file=yes --loop-playlist=no --idle=yes)
-elif command -v vlc >/dev/null 2>&1; then
+elif type vlc >/dev/null 2>&1; then
play_cmd=(vlc --meta-title="Live Photo View: $file")
else
echo "Error: No suitable media player found." >&2
exit 1
fi
-"${play_cmd[@]}" "$tmp_video"
\ No newline at end of file
+"${play_cmd[@]}" "$tmp_video"
diff --git a/memo/oh-my-altgr.md b/memo/oh-my-altgr.md
index 5e5422a..08320d0 100644
--- a/memo/oh-my-altgr.md
+++ b/memo/oh-my-altgr.md
@@ -1,4 +1,4 @@
-de 布局太全能了
+de 布局太全能了:
@@ -23,3 +23,5 @@ shift > Y X C V B N M ; : _
altgr | » « ¢ „ “ ” µ · … –
sh+al ˍ › ‹ © ‚ ‘ ’ º × ÷ —
```
+
+btw, `^` 死键对数字键(上方一排和小键盘均可)也有效, 作用为打出n次幂, 例如 `^` + `9` -> `⁹`.