Created
February 12, 2026 19:07
-
-
Save yossuli/e15115e4b98f8f471340c3570ac95343 to your computer and use it in GitHub Desktop.
Minimal Clipboard Manager - 最低限の機能のみ
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| export LANG=ja_JP.UTF-8 | |
| export LC_ALL=ja_JP.UTF-8 | |
| # Minimal Clipboard Pick - 最低限の機能のみ | |
| # 履歴から選択してペースト | |
| HISTORY_FILE="$HOME/.clipboard_history" | |
| # 履歴確認 | |
| if [[ ! -f "$HISTORY_FILE" ]] || [[ ! -s "$HISTORY_FILE" ]]; then | |
| osascript -e 'display dialog "クリップボード履歴が空です" buttons {"OK"} default button 1' 2>/dev/null | |
| exit 0 | |
| fi | |
| # プレビューリスト作成 | |
| PREVIEW_DATA=$(tail -r "$HISTORY_FILE" | /usr/bin/jq -r '(.timestamp[11:16]) + " - " + (.content | gsub("\n"; "↵") | .[0:60])' 2>/dev/null) | |
| [[ -z "$PREVIEW_DATA" ]] && exit 0 | |
| # AppleScriptリストに変換 | |
| AS_LIST="" | |
| while IFS= read -r line; do | |
| [[ -z "$line" ]] && continue | |
| ESCAPED=${line//\\/\\\\} | |
| ESCAPED=${ESCAPED//\"/\\\"} | |
| if [[ -n "$AS_LIST" ]]; then | |
| AS_LIST="${AS_LIST}, \"${ESCAPED}\"" | |
| else | |
| AS_LIST="\"${ESCAPED}\"" | |
| fi | |
| done <<< "$PREVIEW_DATA" | |
| # 選択 | |
| INDEX=$(osascript 2>/dev/null <<EOF | |
| set historyList to {${AS_LIST}} | |
| set selectedItem to choose from list historyList with prompt "クリップボードエントリを選択:" with title "Clipboard History" default items {item 1 of historyList} | |
| if selectedItem is false then | |
| return "-1" | |
| end if | |
| set selectedText to item 1 of selectedItem | |
| repeat with i from 1 to count of historyList | |
| if item i of historyList is selectedText then | |
| return ((i - 1) as text) | |
| end if | |
| end repeat | |
| return "-1" | |
| EOF | |
| ) || exit 0 | |
| [[ -z "$INDEX" || "$INDEX" == "-1" ]] && exit 0 | |
| # 選択内容を取得 | |
| JQ_RESULT=$(tail -r "$HISTORY_FILE" | /usr/bin/jq -s ".[$INDEX].content // empty" -r 2>/dev/null) | |
| [[ -z "$JQ_RESULT" ]] && exit 1 | |
| # クリップボードに復元 | |
| echo -n "$JQ_RESULT" | pbcopy || exit 1 | |
| # ペースト | |
| osascript 2>&1 <<'APPLESCRIPT_EOF' >/dev/null | |
| try | |
| tell application "System Events" | |
| delay 0.15 | |
| keystroke "v" using command down | |
| end tell | |
| end try | |
| APPLESCRIPT_EOF |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| set -euo pipefail | |
| # Minimal Clipboard Save - 最低限の機能のみ | |
| # クリップボード内容を履歴に保存 | |
| HISTORY_FILE="$HOME/.clipboard_history" | |
| MAX_ENTRIES=100 | |
| # クリップボード取得 | |
| if (( $# > 0 )); then | |
| CONTENT="$*" | |
| else | |
| CONTENT=$(pbpaste 2>/dev/null) || exit 0 | |
| fi | |
| # 空チェック | |
| [[ -z "$CONTENT" ]] && exit 0 | |
| # サイズ制限(1MB) | |
| if (( ${#CONTENT} > 1048576 )); then | |
| CONTENT="${CONTENT:0:1048576}" | |
| fi | |
| # JSON作成 | |
| JSON_ENTRY=$(jq -n --arg content "$CONTENT" --arg timestamp "$(date -u +"%Y-%m-%dT%H:%M:%SZ")" \ | |
| '{content: $content, timestamp: $timestamp}') | |
| # 重複チェック(直前のエントリと比較) | |
| if [[ -f "$HISTORY_FILE" ]] && [[ -s "$HISTORY_FILE" ]]; then | |
| LAST_ENTRY=$(tail -1 "$HISTORY_FILE") | |
| LAST_CONTENT=$(echo "$LAST_ENTRY" | jq -r '.content // empty') | |
| [[ "$LAST_CONTENT" == "$CONTENT" ]] && exit 0 | |
| fi | |
| # 履歴に追記 | |
| echo "$JSON_ENTRY" >> "$HISTORY_FILE" | |
| # 件数制限 | |
| CURRENT_COUNT=$(wc -l < "$HISTORY_FILE" | tr -d ' ') | |
| if (( CURRENT_COUNT > MAX_ENTRIES )); then | |
| LINES_TO_DELETE=$(( CURRENT_COUNT - MAX_ENTRIES )) | |
| tail -n "$MAX_ENTRIES" "$HISTORY_FILE" > "$HISTORY_FILE.tmp" | |
| mv "$HISTORY_FILE.tmp" "$HISTORY_FILE" | |
| fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment