OSDN Git Service

add instantclipmenu
authorpaperbenni <paperbenni@gmail.com>
Fri, 7 Aug 2020 11:16:58 +0000 (13:16 +0200)
committerpaperbenni <paperbenni@gmail.com>
Fri, 7 Aug 2020 11:16:58 +0000 (13:16 +0200)
programs/instantclipmenu [new file with mode: 0755]
programs/instantupdatenotify [changed mode: 0644->0755]

diff --git a/programs/instantclipmenu b/programs/instantclipmenu
new file mode 100755 (executable)
index 0000000..39d8933
--- /dev/null
@@ -0,0 +1,77 @@
+#!/usr/bin/env bash
+
+# fork of clipmenu https://github.com/cdown/clipmenu
+
+: "${CM_LAUNCHER=instantmenu}"
+: "${CM_DIR="${XDG_RUNTIME_DIR-"${TMPDIR-/tmp}"}"}"
+: "${CM_HISTLENGTH=8}"
+
+major_version=6
+
+if ! pgrep -f clipmenud; then
+    clipmenud
+fi &
+
+shopt -s nullglob
+
+cache_dir=$CM_DIR/clipmenu.$major_version.$USER
+cache_file=$cache_dir/line_cache
+
+if [ "$1" = "delete" ]; then
+    if imenu -c "clear clipboard cache?"; then
+        echo "clearing cache"
+        echo "cache $cache_file"
+        echo "cleared" >"$cache_file"
+        exit
+    fi
+fi
+
+if [[ $1 == --help ]] || [[ $1 == -h ]]; then
+    cat <<'EOF'
+instantclipmenu is a simple clipboard manager using instantmenu and xsel. Launch this
+when you want to select a clip.
+
+All arguments are passed through to dmenu itself.
+
+Environment variables:
+
+- $CM_DIR: specify the base directory to store the cache dir in (default: $XDG_RUNTIME_DIR, $TMPDIR, or /tmp)
+- $CM_HISTLENGTH: specify the number of lines to show in dmenu/rofi (default: 8)
+- $CM_LAUNCHER: specify a dmenu-compatible launcher (default: dmenu)
+- $CM_OUTPUT_CLIP: if set, output clip selection to stdout
+EOF
+    exit 0
+fi
+
+# Blacklist of non-dmenu launchers
+launcher_args=(-l "${CM_HISTLENGTH}" -p "    " -q 'clipboard manager' -h -1 -lc "instantclipmenu delete")
+if [[ "$CM_LAUNCHER" == fzf ]]; then
+    launcher_args=()
+fi
+
+list_clips() {
+    LC_ALL=C sort -rnk 1 <"$cache_file" | cut -d' ' -f2- | awk '!seen[$0]++'
+}
+
+if [[ "$CM_LAUNCHER" == rofi-script ]]; then
+    if (($#)); then
+        chosen_line="${!#}"
+    else
+        list_clips
+        exit
+    fi
+else
+    chosen_line=$(list_clips | "$CM_LAUNCHER" "${launcher_args[@]}" "$@")
+fi
+
+[[ $chosen_line ]] || exit 1
+file=$cache_dir/$(cksum <<<"$chosen_line")
+[[ -f "$file" ]] || exit 2
+
+for selection in clipboard primary; do
+    xsel --logfile /dev/null -i --"$selection" <"$file"
+done
+
+if ((CM_OUTPUT_CLIP)); then
+    cat "$file"
+fi
old mode 100644 (file)
new mode 100755 (executable)