#!/bin/bash . $(ffoom path) ffoo import config ffoo import pretty STORAGE_DIR="$HOME/.local/share/saturnin/clips" usage() { usage_is "[ls]" usage_is "save [-1|-2|-c]" usage_is "load [-1|-2|-c]" } clipln() { # # Print desired clipboard(s) and \n # case $1 in primary|secondary|clipboard) xclip -o -selection $1 2>/dev/null ;; ALL) xclip -o -selection primary 2>/dev/null xclip -o -selection secondary 2>/dev/null xclip -o -selection clipboard 2>/dev/null ;; esac echo "" } save_clip() { local clipname=$1 mkdir -p "$STORAGE_DIR" || die "could not create directory for saving" local path="$STORAGE_DIR/$(date +%Y%m%d-%H%M%S.clip)" clipln $clipname > "$path" } lsclips() { local clipname=$1 local ft hint name test -d "$STORAGE_DIR" || return 0 ls "$STORAGE_DIR/"*.clip 2>/dev/null \ | while read name; do ft=$(file -b -i $name | cut -d\; -f1) case $ft in text/*) hint=$(head -c 80 $name | tr '\n' '↵') ;; *) hint=$(head -c 16 $name | hexdump -C) ;; esac echos "$(basename $name) || $ft || $hint" done } load_clip() { local clipname=$1 local name=$(saturnin clip ls | saturnin dmenu | cut -d\ -f 1) cat $STORAGE_DIR/$name | xclip -i -selection $clipname } clipname=primary action=list while true; do case "$1" in save) action=save; shift ;; load) action=load; shift ;; ls) action=list; shift ;; -1) clipname=primary; shift ;; -2) clipname=secondary; shift ;; -c) clipname=clipboard; shift ;; "") break; ;; *) usage; ;; esac done debug "\$@='$@'" debug -v clipname action case $action in save) save_clip $clipname ;; load) load_clip $clipname ;; list) lsclips ;; esac