update fzfclip
This commit is contained in:
@@ -38,9 +38,18 @@
|
|||||||
|
|
||||||
set -euo pipefail
|
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)
|
CACHE_DIR=$(mktemp -d)
|
||||||
export CACHE_DIR
|
export CACHE_DIR
|
||||||
# trap rm later
|
|
||||||
|
|
||||||
export C_TERTIARY='\x1b[1;35m'
|
export C_TERTIARY='\x1b[1;35m'
|
||||||
export C_PRIMARY='\x1b[1;34m'
|
export C_PRIMARY='\x1b[1;34m'
|
||||||
@@ -91,10 +100,16 @@ export ENABLE_ITERM2
|
|||||||
|
|
||||||
# Preview functions
|
# Preview functions
|
||||||
|
|
||||||
|
_clear_preview() {
|
||||||
|
if [ "$ENABLE_ICAT" -eq 1 ]; then
|
||||||
|
printf "\x1b_Ga=d\x1b\\"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
export -f _clear_preview
|
||||||
|
|
||||||
_preview_image() {
|
_preview_image() {
|
||||||
local file="$1"
|
local file="$1"
|
||||||
if [ "$ENABLE_ICAT" -eq 1 ]; then
|
if [ "$ENABLE_ICAT" -eq 1 ]; then
|
||||||
printf "\x1b_Ga=d\x1b\\"
|
|
||||||
chafa -f kitty --size="${FZF_PREVIEW_COLUMNS}x${FZF_PREVIEW_LINES}" "$file"
|
chafa -f kitty --size="${FZF_PREVIEW_COLUMNS}x${FZF_PREVIEW_LINES}" "$file"
|
||||||
elif [ "$ENABLE_SIXEL" -eq 1 ]; then
|
elif [ "$ENABLE_SIXEL" -eq 1 ]; then
|
||||||
chafa -f sixels --size="${FZF_PREVIEW_COLUMNS}x${FZF_PREVIEW_LINES}" "$file"
|
chafa -f sixels --size="${FZF_PREVIEW_COLUMNS}x${FZF_PREVIEW_LINES}" "$file"
|
||||||
@@ -108,40 +123,61 @@ export -f _preview_image
|
|||||||
|
|
||||||
_preview_text() {
|
_preview_text() {
|
||||||
local content="$1"
|
local content="$1"
|
||||||
if [ "$ENABLE_ICAT" -eq 1 ]; then
|
printf "%s" "$content" | head -n 100
|
||||||
printf "\x1b_Ga=d\x1b\\"
|
|
||||||
fi
|
|
||||||
echo "$content" | head -n 100
|
|
||||||
}
|
}
|
||||||
export -f _preview_text
|
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() {
|
_preview_file() {
|
||||||
path="$1"
|
path="$1"
|
||||||
path_mime=$(file -b --mime-type "$path")
|
path_mime=$(file -b --mime-type "$path")
|
||||||
if [[ $path_mime =~ image ]]; then
|
if [[ $path_mime =~ image ]]; then
|
||||||
_preview_image "$path"
|
_preview_image "$path"
|
||||||
elif [[ "$path_mime" =~ video ]]; then
|
elif [[ "$path_mime" =~ video ]]; then
|
||||||
video_hash=$(echo "$path" | md5sum | cut -d" " -f1)
|
_preview_video "$path"
|
||||||
thumb_file="$CACHE_DIR/$video_hash.png"
|
# elif [[ "$path_mime" =~ audio ]]; then
|
||||||
if [ ! -f "$thumb_file" ]; then
|
# _preview_audio "$path"
|
||||||
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
|
|
||||||
else
|
else
|
||||||
_preview_text "$path"
|
_preview_text "$path"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
export -f _preview_file
|
export -f _preview_file
|
||||||
|
|
||||||
|
|
||||||
preview() {
|
preview() {
|
||||||
|
_clear_preview
|
||||||
|
|
||||||
entry="$1"
|
entry="$1"
|
||||||
|
|
||||||
content=$(echo "$entry" | cut -f2-)
|
content=$(echo "$entry" | cut -f2-)
|
||||||
@@ -154,31 +190,31 @@ preview() {
|
|||||||
[ -f "$cache_file" ] || echo "$entry" | cliphist decode >"$cache_file"
|
[ -f "$cache_file" ] || echo "$entry" | cliphist decode >"$cache_file"
|
||||||
_preview_image "$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 "^<img src=\"file://\K[^\"]+")
|
|
||||||
#qq_ext="${qq_img_file##*.}"
|
|
||||||
#qq_img_cache_file=$CACHE_DIR/$id.$qq_ext
|
|
||||||
#cp $qq_img_file $qq_img_cache_file
|
|
||||||
if [ -f "$qq_img_file" ]; then
|
|
||||||
_preview_image "$qq_img_file"
|
|
||||||
else
|
|
||||||
_preview_text "$qq_img_file does not exist."
|
|
||||||
fi
|
|
||||||
|
|
||||||
elif path=$(echo "$entry" | cliphist decode) && [[ "$path" == /* ]]; then
|
elif path=$(echo "$entry" | cliphist decode) && [[ "$path" == /* ]]; then
|
||||||
if [ -e "$path" ]; then
|
if [ -e "$path" ]; then
|
||||||
_preview_file "$path"
|
_preview_file "$path"
|
||||||
else
|
else
|
||||||
_preview_text "$path does not exist."
|
_preview_text "$path does not exist."
|
||||||
fi
|
fi
|
||||||
|
|
||||||
elif decoded=$(echo "$entry" | cliphist decode) && [[ "$decoded" == file://* ]]; then
|
elif decoded=$(echo "$entry" | cliphist decode) && [[ "$decoded" == file://* ]]; then
|
||||||
raw_path="${decoded#file://}"
|
paths=()
|
||||||
raw_path=$(echo "$raw_path" | python -c "import sys, urllib.parse; print(urllib.parse.unquote(sys.stdin.read().strip()))")
|
for path in $decoded; do
|
||||||
if [ -e "$raw_path" ]; then
|
raw_path="${path#file://}"
|
||||||
_preview_file "$raw_path"
|
raw_path=$(echo "$raw_path" | python -c "import sys, urllib.parse; print(urllib.parse.unquote(sys.stdin.read().strip()))")
|
||||||
|
paths+=("$raw_path")
|
||||||
|
done
|
||||||
|
|
||||||
|
if [ "${#paths[@]}" -eq 1 ] && [ -e "${paths[0]}" ]; then
|
||||||
|
_preview_file "${paths[0]}"
|
||||||
else
|
else
|
||||||
_preview_text "$raw_path does not exist."
|
text="Multiple files:"$'\n'
|
||||||
|
for p in "${paths[@]}"; do
|
||||||
|
text+="$p"$'\n'
|
||||||
|
done
|
||||||
|
_preview_text "$text"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
else
|
else
|
||||||
if [ "$ENABLE_ICAT" = 1 ]; then
|
if [ "$ENABLE_ICAT" = 1 ]; then
|
||||||
printf "\x1b_Ga=d\x1b\\"
|
printf "\x1b_Ga=d\x1b\\"
|
||||||
@@ -228,20 +264,6 @@ copy_selection() {
|
|||||||
if [[ "$mime" =~ image ]]; then
|
if [[ "$mime" =~ image ]]; then
|
||||||
echo "$decoded" | wl-copy
|
echo "$decoded" | wl-copy
|
||||||
|
|
||||||
# HTML with QQ image
|
|
||||||
elif [ "$mime" = "text/html" ]; then
|
|
||||||
local qq_src
|
|
||||||
qq_src=$(echo "$decoded" | grep -oP "^<img src=\"file://\K[^\"]+")
|
|
||||||
|
|
||||||
if [ -f "$qq_src" ]; then
|
|
||||||
local encoded_path
|
|
||||||
encoded_path=$(url_encode "$qq_src")
|
|
||||||
|
|
||||||
echo "file://$encoded_path" | wl-copy --type text/uri-list
|
|
||||||
else
|
|
||||||
echo "$decoded" | wl-copy
|
|
||||||
fi
|
|
||||||
|
|
||||||
# URL starting with file://
|
# URL starting with file://
|
||||||
elif [[ "$decoded" == file://* ]]; then
|
elif [[ "$decoded" == file://* ]]; then
|
||||||
echo "$decoded" | wl-copy --type text/uri-list
|
echo "$decoded" | wl-copy --type text/uri-list
|
||||||
@@ -265,7 +287,6 @@ FZF_PORT=$(shuf -i 10000-60000 -n 1)
|
|||||||
RELOAD_CMD="cliphist list | format_clip_list | add_num"
|
RELOAD_CMD="cliphist list | format_clip_list | add_num"
|
||||||
wl-paste --watch bash -c "curl -s -X POST -d 'reload($RELOAD_CMD)' http://localhost:$FZF_PORT" >/dev/null 2>&1 &
|
wl-paste --watch bash -c "curl -s -X POST -d 'reload($RELOAD_CMD)' http://localhost:$FZF_PORT" >/dev/null 2>&1 &
|
||||||
WATCH_PID=$!
|
WATCH_PID=$!
|
||||||
trap 'rm -rf "$CACHE_DIR"; kill $WATCH_PID 2>/dev/null' EXIT
|
|
||||||
|
|
||||||
# Ensure terminal is large enough
|
# Ensure terminal is large enough
|
||||||
|
|
||||||
|
|||||||
@@ -45,13 +45,13 @@ mp4_offset=$((offset - 3))
|
|||||||
tail -c "+$mp4_offset" "$file" > "$tmp_video"
|
tail -c "+$mp4_offset" "$file" > "$tmp_video"
|
||||||
|
|
||||||
play_cmd=()
|
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)
|
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")
|
play_cmd=(vlc --meta-title="Live Photo View: $file")
|
||||||
else
|
else
|
||||||
echo "Error: No suitable media player found." >&2
|
echo "Error: No suitable media player found." >&2
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
"${play_cmd[@]}" "$tmp_video"
|
"${play_cmd[@]}" "$tmp_video"
|
||||||
|
|||||||
+3
-1
@@ -1,4 +1,4 @@
|
|||||||
de 布局太全能了
|
de 布局太全能了:
|
||||||
|
|
||||||
<img src="https://upload.wikimedia.org/wikipedia/commons/3/3e/KB_Germany_Linux.svg" alt="Deutsche Tastaturbelegung unter Linux"/>
|
<img src="https://upload.wikimedia.org/wikipedia/commons/3/3e/KB_Germany_Linux.svg" alt="Deutsche Tastaturbelegung unter Linux"/>
|
||||||
|
|
||||||
@@ -23,3 +23,5 @@ shift > Y X C V B N M ; : _
|
|||||||
altgr | » « ¢ „ “ ” µ · … –
|
altgr | » « ¢ „ “ ” µ · … –
|
||||||
sh+al ˍ › ‹ © ‚ ‘ ’ º × ÷ —
|
sh+al ˍ › ‹ © ‚ ‘ ’ º × ÷ —
|
||||||
```
|
```
|
||||||
|
|
||||||
|
btw, `^` 死键对数字键(上方一排和小键盘均可)也有效, 作用为打出n次幂, 例如 `^` + `9` -> `⁹`.
|
||||||
|
|||||||
Reference in New Issue
Block a user